0

I have a 3 Dimension Array and would like to get the value of each element
I would rather not use a For Next Loop to get the element values
The 3D Array will hold Integers but I am testing with the Array declared as Objects
I can get all three elements and really do not want to play with the Substring method
Here is the code I have thus far

Dim arrInfo(30, 30, 30) As Object
Dim V, X, Y As Object
    arrInfo(0, 0, 0) = (1, 42, 70)
    V = arrInfo(0, 0, 0)
    tbOne.Text = V.ToString

Tried this same results
tbTwo.Text = arrInfo.GetValue(index1:=0, index2:=0, index3:=0).ToString

Both produce (1, 42, 70)
Now How do I get each element as a value?

I am trying to use a 3D Array to set X & Y coordinates of where to print on 8.5 X 11 Sheet of Avery Label's I set the data to be printed when I click on a Button
In the past VB 6 I had a Variant Array so the reason for the 3D Array is to set the values for the individual labels

Here is the code that sets the label information when a Button is clicked and values to be printed are used in the pdDoc print method

    Private Sub btnThree_Click(sender As Object, e As EventArgs) Handles btn3.Click
    btn3.Enabled = False
    cinemas(2, 2) = 580
    cinemas(2, 3) = 70
    lblArray(2) = gv_FN & " " & gv_LN & vbNewLine & gv_AD & vbNewLine & gv_CT & ", " & gv_ST & "  " & gv_ZP
End Sub

       If Z = 2 Then
            X = cinemas(2, 2)
            Y = cinemas(2, 3)
            e.Graphics.DrawString(lblArray(2), labelFont, Brushes.Black, X, Y)
        End If

The first value in arrInfo(0,0,0) is the integer I want to use for lblArray(2) The idea was to remove the 2D Array cinemas(2,2) and capture all three variables from arrInfo(0,0,0)

3 Answers 3

1

I added a line that makes it a little clearer what your are doing.

    Dim arrInfo(30, 30, 30) As Object
    Dim V, X, Y As Object
    Dim o As Object = (1, 42, 70) '<--- Line added
    arrInfo(0, 0, 0) = o
    V = arrInfo(0, 0, 0)
    TextBox1.Text = V.ToString

You are assigned a single object, (1, 42, 70), to a single element of the array located at arrInfor(0,0,0).

Maybe you should check out Point3D Class. Then you can make a one dimensional array of 3D points. https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datavisualization.charting.point3d?view=netframework-4.8

Sign up to request clarification or add additional context in comments.

1 Comment

I have not looked at all the information at the link but this comment makes me wonder if my 3D array might be a bad idea "the Z value is then disregarded" I will add some code so it will be much clearer than me jabbering
1

Well I have a couple of answers one kind of funny and one a lot more work than what you are doing

The funny answer is like Gypsy Rose Lee the American burlesque entertainer and famous for her striptease act. Here is how to strip away the info you do not need
The issue is you will need a different algorithm for each length of Object = (1, 42, 70) and this will lead to more work than it might be worth anyway here is the code Take it all out or is that off

    arrInfo(0, 0, 0) = (1, 42, 70)
    V = arrInfo(0, 0, 0)
    tbOne.Text = V.ToString
    Dim aString As String = tbOne.Text
    tbTwo.Text = GetChar(aString, 2)
    Dim bString As String = Replace(tbOne.Text, "(", "")
    tbThree.Text = Mid(bString, 3, 3).Trim
    Dim cString As String = Replace(tbOne.Text, ")", "")
    tbFour.Text = Mid(cString, 9, 9)

Because this is a matrix each Label is in the same Row and Column so the X value increase as you print the label to the RIGHT and the Y value increases as you move DOWN the Row's

Setting the initial Top Left Label X and Y values all you need to do is increase each value as you try to print to the RIGHT or Print DOWN one Row CODE BELOW No Need for the Array with X and Y values

    X = 42
    Y = 70
    For Z = 1 To 6
        If Z = 1 Then
            e.Graphics.DrawString(lblArray(1), labelFont, Brushes.Black, X, Y)
        End If
        If Z = 2 Then
            e.Graphics.DrawString(lblArray(2), labelFont, Brushes.Black, X + 268, Y)
        End If
        If Z = 3 Then
            e.Graphics.DrawString(lblArray(3), labelFont, Brushes.Black, X + 538, Y)
        End If
        If Z = 4 Then
            e.Graphics.DrawString(lblArray(4), labelFont, Brushes.Black, X, Y + 96)
        End If
        If Z = 5 Then
            e.Graphics.DrawString(lblArray(5), labelFont, Brushes.Black, X + 268, Y + 96)
        End If
        If Z = 6 Then
            e.Graphics.DrawString(lblArray(6), labelFont, Brushes.Black, X + 538, Y + 96)
        End If
    Next

I am guessing but NOT using the Array for X & Y values should use less memory perhaps someone will comment about my Guess

Comments

1

At the very bottom of your post you state that you want to "capture all three variables from arrInfo(0,0,0)".

I don't understand what you're doing with the parenthesis here: (1, 42, 70).

It would make sense to use an ARRAY, so use CURLY BRACES instead: {1, 42, 70}

Now you can reference said array with your "V" variable, and use standard parenthesis to access each element:

Dim V, X, Y As Object
Dim arrInfo(30, 30, 30) As Object

arrInfo(0, 0, 0) = {1, 42, 70} ' note the CURLY BRACES to make an ARRAY

V = arrInfo(0, 0, 0)
tbOne.Text = V(0)
tbTwo.Text = V(1)
tbThree.Text = V(2)

Output:

enter image description here

4 Comments

I plugged in your code and get my new favorite phrase Late Binding Error with V(0) I even tried to change everything to Type Integer I can not curly braces do not work I thought my syntax was to add values to the Array even tried this because VS said use this Dim W As (Integer, Integer, Integer) = (1, 42, 70)
I see my ERROR I was trying to put all three values 1,42,70 In the arrInfo(0,0,0) It Don't work that way I did adapt Mary's code to put a String + Integer + Integer in arrInof withi this Dim o As Object = lbS & " " & 42 & " " & 70 and used this arrInfo(0, 0, 0) = o where o is an Object Thanks for the Reply
Not sure what the difference is. The code above worked without error or issue. That is the entire code in the button click event, and that is the actual output when run. Running Visual Studio 2017 with default install settings for VB. Must be something different about your bigger picture. In general, though, it's a bad idea to leave things as Object.
I agree on the Object I am learning and testing so the lesson was NOT a good idea I am using VS 2019 Option Strict ON this changed some of my bad habits I ended up with a 2D Array when I think TWO one dimension arrays would be better I am only managing Row and Column X & Y positions Structure Item might be better but not enough experience with it Thanks for helping me learn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.