TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sam
NA
166
0
Problems in IF condition
Mar 7 2012 5:08 AM
Hi,
I have a strange situation as follows:
There are several (public) NumericUpDown controls.
I wish to multiply the Value of one of the controls by factor 100.
I set the controls limits (min and max) and all other parameters accordingly.
The specific control is identified in an 'if' condition by its Name or Tag.
if (numUpDn.Tag == "09"
) {
numUpDn.Value = numUpDn.Value * 100;
}
The problem is that the multiplication by 100 is performed twice, resulting in a large number, out of the control max limit.
When running in single step debug, the first time the value is multiplied by 100 and gets its correct value,
but on the next step it does not exit the 'if' condition, but seems to once again run the multiplication, causing out of range exception, with a number
100 times its expected value (total multiplication by 10,000 ).
Furthermore, I found out that if the multiplier number is small enough (like 2 instead of 100), it will loop and multiply until out-of-range exemption will occur.
If I change the Tag inside the assignment {....} BEFORE multiplying, it will pass one time and be OK (the condition is false!).
If I do the same AFTER the multiplication, it will pass twice and will fail.
if (numUpDn.Tag == "09"
) {
numUpDn.Tag =
" "
;
numUpDn.Value = numUpDn.Value * 100;
}
Does anyone have an explanation to this phenomenon?
Is my syntax wrong?
Is there a way to force out of the if after execution?
Thanks
sam
Reply
Answers (
5
)
GridView
picture