M
Max Moor
Hi All,
I'm playing with reading from a file for the first time. The code
below isn't very robust or polished, but I'm trying things out with it.
I've read a line from a text file. The first part of the line will be a
"key" name, followed by the data I want to return from the file. The
problem is the "Right" function. When I edit that line and move the
cursor, VB changes the 'R' to a lower case 'r'. Then when the code
runs, I get an "invalid procedure call or argument" error. I've used
"Len" and "Mid" in other modules, so I don't think it's a reference
problem. Anyone have any thoughts?
- Max
Public Function ReadFilterKey(strKeyName As String) As String
Dim varKeyLine As Variant
Dim strKeyData As String
Dim lngKeyNameLen As Long
Dim lngKeyLen As Long
strKeyData = Application.CurrentProject.Path
Open Application.CurrentProject.Path & "\MyDB.flt" For Input As #1
Do While Not EOF(1)
Line Input #1, varKeyLine
varPosition = InStr(varKeyLine, strKeyName)
If (varPosition <> 0) Then
lngKeyNameLen = Len(strKeyName) + 1
lngKeyLen = Len(strKeyName)
strKeyData = right(varKeyLine, lngKeyLen - lngKeyNameLen)
Exit Do
End If
Loop
Close #1
ReadFilterKey = strKeyData
End Function
I'm playing with reading from a file for the first time. The code
below isn't very robust or polished, but I'm trying things out with it.
I've read a line from a text file. The first part of the line will be a
"key" name, followed by the data I want to return from the file. The
problem is the "Right" function. When I edit that line and move the
cursor, VB changes the 'R' to a lower case 'r'. Then when the code
runs, I get an "invalid procedure call or argument" error. I've used
"Len" and "Mid" in other modules, so I don't think it's a reference
problem. Anyone have any thoughts?
- Max
Public Function ReadFilterKey(strKeyName As String) As String
Dim varKeyLine As Variant
Dim strKeyData As String
Dim lngKeyNameLen As Long
Dim lngKeyLen As Long
strKeyData = Application.CurrentProject.Path
Open Application.CurrentProject.Path & "\MyDB.flt" For Input As #1
Do While Not EOF(1)
Line Input #1, varKeyLine
varPosition = InStr(varKeyLine, strKeyName)
If (varPosition <> 0) Then
lngKeyNameLen = Len(strKeyName) + 1
lngKeyLen = Len(strKeyName)
strKeyData = right(varKeyLine, lngKeyLen - lngKeyNameLen)
Exit Do
End If
Loop
Close #1
ReadFilterKey = strKeyData
End Function