Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wierd Error

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
Okay I have 90 image boxes with tags, If th e user press next 6 is added to every tag.

So

For i = 0 to 89
temp = minpic(i)+6
minpic(i).tag = temp
Next i

Now unless i add a msgbox inbetween the minpic it will not work, then if i do add it it bombs out at the very end. Brad,
Free mp3 player,games and more.
 
It is not wierd. The code is wrong. You may like to try the following:

For i = 0 to 89
temp = minpic(i).tag + 6
minpic(i).tag = temp
Next i
 
Really? It works fine here (in a test bed where I just added 89 new image controls, and then ran the corrected tag update code). Perhaps you could provide a little more of your code to give some better context.
 
Here is the exact thing, Each of the images has a tag. I made sure of that.

For i = 0 To 89
temp = minpic(i).Tag + 6
minpic(i).Tag = temp
Next i
Brad,
Free mp3 player,games and more.
 
The code is weird? In my opinion it's equivalent to
For i = 0 to 89
minpic(i).tag = minpic(i).tag + 6
next i


Which then means that you take the value of a Tag, add 6 and stores the result into the same tag. That could be OK, but if my assumption is correct, then I have 2 questions:

1. Did you use any Dim statement to declare your variables?
The Tag property is a String variable to which you add a numerical value. If you didn't declare the temp variable, VB will make it a variant. That takes a lot of conversions and inevitable surprising results (if any).

2. Where did you initialize the tags? The first time you go through the loop minpic(0) will contain the Null string. VB will not allow numerical operations on Null strings.

So check your declarations and initializations before proceeding. (Option Explicit is not a waste of time, as some programmer's are tempted think) _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top