Right function not working

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
 
D

Dirk Goldgar

Max Moor said:
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

I suspect that you have, or maybe used to have a function, variable, or
control named "right" (uncapitalized). What happens if you click on the
function name and press Shift+F2 (View Definition)? Have you searched
your project for that string (matching case)?
 
M

Max Moor

@TK2MSFTNGP11.phx.gbl:

I suspect that you have, or maybe used to have a function, variable, or
control named "right" (uncapitalized). What happens if you click on the
function name and press Shift+F2 (View Definition)? Have you searched
your project for that string (matching case)?

Hi Dirk,
Dumb, dumb, dumb. I kept staring at the code after I hit "Send", and
found a bug making the length argument come out negative. That was causing
the break in execution.
I'll try what you suggest to figure out the name capitalization part.
I didn't know about the view definition thing. Keep a good thought, and
thanks.

- Max
 
N

Naresh Nichani MVP

Hi:

Your could try VBA.Right -- prefix VBA before the right to see if it helps
as well.

Regards,

Naresh Nichani
MS Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top