Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / October 2004



Tip: Looking for answers? Try searching our database.

Printing a List Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave Lewis - 29 Oct 2004 17:33 GMT
I Have a small app that adds it's results to a list box, what I want to do
is save the contents of this box to a text file or better still an excel
doc, can someone point me in the right direction

Regards

Dave L
CajunCoiler (http://www.cajuncoiler.tk) - 29 Oct 2004 21:32 GMT
Try this...

Public Sub Listbox2Textfile(Listbox1 As Listbox, Filename As String)
Dim f As Integer
Dim h As Long
f=Freefile
Open Filename For Output As #f
For h = 0 To Listbox1.ListCount-1
Print #f, Listbox1.List(h)
Next h
Close #f
End Sub

Make the file extension ".txt" for  a text file, or ".csv" for Excel.

> I Have a small app that adds it's results to a list box, what I want to do
> is save the contents of this box to a text file or better still an excel
[quoted text clipped - 3 lines]
>
> Dave L
Dave Lewis - 31 Oct 2004 17:30 GMT
Can you give an example? I keep getting 'expected =' or 'syntax error' when
trying this

Private Sub Command2_Click()
printfile = "c:\test.csv"
Listbox2Textfile (List1,printfile)
End Sub

or have I got the wrong end of the stick here?

Regards

DL

> Try this...
>
[quoted text clipped - 18 lines]
> >
> > Dave L
Rick Rothstein - 31 Oct 2004 17:37 GMT
> Can you give an example? I keep getting 'expected =' or 'syntax error' when
> trying this
>
> Private Sub Command2_Click()
> printfile = "c:\test.csv"
> Listbox2Textfile (List1,printfile)

You have the syntax wrong; remove the parentheses from around the
argument list to the Sub. Parentheses are only used with a Sub if the
Call keyword is used. The above line should be either this...

    Listbox2Textfile List1, printfile

or this...

    Call Listbox2Textfile(List1, printfile)

Rick - MVP
Dave Lewis - 31 Oct 2004 21:11 GMT
That did it thank you both
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.