Implementing a 2D array in VB

cs1ctp

Board Regular
Joined
Oct 7, 2005
Messages
122
Hi,

I have two arrays: ArrayMyTop and ArrayMyLeft. Basically I wish to search both arrays to find instances where the input from two ComboBox's match the values that appear in the same position of each array, for example:

ArrayMyTop = 1,2,3,4,5,6
ArrayMyLeft = 7,8,9,10,11,12
ComboBox1 Input = 3
ComboBox2 Input = 9

A match would be found in position 3 of both array's, the values 3 and 9 both exist. However if the inputs were 2 and 9 respectively, this would not be found as although both values are in the array, they are not in the same positions.

For implementing this I was considering having a for … next loop within a for … next loop, but I thought that maybe a 2D array would be a lot better. However I am not sure how to implement this in VB!! The following is the code I have for searching one of the array's and my question is how would I turn this into a 2D array using inputs from two combo boxes to find a match within the array.

Code:
found = False
        For i = LBound(ArrayMyTop) To UBound(ArrayMyTop)
            If (ComboBox1.Value * 18) + 60 = ArrayMyTop(i) Then
                msg = MsgBox("Button Not Created - Already Exists", vbOKOnly, "Button Creation")
                found = True
                Exit For
            End If
        Next i
Hope this makes sense,

Chris
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Chris

How are you creating these arrays in the first place?

Are they the contents of the comboboxes?
 
Upvote 0
No, I am reading them in from a file as follows:
Code:
Open "U:/contracts.txt" For Input As #1
    k = 0
    On Error Resume Next
    Do While Not EOF(1)
        
        ReDim Preserve ArrayContract(k + 1) As Variant   'resize the array to add another place
        ReDim Preserve ArrayMyTop(k + 1) As Variant      'resize the array to add another place
        ReDim Preserve ArrayMyLeft(k + 1) As Variant     'resize the array to add another place
        
        Input #1, ArrayContract(k), ArrayMyTop(k), ArrayMyLeft(k)
        
        k = k + 1
    Loop
    Close #1
 
Upvote 0
No, I am reading them in from a file as follows:
Code:
Open "U:/contracts.txt" For Input As #1
    k = 0
    On Error Resume Next
    Do While Not EOF(1)
        
        ReDim Preserve ArrayContract(k + 1) As Variant   'resize the array to add another place
        ReDim Preserve ArrayMyTop(k + 1) As Variant      'resize the array to add another place
        ReDim Preserve ArrayMyLeft(k + 1) As Variant     'resize the array to add another place
        
        Input #1, ArrayContract(k), ArrayMyTop(k), ArrayMyLeft(k)
        
        k = k + 1
    Loop
    Close #1
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top