April 24, 2024, 05:49:17 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Strange - why does this variable change?

Started by Andy, December 13, 2020, 08:49:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

December 13, 2020, 08:49:46 PM Last Edit: December 13, 2020, 08:51:43 PM by Andy
In my include file I have the following:

1. An INT variable

INT Ucase = 0

2. An INT variable to store X number of subroutine line numbers.

INT Subs[5000]

3. A subroutine that uses the Subs variable.

SUB StoreSubs()
    INT a1 = 0
    FOR a1 = 1 TO 5000 '<------ Took this down to 5,000 instead of 500000....
      Subs[a1] = 0
    NEXT a1
    INT lvcount = CONTROLCMD(w1,ListView2,@LVGETCOUNT)
    SubCount = lvcount
    FOR a1 = 0 to lvcount
      CONTROLCMD(w1,ListView2,@LVGETTEXT,a1,1,text)
      INT SubVal = val(Text)-1
      Subs[SubVal]= SubVal
    NEXT a1
ENDSUB

Now, the variable Ucase (unless a user changes this setting in my "Settings" option) is set to 1 by default.

It was being set to zero (for some reason), and I traced it all the way back to the above subroutine.

As you can see, nowhere in the sub does it refer to / or change Ucase...

When I originally added in the Subs variable it was set to a stupidly high number

Subs[50000000] (think it was a typo that I forgot to correct)

Out of desperation I amended it to 5,000 (which is more than enough), amended to sub to 5,000 and now Ucase remains 1 which is correct.

The question is why would Subs[50000000] cause another variable to change?

I've checked out the facts on this and I know I didn't miss anything.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

billhsln

December 13, 2020, 09:25:00 PM #1 Last Edit: December 13, 2020, 09:32:02 PM by billhsln
Any time I have had a variable that went wonky, it was do to going over the bounds of an array.  IE:
DEF arry[100]:INT
DEF ucase=1:INT

FOR i=1 to 100:arry[i]=0:NEXT i

You don't get an error for this and you would end up with ucase being 0.

I have done this so many times, it isn't even funny.  Learned to create a max variable for any array that I create and make sure it does not go above the bounds.

DEF max=100-1:INT :' forces me to remember that we are 0 based

FOR i=1 to max:arry[i]=0:NEXT i

Obviously when you load to the next available array element, you will need to check to make sure it is not > max too.

Bill
When all else fails, get a bigger hammer.

Andy

Thanks Bill,

Didn't know that!

Very interesting, and no it's not funny, I was undoing a simple paste in my editor and all the key words were suddenly going to lower case which only happens when the variable Ucase is set to zero.

So this lesson is a "must remember" one.

Thanks again,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.