Limit values of my Integer

joe_pool_is

Well-known member
Joined
Jan 18, 2004
Messages
451
Location
Texas
I have an integer that is used to index an array. The array has 12 elements in it, so I want to access it with different loops (for, case, while, etc.).

Somehow, my program is setting this integer value to 12, which causes problems on a 0 to 11 array.

I cant find anyplace that sets the value to 12 in the code, either. Ive been stumped on this for a couple of days.

1. Is there a way I can limit the variables values to only 0 - 11?

2. Is there a way to set a flag so that as soon as this variable is assigned a value above 11, my debugger can stop program execution?
 
Even better, you can create your array to start at 1, therefore 12 would be the right number.

Without seeing your code, the integer is counting how many items are in your array, if you want the array to start with a 0, you could always set the integer to -1, or use a until INTEGER-1.
 
Hey Jay,

I gave that a try, but now for some reason my code is incrementing my integer i to 13, and now 13 is outside the bounds of my array. Grrr!

Anyone: Is there a way to cause my program to Break when i > 12?
 
Break at 12

Cant you just add a watch on i and ask to break when i > 12 ????

I expect the problem is that you do not reset i when you do the second loop, hence it is looking to loop from 13 to 24.

:(
 
I probably could if I were a little better at that debugger. Ive got a watch set on it, and it looks like the integer called Studio is set to 13 after the Form Load. I havent even accessed the value Studio yet at this point!
 
Edit: had chance to look at it.

Sheppard earlier seems to have hit on the cause - at the end of the Ticker_Tick sub Studio will be set to 13.
Is there a reason you need to check the value so early on in the routine - you will reset it as part of the for next loop anyway.

Although the value of Studio does seem to be reference in several places - one of the downside of using global variables is that things can get confusing, plus changes can have unforseen consequences.

You maybe better of moving some of those variables into classes or structures and providing Methods / Properties to acces them - at least that way you can see when they are being modified and provide centralised validation.
 
Last edited by a moderator:
Looping

Yes, good point.

It is always a good idea to use a local variable when using it just for looping.

i.e. The integer only acts as a counter and is not used elsewhere in the program.

I would suggest using 3 different variables for the loops.

Code:
Dim a as integer = 0, b as integer = 0, c as integer = 0

This makes it much easier to follow and avoids any unwanted increments !!!
 
Thanks for the suggestions *and* for taking the time to digest my code well enough to provide a good reply.

You two are probably wondering: What is this for? I work at a Closed Captioning facility. Here, we have several Studios where captioning data is sent out by Live Captioners (Stenographers). The switchers are in each individual Studio, and they allow the Captioners to select the source of the data. The program enables the engineers in the Command Center to monitor the settings in the Studios and (if need be) make a data selection when a Captioner forgets.

Again, thanks for the help!
http://www.ncicap.org
 
Eh?

To be honest with you I didnt look at your code, nor do I have a clue what closed captioning is !

BUT, Im glad that you have found our advice helpful and wish that your project goes well.


Take it easy - whatever you get up to !

;)
 


Write your reply...
Back
Top