|
-
Jan 5th, 2009, 01:52 AM
#1
Thread Starter
Lively Member
[RESOLVED] Listbox add problum
Greetings All
I forgot VS 2008
I can add a textbox text to the listbox and save it to IO.File.AppendText(Application.StartupPath & "\List.txt")
but i cant get it to add with a openfiledialog , now the listbox allready hase text loaded in it , iam trying to add too it with openfiledialog
openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.Title = "Select a Cursor File"
openFileDialog1.FileName = ""
ProgressBar1.Visible = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim lines() As String = File.ReadAllLines(openFileDialog1.FileName)
For Each line As String In lines
Lst.Items.Add(line)
Next
can someone help me on this
Thankl You
Dem
-
Jan 5th, 2009, 03:30 AM
#2
Re: Listbox add problum
Are you getting an error?
I tried it with a couple of edits and works fine.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.Title = "Select a Cursor File"
OpenFileDialog1.FileName = ""
ProgressBar1.Visible = True
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim lines() As String = IO.File.ReadAllLines(OpenFileDialog1.FileName)
For Each line As String In lines
ListBox1.Items.Add(line)
Next
End If
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 5th, 2009, 03:41 AM
#3
Thread Starter
Lively Member
Re: Listbox add problum
 Originally Posted by RobDog888
Are you getting an error?
I tried it with a couple of edits and works fine.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.Title = "Select a Cursor File"
OpenFileDialog1.FileName = ""
ProgressBar1.Visible = True
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim lines() As String = IO.File.ReadAllLines(OpenFileDialog1.FileName)
For Each line As String In lines
ListBox1.Items.Add(line)
Next
End If
End Sub
End Class
Thanks for replying
i can add it it works but iam trying to add it also to
IO.File.AppendText(Application.StartupPath & "\List.txt")
i have items in the list box, and iam trying to add more with opendialog ud dating my IO.File.AppendText(Application.StartupPath & "\List.txt")
Thank you
Dem
-
Jan 5th, 2009, 03:44 AM
#4
Re: Listbox add problum
Ummm... so you are wanting to write text to that file regardless of what file is selected? Can you give an example or something as its not clear how you want it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 5th, 2009, 04:00 AM
#5
Thread Starter
Lively Member
Re: Listbox add problum
 Originally Posted by RobDog888
Ummm... so you are wanting to write text to that file regardless of what file is selected? Can you give an example or something as its not clear how you want it.
I got a listbox that loads when form loads code is
Dim lines() As String = IO.File.ReadAllLines(Application.StartupPath & "\List.txt")
Dim i As Integer = 0
Lst.Items.AddRange(lines)
now i created a textbox to where i can add 1 line ot text
Lst.Items.Add(TextBox1.Text)
Dim streamWriter As IO.StreamWriter
' Create the StreamWriter object
streamWriter = IO.File.AppendText(Application.StartupPath & "\List.txt")
' Write a line to the file from user inputted
' information from a text box
streamWriter.WriteLine((Me.TextBox1.Text))
' Close the file
streamWriter.Close()
ok form loads the listbox, now i want to add a file to the listbox using opendialog.
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim lines() As String = File.ReadAllLines(openFileDialog1.FileName)
Dim myWritePath As String = Application.StartupPath & "\List.txt"
Dim sw As New IO.StreamWriter(myWritePath, True)
For Each line As String In lines
sw.WriteLine(line, True)
Lst.Items.Add(line)
'IO.File.AppendText(Application.StartupPath & "\List.txt")
Next
i want to update the IO.File.AppendText(Application.StartupPath & "\List.txt")
i hope i expland this right
Dem
-
Jan 5th, 2009, 10:30 AM
#6
Thread Starter
Lively Member
Re: Listbox add problum
Thank You RobDog888 for your time and help.
I did it this way , if theres a better way plz let me know.
Code:
openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.Title = "Select a Cursor File"
openFileDialog1.FileName = ""
ProgressBar1.Visible = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim streamWriter As IO.StreamWriter
Dim lines() As String = File.ReadAllLines(openFileDialog1.FileName)
streamWriter = IO.File.AppendText(Application.StartupPath & "\List.txt")
For Each line As String In lines
Lst.Items.Add(line)
streamWriter.WriteLine(line)
Next
streamWriter.Close()
Regards
Dem
Last edited by RobDog888; Jan 6th, 2009 at 04:16 AM.
-
Jan 6th, 2009, 04:16 AM
#7
Re: [RESOLVED] Listbox add problum
Looks fine. Glad its working as you need now.
Ps, I added [code] tags to make it easier to read.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|