I am new to VBA and I am having a hard time understanding how variables are passed from one procedure to the next. The following code works up until I click an option in ListBox1, when that happens I get an error stating "Sub or Function not defined"... the error is refering to the array named Jobarray. How do I get the procedure "UserForm_Initialize" to pass the variable to "ListBox1_Click"?
Code:
Private Sub ListBox1_Click()
listnum = ListBox1.ListIndex
fn = Jobarray(listnum, 2)
End Sub
Private Sub UserForm_Initialize()
Dim MyFile, MyPath, MyName, intI As Integer
Dim Jobarray(50, 50) As String
MyPath = "F:\"
MyName = Dir(MyPath, vbDirectory)
intI = 0
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
If Left(MyName, 5) Like "#####" Then
Jobarray(intI, 0) = (MyPath & MyName)
intI = intI + 1
End If
End If
End If
MyName = Dir
Loop
intB = 0
intC = 0
Dim Check
JobPath = Dir(MyName, vbNormal)
Do While JobPath <> ""
JobPath = Jobarray(intB, 0)
If JobPath <> "" Then
FabName = Dir(JobPath & "\*.txt", vbNormal)
Jobarray(intC, 1) = FabName
intB = intB + 1
intC = intC + 1
End If
Loop
ListBox1.ColumnCount = 1
TmpName = "temp"
intC = 0
intD = 0
Dim TempArray(50) As String
Do While TmpName <> ""
TmpName = Jobarray(intC, 1)
TmpLen = Len(TmpName)
NewLen = TmpLen - 4
If TmpName <> "" Then
TmpFab = Left(TmpName, NewLen)
End If
If TmpName <> "" Then
Check = Filter(TempArray, TmpFab)
Check1 = UBound(Check)
If Check1 = -1 Then
TempArray(intD) = TmpFab
intD = intD + 1
End If
End If
intC = intC + 1
Loop
intE = 0
Do While TempArray(intE) <> ""
ListBox1.AddItem UCase(TempArray(intE))
intE = intE + 1
Loop
ListBox3.ColumnCount = 1
ListBox1.TextColumn = 1
ListBox3.TextColumn = 1
End Sub
Thanks in advance.
Greg
Bookmarks