joe_pool_is Posted January 22, 2004 Posted January 22, 2004 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 can't find anyplace that sets the value to 12 in the code, either. I've been stumped on this for a couple of days. 1. Is there a way I can limit the variable's 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? Quote Avoid Sears Home Improvement
Jay1b Posted January 22, 2004 Posted January 22, 2004 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. Quote
joe_pool_is Posted January 22, 2004 Author Posted January 22, 2004 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? Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted January 22, 2004 Administrators Posted January 22, 2004 If you could post your code it would help us to find the problem... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted January 22, 2004 Author Posted January 22, 2004 Attached is the entire project, entitled SwitcherTester.zip. I had to delete the bin and obj folders to conserve space.switchertester.zip Quote Avoid Sears Home Improvement
Sheppard Posted January 22, 2004 Posted January 22, 2004 Break at 12 Can't 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. :( Quote "Today I saw a little worm wriggling on his belly. Perhaps he'd like to come inside and see what's on the telly." - Spike Milligan (Tribute).
joe_pool_is Posted January 22, 2004 Author Posted January 22, 2004 I probably could if I were a little better at that debugger. I've got a watch set on it, and it looks like the integer called Studio is set to 13 after the Form Load. I haven't even accessed the value Studio yet at this point! Quote Avoid Sears Home Improvement
Sheppard Posted January 22, 2004 Posted January 22, 2004 Initial Value Have you checked the initial value of 'Studio' ?? Try using Dim Studio as Integer = 1 Quote "Today I saw a little worm wriggling on his belly. Perhaps he'd like to come inside and see what's on the telly." - Spike Milligan (Tribute).
Administrators PlausiblyDamp Posted January 22, 2004 Administrators Posted January 22, 2004 (edited) 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. Edited January 22, 2004 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Sheppard Posted January 23, 2004 Posted January 23, 2004 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. 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 !!! Quote "Today I saw a little worm wriggling on his belly. Perhaps he'd like to come inside and see what's on the telly." - Spike Milligan (Tribute).
joe_pool_is Posted January 23, 2004 Author Posted January 23, 2004 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 Quote Avoid Sears Home Improvement
Sheppard Posted January 23, 2004 Posted January 23, 2004 Eh? To be honest with you I didn't look at your code, nor do I have a clue what 'closed captioning' is ! BUT, I'm glad that you have found our advice helpful and wish that your project goes well. Take it easy - whatever you get up to ! ;) Quote "Today I saw a little worm wriggling on his belly. Perhaps he'd like to come inside and see what's on the telly." - Spike Milligan (Tribute).
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.