Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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.

Posted

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.

 

:(

"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).
Posted

Initial Value

 

Have you checked the initial value of 'Studio' ??

 

Try using

 


Dim Studio as Integer = 1

"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
Posted (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 by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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 !!!

"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).
Posted

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

Posted

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 !

 

;)

"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).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...