Hi People.
So, i'm not sure if this is the way VBA wants me to do this.. but here it is.
global filearr(1 to 4) as string
Private Sub buttonBrowse1_Click() 'file1
Dim fn As String
fn = Application.GetOpenFilename _
(Title:="Open Webroot File 1", MultiSelect:=False) 'open the file
Call outputFileNames(1, tbFileOne, fn) 'call the output function with given parameters
^^^^ TBFILEONE IS AN ACTIVEX TEXTBOX [see the subroutine below]
End Sub
Private Sub outputFileNames(fileCount As Integer, obj As TextBox, filename As String)
If Len(filename) > 0 Then 'if filename is there...
fileArr(fileCount) = filename 'set the global variable
If Len(fileArr(fileCount)) > 50 Then 'if its too big for the box
Dim splitter() As String
splitter = Split(fileArr(fileCount), "\") 'split based on \
Dim i As Integer 'forloop
Dim max As Integer 'max num of splits to show
If (UBound(splitter) > 3) Then
max = 3 'if the split path is massive set it to 3
Else
max = UBound(splitter) 'otherwise it is 2 or 1
End If
obj.Value = "" 'initialize texbox to ""
For i = 0 To max
obj.Value = obj.Value & splitter(i) 'enter the first half of the path
Next
obj.Value = obj.Value & "..." & splitter(UBound(splitter)) '.. and then last entry
Else
obj.Value = fileArr(fileCount) 'if its small enough, just output
End If
Else
obj.Value = ""
End If
End Sub
Basically i want to re-use the code because I'm going to have so many textbox's and browse box's that need this split done, I dont want to copy-paste this code everywhere and worry about scope and variable names..etc.
My problem is that VBA is giving me a type mismatch as marked above in red text. My guess is that VBA doesnt like how I'm passing this textbox to use it dynamically.
Hints?