Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27212

VS 2010 Trouble with array

$
0
0
I'm reading text from a file, and i can't seem to get this to work. I need to read a line into an array using the following code;


Private Sub LoadDataFile()
With Me

fileReader = My.Computer.FileSystem.OpenTextFileReader(AppPath() & "Data\Data.txt")
While Not fileReader.EndOfStream
stringReader = fileReader.ReadLine()

Dim Seperators As String = "," & " "
Dim StandardShapeLen As Integer = Len("{" & .ShapeSelectLbl.Text & "}")
Dim ClassifiedShapeLen As Integer = Len("{" & .ShapeSelect.Text & "}")

'*****************************LOAD STANDARD SHAPES
If VB.Left(stringReader, StandardShapeLen) = "{" & .ShapeSelectLbl.Text & "}" Then
stringReader = Replace(stringReader, "{" & .ShapeSelectLbl.Text & "}", "")
.ShapeSelect.Items.AddRange(Split(Trim(stringReader), Seperators))

'*****************************LOAD CLASSIFIED SHAPES
ElseIf VB.Left(stringReader, ClassifiedShapeLen) = "{" & .ShapeSelect.Text & "}" Then
stringReader = Replace(stringReader, "{" & .ShapeSelect.Text & "}", "")
.ClassifiedShapeSelect.Items.AddRange(Split(Trim(stringReader), Seperators))

'*****************************LOAD METRIC DIAMETERS
ElseIf InStr(stringReader, "Metric " & .DiameterSelectLbl.Text) > 0 And Val(.InputOne.Text) >= 2.6 Then
stringReader = Replace(stringReader, "{" & "Metric " & .DiameterSelectLbl.Text & "}", "")
.DiameterSelect.Items.AddRange(Split(Trim(stringReader), Seperators))
'*****************************LOAD ENGLISH DIAMETERS
ElseIf InStr(stringReader, "English " & .DiameterSelectLbl.Text) > 0 And Val(.InputOne.Text) < 2.6 Then
stringReader = Replace(stringReader, "{" & "English " & .DiameterSelectLbl.Text & "}", "")
.DiameterSelect.Items.AddRange(Split(Trim(stringReader), Seperators))

End If

End While
End With

End Sub

If i hard code the data like below, it works, but what i'm trying to do is use a single data file for the entire program; see below...
As you can see, ClassifiedShapes() is a hard coded array, but i don't want to do this, plus i'm alread getting the data from above, where i'v highlighted it in red. It's hard to explain, but i hope you can understand my gibberish. I've attached the text file as well. All of the above code works fine, but i would like to load the ClassifiedShapes() array using the code above.

Dim ClassifiedShapes() As String

ClassifiedShapes = {"MONO LOBES", "MULTI LOBES", "L SHAPES", "KEYS", "POLYGONS", "U SHAPES", "TRIANGLES / TRAPEZOIDS", "TEE'S", "MISCELLANEOUS", "DUO TEE'S"}


With Me

For index = 0 To ClassifiedShapes.GetUpperBound(0)
If .ShapeSelect.Text = (ClassifiedShapes(index)) Then
.ClassifiedShapeLbl.Visible = True
.ClassifiedShapeSelect.Visible = True
.ClassifiedShapeSelect.SelectedIndex = -1
Exit Sub
Else
.ClassifiedShapeLbl.Visible = False
.ClassifiedShapeSelect.Visible = False
End If
Next
Attached Files

Viewing all articles
Browse latest Browse all 27212


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>