% symbol - what is it for (ie counter%) - Lotus Script

I’ve seen the % symbol used. Especially for a counter% used with an array. What does this % do?

I’m getting a subscript out of range error. Might this have something to do with not using the %?

If someone would please help me with what the % does then I think I can solve my out of range problem on my own.

Thanks.

Subject: % symbol - what is it for (ie counter%) - Lotus Script

Success! Thank you for all of your input. The 1st answer I got was what I needed. Sorry, I should have said that right away. I just started the Forum a couple weeks ago and I’m still learning the etiquette.

My question was about the % as I had never seen it before. I always declare my variables. However, I didn’t realize I could force the declaration with “option include” / that’s great!

Turns out, my out of range wasn’t related to the %. I had a hard time in the debugger since I had no idea what % did.

Out of range problem was caused by improper initialzation of my array. I had a “redim” instead of a “redim preserve”.

Thanks again for all your help and great input. I learned several new things.

I’ll be sure to do a better job with forum etiquette next time I have a question.

(Also, I started Notes Development about 3 months ago, and Lotus Script about 1 month ago, so I get confused about obvious things sometimes.)

Subject: % symbol - what is it for (ie counter%) - Lotus Script

Paul,

The % tells Lotus script that the variable is an integer.

Subject: RE: % symbol - what is it for (ie counter%) - Lotus Script

And if you ask me, it’s best avoided. Dim all your variables and use Option Declare to remind you to do it, and there’s no need for this ugly postfix notation.

As for the subscript out of range, there are a couple of potential reasons. The most likely is that your counter really IS out of range. By default, arrays start at index 0 (unless you use Option Base 1) and end at what upper bound was set in the array declaration. Any value for counter < 0 or > upper bound will raise this array. Arrays can also be explicitly defined for a different range, like e.g.

Dim months(1 to 12) as Integer

In this case, it’s pretty obvious what range valid indexes have to be in.

Designer help states, that array bounds must fall in the range -32768 to 32767, but this is only half of the truth. You actually can not define an array ranging from -32768 to 32767, because the size of the array cannot exceed 32767 elements.

A counter variable of type Integer should keep you from specifying a too big range for an array, so the most likely reason is the variable really being out of range. Use the Debugger to check.

Subject: postfix notation has its uses…

I find postfix notation helpful when setting my constants, but I never use it for my variables.

And I agree totally on using Option Declare. saves a ton of time when it comes to debugging. Besides, just randomly throwing variables out there dims them as Variants by default, and in my estimation that’s just sloppy programming.

just my 2 unasked for cents…

brandt

Subject: RE: postfix notation has its uses…

Not to mention the old classic of

Dim i, j, k as Integer

which will leave you with two Variants and one Integer …

Subject: % symbol - what is it for (ie counter%) - Lotus Script

As another person said: the %-sign tells LotusScript compiler that it is a variable of INTEGER. It is very likely that You try to exceed its maximum capacity (32767) and therefore it should be declared as LONG instead.

Remove the %-sign from the code and replace it with Dim myVariable As Long at the start of the code instead.

hth

Subject: RE: % symbol - what is it for (ie counter%) - Lotus Script

Declaring the index as long will not help at all, since array bounds are limited to integer values.

Subject: RE: % symbol - what is it for (ie counter%) - Lotus Script

Ah - of course! I didn’t noticed that the discussion was about ARRAYS. Assumed that it was a discussion about just normal variables used for counting…Yes, the array bounds are limited to 32767 elements.

We haven’t seen any code, so its pretty difficult to help solving this issue… It has to be solved on a higher level discussing only general principles/workarounds etc.

Thank You for pointing out the problem with my answer!

Subject: Where’s the code, Paul?

"We haven’t seen any code, so its pretty difficult to help solving this issue… "

Yep. Some more input would make this guessing game a little easier.