Issue using val() in LO Basic

I have the following code:

rx = mid(e, p*7 - 6, 3)
cx = mid(e, p*7 - 3, 3)
row = int(val(rx))
col = int(val(cx))

But when I run it with the debugger and break on the next line, row and col are both zero:
Watch

I can’t figure out why. Int() is used here as a WAG due to Val() returning a Double, obviously with no help. I thought maybe the leading zeros was throwing Val() off, so I removed them and still no-go. MsgBox Val(“001”) shows 1 too. If I throw MsgBox val(cx) in after the cx = line, the pop-up is empty/blank. It’s like the val() function is not being recognized or something is causing it to return Nothing.

I’m relatively new to LO Basic (but not basic - although its been a while - nor software development). Am I missing something?

Any help would be greatly appreciated!

Thanks,

Chuck

Hello,

Don’t have any problem with or without Int():

image description

Must be something else you may have redacted.

Here rx & cx are Dim’ed as string but same result using Variant. row & col Dim’ed as Integer.

Also, using val = will error as Invalid procedure call.

(Oh, yeah…) Thanks for the reply. I did figure it out before I saw it though… The "Also using val = " would have made it obvious!

OK, I’m embarrassed! I have defined a variable “val” as string.
Hope this helps someone someday! :slight_smile:

Chuck

Do not use the function names (reserved names) as a variable name. If you need it anyway, then use a prefix letter: sVal for string, or iVal for integer - depended on the type of the variable. Then you will remember the type, when you use the cariable in your macro code.

Thanks for the reply. I’ve been a professional software developer for over 40 years, so I know how to resolve such an issue :slight_smile: :slight_smile: :slight_smile: It just didn’t strike me, even though two lines later I used the function name as a variable. That’s what happens sometimes when you’re spending too much time coding. :wink: