B
blisspikle
The following sub form1_load reads in a text file that will say
something like the text below. I think that the problem is that every
time I add a class V_Sensor into the arraylist it puts it in as a
reference. So in the end all of the arraylist items turn out to be the
same as the last sensor in the text file. I am new and I do not know
how to declare and put a class into an arraylist so it will be a
different reference for every loop.
<text>
NAME=SENSOR1
SLOPE=1.1
YINTERCEPT=1.2
NAME=SENSOR2
SLOPE=2.1
YINTERCEPT=2.2
etc....
</text>
<code>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim V_Sensor As New AnalogSensor()
Dim V_FileReader As StreamReader
Dim V_TextLine As String
Dim V_TextSplit(2) As String
Const V_FileName As String = "HDTCHECKFIX.ini"
V_FileReader = File.OpenText(V_FileName)
V_TextLine = V_FileReader.ReadLine
Do While Not V_TextLine = ""
V_TextSplit = V_TextLine.Split("=")
If V_TextSplit(0).ToUpper = "NAME" Then
If Not V_Sensor.Name = "" Then
AnalogSensors.Add(V_Sensor)
End If
V_Sensor.Name = ""
V_Sensor.Name = V_TextSplit(1)
End If
If V_TextSplit(0).ToUpper = "SLOPE" Then
V_Sensor.Slope = V_TextSplit(1)
End If
If V_TextSplit(0).ToUpper = "YINTERCEPT" Then
V_Sensor.YIntercept = V_TextSplit(1)
End If
V_TextLine = V_FileReader.ReadLine
Loop
If Not V_Sensor.Name = "" Then
AnalogSensors.Add(V_Sensor)
End If
V_Sensor.Name = ""
V_FileReader.Close()
End Sub
</code>
Thank you,
something like the text below. I think that the problem is that every
time I add a class V_Sensor into the arraylist it puts it in as a
reference. So in the end all of the arraylist items turn out to be the
same as the last sensor in the text file. I am new and I do not know
how to declare and put a class into an arraylist so it will be a
different reference for every loop.
<text>
NAME=SENSOR1
SLOPE=1.1
YINTERCEPT=1.2
NAME=SENSOR2
SLOPE=2.1
YINTERCEPT=2.2
etc....
</text>
<code>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim V_Sensor As New AnalogSensor()
Dim V_FileReader As StreamReader
Dim V_TextLine As String
Dim V_TextSplit(2) As String
Const V_FileName As String = "HDTCHECKFIX.ini"
V_FileReader = File.OpenText(V_FileName)
V_TextLine = V_FileReader.ReadLine
Do While Not V_TextLine = ""
V_TextSplit = V_TextLine.Split("=")
If V_TextSplit(0).ToUpper = "NAME" Then
If Not V_Sensor.Name = "" Then
AnalogSensors.Add(V_Sensor)
End If
V_Sensor.Name = ""
V_Sensor.Name = V_TextSplit(1)
End If
If V_TextSplit(0).ToUpper = "SLOPE" Then
V_Sensor.Slope = V_TextSplit(1)
End If
If V_TextSplit(0).ToUpper = "YINTERCEPT" Then
V_Sensor.YIntercept = V_TextSplit(1)
End If
V_TextLine = V_FileReader.ReadLine
Loop
If Not V_Sensor.Name = "" Then
AnalogSensors.Add(V_Sensor)
End If
V_Sensor.Name = ""
V_FileReader.Close()
End Sub
</code>
Thank you,