1
Hi Chris,
If you want to read in the text file immediately upon creation of the form, you can do this in the constructor
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
or you can do so in the form load event. (Go to the properties tab and choose the lightening bolt. Double click on Load and it will generate a Form_Load event handler for you)
End Class
0
0
Thanks Mike,
That's what I was stuck on. I'm up and running now.
Now I have another question if I may.
How do I do a Do While loop for an array. etc.
Do While TempArray() is not empty
Thanks,
Chris
Regards,
Chris
0
Hi Mike,
Thanks for the reply.
I'm not explaining it very well I'm afraid.
Basically I don't want to have to click a button for the text file read to happen. I want it to read in the file in the back ground. I'm steadily following examples in learning sites but they all seem to require a button to start a process.
Having said all that I think I've figured it out. Instead of right clicking on a button and putting the code in the relevent section, I right clicked on the whole form1 and it's created a new Private Sub. I've put my code in there and it seems to run it without any button presses. I presume that's how to do it.
Appears so mind boggling when you don't know it :)
0
Hi Chris,
Not sure what you are asking. Private and Public are encapsulation keywords. Here is some sample code in Vb to read a file into a string selected from the open file dialog. You'll need to drag a button on the form as well as the OpenFileDialog control. Double clicking on the button will generate the event handler you see below.
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sr As StreamReader
Dim fileContent As String
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
sr = New StreamReader(OpenFileDialog1.FileName)
fileContent = sr.ReadToEnd()
End If
End Sub
End Class