-
This is an exerpt of my code, it goes on like this 9 times! Ugh! I know I can shorten it by useing an array or an index but I havn't a clue how to make that work. Anyone feel like helping me?
Public Function MultiDirExport(ExportPath)
Dim DirExport As String
If frmMultiDir.txtDir(0).Text = "" Then
Exit Function
Else
DirExport = frmMultiDir.txtDir(0).Text
DosShell "dir /b " & DirExport & " >> C:\Windows\Temp\MP3_Export.txt"
End If
If frmMultiDir.txtDir(1).Text = "" Then
Exit Function
Else
DirExport = frmMultiDir.txtDir(1).Text
DosShell "dir /b " & DirExport & " >> C:\Windows\Temp\MP3_Export.txt"
End If
If frmMultiDir.txtDir(2).Text = "" Then
Exit Function
Else
DirExport = frmMultiDir.txtDir(2).Text
DosShell "dir /b " & DirExport & " >> C:\Windows\Temp\MP3_Export.txt"
End If
End Function
-
Hello Yogi_Bear_79,
You could do it this way:
Code:
Public Function MultiDirExport(ExportPath)
Dim DirExport As String
Dim I As Integer
For I = 0 To frmMultiDir.txtDir.Count
If Len(frmMultiDir.txtDir(I).Text) > 0 Then
DirExport = frmMultiDir.txtDir(I).Text
DosShell "dir /b " & DirExport & " >> C:\Windows\Temp\MP3_Export.txt"
End If
Next I
End Function
Hope this helps,
-
Your wrong Rwa, because Yogi_Bear_79 exit function after the first txtDir(i)="". The code look like this
Code:
Public Function MultiDirExport(ExportPath)
Dim DirExport As String
Dim I as integer
dim MaxI as integer
Maxi=frmMultiDir.txtDir.Count
For i=0 to MaxI
If frmMultiDir.txtDir(0).Text = "" Then
Exit Function
Else
DirExport = frmMultiDir.txtDir(0).Text
DosShell "dir /b " & DirExport & " >> C:\Windows\Temp\MP3_Export.txt"
End If
Next
End Function
-
Well there KWell,
Your code will only check one textbox:
If frmMultiDir.txtDir(0).Text = "" Then
Then finish looping while checking nothing. I think my code will work a little better. It will write to the log file if any of the textbox's have text in them.
Best,