0

Hi

I'm having some problems with an array
i have in the definitions

Dim x(4)() as string

then when it comes to my assignments I have

x(4)(ss) = (TextBox5.Text)

but it throws an exception (Null Reference)

Can anyone help me with this?

Thx in advance

3
Contributors
12
Replies
13
Views
5 Years
Discussion Span
Last Post by codeorder
0

Hi,

Thanks for your answer, but what i'm trying to do is define a two-dimentional array with the 2nd dimention as an undefined.

0

Hi,

I still can't quite figure it out:

Public Class Test
    Dim x(6)() As String
    
    Dim y As String
    Dim ss As Integer

    Private Sub KryptonCheckButton2_Click(sender As System.Object, e As System.EventArgs) Handles KryptonCheckButton2.Click

    End Sub

    Private Sub KryptonCheckSet1_CheckedButtonChanged(sender As System.Object, e As System.EventArgs) Handles KryptonCheckSet1.CheckedButtonChanged

    End Sub

    Private Sub KryptonGroupBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles KryptonGroupBox1.Paint

    End Sub

    Private Sub KryptonButton1_Click(sender As System.Object, e As System.EventArgs) Handles KryptonButton1.Click
        Dim ans As ans


        If KryptonRadioButton5.Checked = True Then
            ans = Test.ans.A1


        ElseIf KryptonRadioButton6.Checked = True Then
            ans = Test.ans.A2



        ElseIf KryptonRadioButton7.Checked = True Then
            ans = Test.ans.A3



        ElseIf KryptonRadioButton8.Checked = True Then
            ans = Test.ans.A4
        Else
            MsgBox("Error")
        End If

        x(0)(ss) = (KryptonTextBox1.Text)
        x(1)(ss) = (KryptonTextBox2.Text)
        x(2)(ss) = (KryptonTextBox3.Text)
        x(3)(ss) = (KryptonTextBox4.Text)
        x(4)(ss) = (KryptonTextBox5.Text)
        x(5)(ss) = (ans)

        MsgBox(x)
       
        ss = (ss + 1)
    End Sub

    Enum ans
        A1
        A2
        A3
        A4
    End Enum

    Private Sub Test_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ss = 1
    End Sub
End Class

Edited by FrodoBaggins: n/a

0

>>i'm trying to do is define a two-dimentional array with the 2nd dimention as an undefined.
See if this helps regarding the 2D Array.

Public Class Form1
    Private x(6, 0) As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        x(0, 0) = "test"
        MsgBox(x(0, 0))
        x(1, 0) = "test again"
        MsgBox(x(1, 0))
    End Sub
End Class
0

Hi,

When I tried to write to it the 2nd time (so 0, 1) it was outside the bounds of the array (IndexOutOfRange Exception)

0

Try Private x(6, 5) As String and that should give you plenty more Indexes inside the bounds of the array.

Edited by codeorder: n/a

0

Hi,

I need an unlimited amount in the second dimention, so like a dynamic array, because as the user types something a corrosponding value has to be added, and I need there not to be a limit to the amount they can add to the array.

Thanks

0
Public Class Form1
    Private x(6, 0) As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        reDimAndPreserveArray(1)
        MsgBox("x(" & x.GetUpperBound(0) & ", " & x.GetUpperBound(1) & ")") '// FOR.TESTING.
    End Sub

    Private Sub reDimAndPreserveArray(ByVal iNumberOfArraysToAdd As Integer)
        Static iCurrentNumberOfArrays As Integer = 0
        iCurrentNumberOfArrays += iNumberOfArraysToAdd
        ReDim Preserve x(6, iCurrentNumberOfArrays)
    End Sub
End Class

Click the btn a few times for testing and anytime you need to add more arrays, just use that Sub and specify the amount of arrays to add.
.btw: it will Preserve all the previous values for the array.
Hope this helps.:)

0

Hi,

Thanks this solved the problem. I used the redim command on every button press.

Also is it possible to save an array to file as an array rather than a series of strings? I want to be able to read from it easily without preforming splitting operations.

Thanks

0

Solving the problem caused another. Dam.n you God!:D

I personally have no idea how to save a 2D array to a file without having to loop thru all the arrays.
You should start a thread regarding this new issue and hopefully someone will be able to shine some light on this matter.

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.