Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Questions 1

Status
Not open for further replies.

MelissaKT

Technical User
Jun 22, 2004
95
0
0
US
I am attempting to use arrays for the first time. I've scanned this website and looked at Ken Getz's Developer's Guide. I'm really confused.

Here's what I'm planning on doing with the information - maybe somebody can come up with a better idea? I have a subform that has a PO number combo box. Once a user chooses the PO number that they want to pay, a dialog box with a multiselect list box comes up and allows the user to select several items (budget accounts and totals). I want to append that data to the subform. I'm going to use a public form variable and build a string to send back to the subform. At this point, I think an array would be a really good way to split it out. The question is how do I build columns for the array? How do I append the data to the array columns? I would truly appreciate ANY help understanding how to make this work. Thank you in advance

 
I do not think that you need an array, however, here are a few notes:

[tt]'Note 1
ThisArray=Split("a,b,c",",")

Debug.Print ThisArray(0) 'a
Debug.Print ThisArray(2) 'c

'Note 2
Dim ThisArray(2, 1)

ThisArray(0, 0) = "a"
ThisArray(1, 0) = "b"
ThisArray(2, 0) = "c"
ThisArray(0, 1) = "1"
ThisArray(1, 1) = "2"
ThisArray(2, 1) = "3"

Debug.Print ThisArray(0, 1)[/tt]
 
I've just found some good information in a book called VBA Developer's handbook by Ken Getz. Here's what I've got so far:
In the Dialog Form that allows the user to choose several different budget accounts, I have
Code:
Dim i As Integer
Dim strSelectedTEMP As String
strSelectedTEMP = ""
With Me.lstPO
    For i = 0 To .ListCount - 1
        If .Selected(i) Then
            strSelectedTEMP = strSelectedTEMP & .Column(0, i) & ";" & .Column(1, i) & ";" & .Column(2, i) & ";"
        End If
    Next i
End With
strSelectedTEMP = Left(strSelectedTEMP, Len(strSelectedTEMP) - 1)
strSelected = strSelectedTEMP
Debug.Print strSelected
Me.Visible = False
This seems to be working well. It builds the string that I want to send back to my other form. In the form that is receiving the information, I have:
Code:
If IsLoaded("frmPONumberBudgetAcctDIALOG") Then
    Dim astrPONumber()
    astrPONumber = Split(Forms("frmPONumberBudgetAcctDIALOG").strSelected, ";")
    
End If

If I understand correctly, I need to redim the ary with the number of values that it is going to hold and the number of columns. How do I tell how many values that I need to redim with? It could be a different number of values each time. I'm really confused. I hope I'm explaining where my confusion lies?

 
If you are using Split, you don't need to know anything about the array. You can get the number of items in the array with UBound:

[tt]astrPONumber=Split(strSelected,",")

For i=0 To Ubound(astrPONumber)
Debug.Print astrPONumber(i)
Next[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top