-
Jan 18th, 2018, 02:28 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Simple way to pass a filename as a parameter
Is there simple way to pass a filename as a parameter?
-
Jan 18th, 2018, 02:41 PM
#2
Re: Simple way to pass a filename as a parameter
A parameter to what? Do you have the file name? Do you need to show a dialog to have the user select a file name? Would be helpful if you can provide far more details.
-
Jan 18th, 2018, 02:49 PM
#3
Thread Starter
Frenzied Member
Re: Simple way to pass a filename as a parameter
Sorry. I want to pass a parameter to a routine, successively with a number of existing filenames.
-
Jan 18th, 2018, 02:51 PM
#4
Re: Simple way to pass a filename as a parameter
Well, you'd write your routine to accept a parameter, i.e.,
Code:
Public Sub ProcessTheFile(FileName As String)
' do whatever with the file you are passing
End Sub
' and in some other part of your code, you'd call the routine:
ProcessTheFile myFileName
-
Jan 18th, 2018, 02:59 PM
#5
Re: Simple way to pass a filename as a parameter
Hi el84,
Still working on that Word automation project?
Yeah, as LaVolpe says, I think we need a few more details. In most cases, a filename is just a string. I pass them all over the place all the time.
Code:
Public Sub UnpackSupportFile(sFileName As String, ByVal sPathWhereToSave As String, Optional bOverwriteIfExists As Boolean = True)
AddSlash sPathWhereToSave
If bFileExists(sPathWhereToSave & sFileName) Then
If Not bOverwriteIfExists Then Exit Sub ' User must handle existing file and what to do.
End If
RetrieveResourceFileAndSaveToDisk sPathWhereToSave, sFileName, "Support", bOverwriteIfExists
End Sub
Code:
Public Function LoadResourceFileFromName(sFileName As String, sResourceType As String) As Byte()
' Loads the specified data file resource from the current project's resource (.RES) file, actually the .EXE once compiled.
' sFileName Specifies the unique name of the data file resource.
' sResourceType Optional. Specifies the "type" of data file being returned. The Visual Basic default for data files is "CUSTOM".
'
' Will error if not found. Note that CASE doesn't matter in the LoadResData call.
' However, spaces are not allowed in resource names, so they are removed.
LoadResourceFileFromName = LoadResData(Replace$(sFileName, " ", vbNullString), sResourceType) ' Returns a Byte array.
End Function
Code:
Public Function PathFromListview(lsv As ListView, sFileName As String) As String
' Returns vbNullString if not found.
Dim i As Long
'
For i = 1 To lsv.ListItems.Count
If UCase$(lsv.ListItems(i).Text) = UCase$(sFileName) Then
PathFromListview = lsv.ListItems(i).SubItems(1)
Exit Function
End If
Next i
' Return vbNullString if we drop out.
End Function
Truth be told, I more typically pass the entire file specification (path & name), rather than just the name.
Take Care,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 18th, 2018, 03:01 PM
#6
Re: Simple way to pass a filename as a parameter
Ahhh, sorry. I was taking too long to assemble my post. From what you said in post #3, it sounds like an exploration of the ParamArray keyword may also be useful to you.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Jan 18th, 2018, 03:17 PM
#7
Thread Starter
Frenzied Member
Re: Simple way to pass a filename as a parameter
LaVolpe: That's exactly what I wanted. Many thanks. It was the As String that I had omitted. I'll mark this resolved
Elroy: I have now solved that original problem and will post all my code in that thread shortly. Thanks too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|