See if this helps to load.File into Array.
Imports System.IO
Public Class Form1
Private myNamesFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "myNamesFile.txt"
Private arFileLines() As String = Nothing
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If File.Exists(myNamesFile) Then
arFileLines = File.ReadAllLines(myNamesFile)
MsgBox(arFileLines(1)) '// get line.2 from File.
End If
End Sub
End Class
.make sure you have at least 2 lines in your myNamesFile .
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
myCoolSub()
End Sub
Private Sub myCoolSub()
If File.Exists(myNamesFile) Then
arFileLines = File.ReadAllLines(myNamesFile)
MsgBox(arFileLines(1)) '// get line.2 from File.
End If
End Sub
>>how would i write a Private Sub to save the info in the array?.save to.file? or just add values to the Array? andAlso from where/what controls?
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
.actually, see If this helps w/saving.
Imports System.IO
Public Class Form1
Private myNamesFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\myNamesFile.txt"
Private arFileLines() As String = Nothing
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
myCoolSaveSub()
End Sub
Private Sub myCoolSaveSub()
arFileLines = New String() {TextBox1.Text, TextBox2.Text, TextBox3.Text}
File.WriteAllLines(myNamesFile, arFileLines)
MsgBox("file.saved.")
End Sub
End Class
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
>>where does that code save the file to?
Private myNamesFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\myNamesFile.txt"
>>What are the 3 text boxes for?
I used them as an example to write content back to the file.
.reason was: I had no idea other than >>i have a prompt that allows me to enter the number of names and the names themselves.
.thus I used TextBoxes.
If you specify on how and what controls contain those "names" for you to save/load the names to/from, then I will have a better understanding towards supplying a possible solution.
>>im sorry if i seem naggy or rude about this
.never even crossed my mind.:)
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
>>I have 1 rich text box that the data gets displayed in.
That's what I was looking for, thanx.:)
Imports System.IO
Public Class Form1
Private myNamesFile As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\myNamesFile.txt"
Private arFileLines() As String = Nothing
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click
myCoolSaveSub(myNamesFile, RichTextBox1)
End Sub
#Region "-----===-----===-----=== ===-----===-----===-----"
Private Sub myCoolSaveSub(ByVal selCoolFile As String, selCoolRichTextBox As RichTextBox)
File.WriteAllLines(selCoolFile, selCoolRichTextBox.Lines)
MsgBox("file.saved.")
End Sub
#End Region
End Class
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
#Region is to be able to collapse an entire "region" of code and minimize the area of your code window. Your little trigger happy finger should be happy to Not have to scroll as much also.
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384