Hi, I don't understand why this code doesn't work:
On the first pass of the While loop, Line 13 results in Cx(0) = Nothing.
Then the code bombs out and displays the Form1 with the text for Check Boxes 1 to 5 showing their original names: CheckBox1 to CheckBox5, the GroupBox name is still GroupBox1 and the two buttons are still called Button1 and Button2.
I think I can name CheckBox1 Cx(0) can't I ? Then I figure I ought to be able to change it's text to "Apples" (or whatever).
Because I'm now using VS2013, I can't find how to set up a 'Watch' page, I have the choice of 'Watch 1 to 4' but none of them seem to allow me to enter variables to watch, I have to use the ''Instants' but then I can't read the values of my global String Array, y(4), presumably because it's not an instant. I temporarily set up a String variable x, where line 12 is to to check that I am reading the Mid$ correctly, and I am.
So, Guys... Where am I going wrong ?
Poppa.
vb.net Code:
Public Class Form1 Dim y(4) As String Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim a, b As Integer, Cx(4) As CheckBox, z As String z = "Apples+Pears+Oranges+Bananas+Cherries+ " a = InStr(z, "+") b = 0 While a > 0 y(b) = Mid(z, 1, a - 1) Cx(b) = CType(Me.Controls("CheckBox" & b + 1), CheckBox) Cx(b).Text = y(b) z = Mid(z, a + 1) a = InStr(z, "+") b += 1 End While Button1.Text = "Check" Button2.Text = "Exit" GroupBox1.Text = "Fruit Stall" End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Me.Close() End End Sub End Class
Then the code bombs out and displays the Form1 with the text for Check Boxes 1 to 5 showing their original names: CheckBox1 to CheckBox5, the GroupBox name is still GroupBox1 and the two buttons are still called Button1 and Button2.
I think I can name CheckBox1 Cx(0) can't I ? Then I figure I ought to be able to change it's text to "Apples" (or whatever).
Because I'm now using VS2013, I can't find how to set up a 'Watch' page, I have the choice of 'Watch 1 to 4' but none of them seem to allow me to enter variables to watch, I have to use the ''Instants' but then I can't read the values of my global String Array, y(4), presumably because it's not an instant. I temporarily set up a String variable x, where line 12 is to to check that I am reading the Mid$ correctly, and I am.
So, Guys... Where am I going wrong ?
Poppa.