T
thomasp
In the code below I have a function that tests if a file exists. It takes a
variable named strFileName, simple enough. My question is, is there a way
to pass it a variable with another name as long as the variable is a string?
In different subs the variable of the file name may have a different name.
An example would be the subOpenFile listed below. I have two files that I
want to test with the function: strFileName and strFileName2. I worked
around the issue by using a temp variable, but would like a better way.
Thanks,
Thomas
Public Sub subOpenFile(ByVal strFileName As String, ByVal strFileName2 As
String, _
ByVal intImportType As Integer, ByRef
bolExitImport As Boolean)
'This sub either opens one or two file stream readers depending on
which type of import was started.
'If a Q36 import is being processed the second file stream is
opened. Since a file exists function
'was not performed on the .htg file when the import file was
selected, it is performed now. The file
'name is moved to a temp variable long enough for the function to be
ran.
Dim strTempFileName As String
srdImportFile1 = New System.IO.StreamReader(strFileName)
bolExitImport = False
If intImportType = 2 Then
Dim intLen As Integer
intLen = Len(strFileName) - 3
strFileName2 = Left(strFileName, intLen) & "htg"
strTempFileName = strFileName
strFileName = strFileName2
If funFileExists(strFileName) Then
srdImportFile2 = New System.IO.StreamReader(strFileName)
Else
bolExitImport = True
Response = MsgBox("The Targets.htg import file was not
found, exiting import.", MsgBoxStyle.MsgBoxHelp, _
"File Not Found Error!")
End If
strFileName = strTempFileName
End If
End Sub
-------------------------------------------------------------------------------------------------------------
Public Function funFileExists(ByVal strFileName As String) As Boolean
Dim Attr As FileAttribute
On Error Resume Next
Attr = GetAttr(strFileName)
If Err.Number <> 0 Then
funFileExists = False
ElseIf (Attr And FileAttribute.Directory) Then
funFileExists = False
Else
funFileExists = True
End If
Err.Clear()
On Error GoTo 0
End Function
variable named strFileName, simple enough. My question is, is there a way
to pass it a variable with another name as long as the variable is a string?
In different subs the variable of the file name may have a different name.
An example would be the subOpenFile listed below. I have two files that I
want to test with the function: strFileName and strFileName2. I worked
around the issue by using a temp variable, but would like a better way.
Thanks,
Thomas
Public Sub subOpenFile(ByVal strFileName As String, ByVal strFileName2 As
String, _
ByVal intImportType As Integer, ByRef
bolExitImport As Boolean)
'This sub either opens one or two file stream readers depending on
which type of import was started.
'If a Q36 import is being processed the second file stream is
opened. Since a file exists function
'was not performed on the .htg file when the import file was
selected, it is performed now. The file
'name is moved to a temp variable long enough for the function to be
ran.
Dim strTempFileName As String
srdImportFile1 = New System.IO.StreamReader(strFileName)
bolExitImport = False
If intImportType = 2 Then
Dim intLen As Integer
intLen = Len(strFileName) - 3
strFileName2 = Left(strFileName, intLen) & "htg"
strTempFileName = strFileName
strFileName = strFileName2
If funFileExists(strFileName) Then
srdImportFile2 = New System.IO.StreamReader(strFileName)
Else
bolExitImport = True
Response = MsgBox("The Targets.htg import file was not
found, exiting import.", MsgBoxStyle.MsgBoxHelp, _
"File Not Found Error!")
End If
strFileName = strTempFileName
End If
End Sub
-------------------------------------------------------------------------------------------------------------
Public Function funFileExists(ByVal strFileName As String) As Boolean
Dim Attr As FileAttribute
On Error Resume Next
Attr = GetAttr(strFileName)
If Err.Number <> 0 Then
funFileExists = False
ElseIf (Attr And FileAttribute.Directory) Then
funFileExists = False
Else
funFileExists = True
End If
Err.Clear()
On Error GoTo 0
End Function