Friday, April 3, 2009

Dim in LotusScript: Common mistake

If you need to dimension two Integer variables i and j, then in some programming languages you can do it this way:

Dim i, j As Integer

Don't do this in LotusScript, it won't work (well, it will, but not in a good way). Try the following code snippet yourself to see what Notes does here:

Dim i, j As Integer
Msgbox "Type of i: " & Typename(i) & Chr$(13) & "Type of j: " & Typename(j)

You will receive:

Notes doesn't assign a type to i (notice: NOT a bug, just different interpretation - who said you can't have misunderstandings speaking LotusScript, too ;-)). To do it correctly, you have to dimension the variables the old-fashioned way:

Dim i As Integer
Dim j As Integer

More lines of code, but safer (and actually more readable, too).

2 Comments:

Anonymous Vitor Pereira said...

I think you can do it: Dim i as Integer, j As Integer

April 19, 2009 2:45 PM  
Blogger marcusfoerster said...

Hi Vitor,
thanks for your comment. This is correct, that is one way to do it. What I have seen, though, is that the first "as Integer" gets forgotten often.

April 20, 2009 7:53 AM  

Post a Comment

Thank you for your comment. It will be published shortly. Keep having a great day!

<< Home