Coding Error

shenberry

New member
Joined
Jan 14, 2007
Messages
2
Programming Experience
Beginner
Sorry If this is in the wrong location. It is very confusing on where I should put this information at, so I thought testing would be a good place to start.

I am having trouble understanding why some controls can be in the form of control(1).property and others like textbox cannot be in that form. I am tryinig to insert 18 textboxes in to an array , so I can only input values one time. My coding looks like this

VB.NET:
       Dim t As Integer
        t = 1
        For i As Integer = 0 To 17
            Inputmatrices(i) = TextBox(t).Text
            t += 1
        Next i

It doesn't allow me to generate different values for textboxes.
The error it say is textbox is a type and cannot be used as an expression, how do I make it an expression.
Thanks for the help
 
you need to create an instance of a textbox array...

VB.NET:
dim tbArray() as TextBox

and add the elements from there

you can specify the length at the start (in the brackets), but if its dynamic you can use redim preserve to increase the array's capacity if you need to.

good luck :)
 
Thanks I classified an arry as textbox but sitll have an error with TextBoxN now. It wants it to be a variable and not a control.
HEre is the complete coding.

VB.NET:
Public Class Form1

    Dim TextBoxArray(17) As TextBox

 
    Private Sub TextBox28_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox28.TextChanged
        
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        TextBox28.Text = "Addition"
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        TextBox28.Text = "Subtraction"
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        TextBox28.Text = "Multiplication"
        
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        TextBox28.Text = "Identity"

    End Sub

    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InputMatrix.Click
        Dim N As Integer = 0
        TextBoxArray(N) = TextBoxN
        TextBoxArray(N + 1) = TextboxN + 1
    End Sub
End Class
 
Back
Top