Hello AUGI Members,
I have a VBA routine that allows me to select a directory of drawing files and display them in a dialog list box so I can either choose all of them or individual files for a batch operation. The difficulty I am having is that when the file list displays in the list box area they are not in alpha numeric sequence. Can anyone take a look at the sample code below and let me know what needs to be done to sort the list of drawing files so they appear in the list box in the correct sequence....??
Private Sub cmdBrowse_Click()
CDia.DialogTitle = "...Please Select Drawing .DWG Directory"
CDia.Filter = "(*.dwg) |*.dwg|"
CDia.CancelError = False
CDia.ShowOpen 'The CommonDialog accounplishes these
DwgDir = GetPath(CDia.FileName) 'Gets the string path value from the GetPath function
txtDwgDir.Text = DwgDir 'varible defined as public in module (can pass value to other functions, This will hold the dir path value for each drawing
Call PopAvail
If lstAvail.ListCount <> 0 Then
SBar.SimpleText = "...Select .dwg(s) To Plot"
Else: SBar.SimpleText = "...Please Select Directory"
End If
SBar.Refresh
End Sub
Public Function GetPath(FullStr As String)
Dim pos As Integer
Dim LstPos As Integer
pos = 1 'set the pointer to the first position
Do Until pos = 0
pos = InStr(pos, FullStr, "\") 'Reading the string Path
If pos = 0 Then Exit Do
pos = pos + 1: LstPos = pos - 1
Loop 'This will start at the 1 pos and read to till there is no more pos.
FullStr = Left(FullStr, LstPos) 'Reads the string is found
GetPath = FullStr 'sets the value
End Function
Public Function PopAvail() 'Gets the object list from the path location (GetPath)
Dim tempstr As Variant 'Value to count by
Dim strDwgName As Variant
lstSelect.Clear
lstAvail.Clear
strDwgName = Dir(DwgDir & "*.dwg"): 'set the dir path and Filename value
tempstr = Dir(DwgDir & "*.dwg"): 'set the dir path and Filename value
If tempstr <> "" Then
tempstr = Left(tempstr, Len(tempstr) - 4) '?Start, get lenth of str and counts back 4?, not to path but filename?
lstAvail.AddItem tempstr
End If
Do Until tempstr = ""
tempstr = Dir
If tempstr <> "" Then
tempstr = Left(tempstr, Len(tempstr) - 4)
lstAvail.AddItem tempstr
End If
Loop
End Function
Any assistance would be appreciated.
Best Regards,
Vince