Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,

I need an code that will help me to export values from three listbox to excel or text file by using save file dialog.
Thanks

What I have tried:

Dim w as io.streamwriter
Dim I as integer
W = new iO.streamwriter ("c:\" & ".text")
For I = 0 to listbox1.items.count -1
W.writeline(listbox1.items.item(i))
Next
W.close()
Posted
Updated 13-Mar-22 3:13am

Your filename is C:\.text. That's not legal in windows.

Why is it people do this:
"C:\" & ".text"

and not just skip the concatenation entirely since it's not needed:
"C:\filename.txt"
 
Share this answer
 
Comments
Elias Ar 13-Mar-22 1:34am    
Bro,
Your reply doesn't help me, I know I should put the file name but I'm asking for something else, How I can save an Excel or Text file by using the save file dialog, please read the post three times before replying.
Thanks
Take a look at MSDN documentation:
SaveFileDialog Class (System.Windows.Forms) | Microsoft Docs[^]
How to: Write Text to Files with a StreamWriter - Visual Basic | Microsoft Docs[^]

If you would like to write data into Excel file, i'd suggest to install EPPlus 4.5.3.3 NuGet package[^]. Here is CP article with example code: How to Use EPPlus in VB[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900