I am trying to make a form populate RadioButton choices from the lines of a text file.
I have code dynamically declaring variables in an array for each line of the text file:
Public Function CountCharacter(ByVal value As String, ByVal ch As Char) As Integer
Dim cnt As Integer = 0
For Each c As Char In value
If c = ch Then cnt += 1
Next
Return cnt
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim output As String
Dim lineCount As Integer = 0
Dim classText As String = "(text file path)"
output = IO.File.ReadAllText(classText)
'declare text file to variable
lineCount = CountCharacter(output, vbCrLf) + 1
'get line count (delimited by line feed)
Dim strLine() As String = output.Split(vbCrLf)
'split output variable delimited by line feed
Dim classSelection(lineCount) As String
'declare string array for amount of lines
Dim period As Integer = 0
'declare integer for counting 'For Each' statement
For Each line As String In strLine
period += 1
'count one 'For Each' rotation period
classSelection(period) = line
'dynamically declare array data based on line/rotation number
Next
Now I should have classSelection() for each line
When I try to pass this into RadioButtons or CheckBoxes only the first line classSelection(1) is displayable as RadioButton.Text For example:
RadioButton1.Text = classSelection(1)
RadioButton2.Text = classSelection(2)
RadioButton3.Text = classSelection(3)
this will display the first line from the text file on RadioButton1 and be blank on RadioButton2 and 3. I can pass classSelection(1) to any one of the three RadioButtons and it will display on them as well, but classSelection(2) or classSelection(3) will not display on any of the RadioButtons. What is odd to me is that RadioButton2.Text is holding the value of classSelection(2), just not displaying it. As I can pass the value of the non displaying RadioButton2.Text to another object and the value of classSelection(2) will display on it just fine.
What would make classSelection(1) so different from classSelection(2) to make it not display?
theCBO.Items.AddRange(File.ReadAllLines(someFile))
is all you would need – Ňɏssa Pøngjǣrdenlarp