Finding File With Wildcard Follow

0
Avatar
Legacy Poster

Hello.

I'm using BarTender to make ID-cards from the info in our employee database. Works great, but I'm trying to get one specific function togheter...

Currently the photo of the person is inserted automatically based on a four digit employee number and name, like this:

FileName = EmployeeNr & FirstName & LastName & ".bmp"

The problem with this is that the file naming has not always been consistent. Renaming the files is (at the moment) not an option since we are talking about a thousand files. The only thing that I can be sure of is the employee number.

Therefore I would like to use a wildcard (*) to search for the file name. Search for a file containing the employee number and add that photo to the ID.

I have a very basic understanding of VB and have been able to get some nifty things togheter in BarTender, but this has me stumped.

Gratefull for any help
Best regards
Johan Oscarsson

2 comments

0
Avatar
Legacy Poster
Comment actions Permalink

Thought I'd answer my own post...

Managed to find a way to use only the employee number when searching for a photo, like so:

[code]Dim fso, f, f1, fc, fq

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("G:\gsgem\EmployeePhoto")
Set fc = f.Files
fq = 0

For Each f1 in fc
EmployeeNrVar = Mid(f1.name, 1, 4)
If EmployeeNrVar = EmployeeNr Then
FileName = f1.name
fq = 1
End If
If fq = 1 Then
Exit For
End If
Next

Value = FileName[/code]

Works quite nice... [s]But, it's slooooooooow! Since I have so many photos to look through it takes about 1-2 minutes to find each photo.

If anyone has a better way, please let me know.[/s]

Edit: Added an "Exit For" to make the search a little faster. When the right photo is found, exit the search...
0
Avatar
Fernando Ramos Miracle
Moderator
Comment actions Permalink

Hello Johan,

Many thanks for providing your own answer for your post. As the "Files Collection" is probably the way to go with this issue as you've already illustrated I just wanted to add a general example for a function using the For Each... statement:

[i]Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function[/i]

Regards.

Please sign in to leave a comment.