Help on Initialize a variable by reading if off a text file.

jcsdhs

New member
Joined
Nov 13, 2005
Messages
2
Programming Experience
Beginner
Okay I have a program that at Form_Load I want to initialize a variable. I have the variable written in a text file. I wondering how do I initialize it, so I can use it in other events? Like lets say in a click object instance I have A+B = C, then I display C in a text box. B is always a const. Its value is 5 lets say. So how can I declare B in the Form_Load event by reading it off a text file? Then be able to use it in a click object instance.

Thanks in advance.
 
i would declare a variable at the top of the form then in the load event call the sub that reads the file and in that sub have it set that form level variable then after calling that sub have it set the value of C (C will also be a form level variable so it can be used in other events/objects)
 
My instructor doesn't want use 'hard coding' the number in a form level constant, he wants us to make it a variable and use a sub-procedure called from the Form_Load event to open, and read from, the file and initialize the variable.

I know how to declare it a form level constant, but have no idea how to read it from the text file. I already have the file with the number in it. I know its similar to loading a list to a combo box.

Dim ofdComboBox As OpenFileDialog = New OpenFileDialog
Dim dlrResponse As DialogResult
Dim strFileName As String
Dim InputFileName As System.IO.StreamReader

InputFileName =
New System.IO.StreamReader(ofdComboBox.FileName)
strFileName = ofdComboBox.FileName

Do Until InputFileName.Peek = -1
strItem = InputFileName.ReadLine
cbo_areas.Items.Add(strItem)
Loop
InputFileName.Close()

That's how you read to add to a combo box, but have no idea how to initialize the variable and use it???
 
Back
Top