3
Contributors
12
Replies
16
Views
5 Years
Discussion Span
Last Post by ayagi
0
TextBox1 = ""

The above line will cause this error: Value of type 'String' cannot be converted to 'System.Windows.Forms.TextBox'. Can easily be fixed by setting the .Text of the TextBox as the String, and not the TextBox it's self.

TextBox1.Text = ""

Without your code that generates the error, it is difficult for someone to exactly recreate it.

0

thanks.
i already solve it.

i have a problem in my array.. it says "Index was outside the bounds of the arrays"

what is the error handled in that problem?
here is my code

For i As Integer = 0 To 3
                        If i = 0 And skillset(i).ToString <> vbNullString Then
                            txtSkills1.Text = skillset(i).ToString
                        End If
                        If i = 1 And skillset(i).ToString <> vbNullString Then
                            txtSkills2.Text = skillset(i).ToString
                        End If
                        If i = 2 And skillset(i).ToString <> vbNullString Then
                            txtSkills3.Text = skillset(i).ToString
                        End If
                        If i = 3 And skillset(i).ToString <> vbNullString Then
                            txtSkills4.Text = skillset(i).ToString
                        End If
0

>>it says "Index was outside the bounds of the arrays"

This usually occurs when your (i) goes over the Array length/count.
.Here's an example.

Try
            Dim arTemp() As String = {"one", "two", "three"}
            MsgBox(arTemp(3))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Since Arrays start at 0 not 1, the arTemp(3) is actually Array 4, which is not included in my declared Array. Therefore you will get the error message.

Edited by codeorder: n/a

0

Ok. With the above posted code, using MsgBox(arTemp(0)) , you will get "one", MsgBox(arTemp(1)) will get you "two", and MsgBox(arTemp(2)) will get you "three" from the arTemp String Array.
.Since in my code I had MsgBox(arTemp(3)) , that Array does not exist in arTemp, which should return a "four", therefore you get the error of "Index was outside the bounds of the Array".

Basically saying, that error will let you know when you are trying to locate something that is not there, it is "outside the bounds", bounds meaning Array length/count.

Edited by codeorder: added content

0

how can i trap that error?
if i don't have the value for that array, i will display nothing in my textbox..

0

Change MsgBox(ex.Message) to TextBox1.Clear in the Try/Catch of my previously posted code.

Try
            '// run all code here that can/might cause an error.
        Catch ex As Exception
            '// add code here to correct the error if it does occur.
        End Try

Edited by codeorder: title added

0

if i don't write any code in catch ex as exception.
the error will not display ..

0

thanks its really help.
i feel so upset not solving that error.
i just new in .net programming.
:) thank you so much :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.