jonnaboy Posted May 26, 2005 Posted May 26, 2005 Hi, I'm in need of some QUICK help! how do i write a statement so that value 1 and value 2 check value 3 to see which value (1 or 2) is numerically closer to value 3? to explain this tongue-twister further... private int hello = 21; lblgoodMorning (has a value of 13) lblgoodBye (has a value of 10) in this case, a message box would display lblgoodMorning is closer! Many Thanks Quote
IngisKahn Posted May 26, 2005 Posted May 26, 2005 Just subtract and take the absolute value. if (Math.Abs(value1 - value3) > Math.Abs(value2 - value3)) ... Quote "Who is John Galt?"
jonnaboy Posted May 26, 2005 Author Posted May 26, 2005 Thanks for your quick reply. I entered the following... void BtnBankStickClick(object sender, System.EventArgs e) { if (Math.Abs(lblRandom - thisScore) > Math.Abs(lblBankRandom - totalScore)) { lblplayerWin.Show(); }} but i get the following error message... Operator '-' cannot be applied to operands of type 'System.Windows.Forms.Label1' and 'int' any ideas? Quote
IngisKahn Posted May 26, 2005 Posted May 26, 2005 You need to access the text in the label and convert it to a number. int.Parse(lblRandom.Text) Quote "Who is John Galt?"
Leaders snarfblam Posted May 26, 2005 Leaders Posted May 26, 2005 You can't compare a label to a number. One is a number, and the other is... well... a label. Try this: void BtnBankStickClick(object sender, System.EventArgs e) { if (Math.Abs(Int32.Parse(lblRandom.Text) - thisScore) > Math.Abs(Int32.Parse(lblBankRandom.Text) - totalScore)) { lblplayerWin.Show(); }} You have to parse the text of the labels. Note that this will cause an error if either of the labels' text is not a valid number. Quote [sIGPIC]e[/sIGPIC]
jonnaboy Posted May 26, 2005 Author Posted May 26, 2005 That worked perfectly. Thank you so much! Do you know how could i go about reloading the entire form from scratch on the click of a cmd button? Quote
thenerd Posted May 26, 2005 Posted May 26, 2005 Like, restarting the program? or clearing the form? Clearing the form is me.invalidate() Restarting the program, the only way I can think of is to simply reset all the variables you used. Maybe have a sub that runs in the beginning that resets all variables, and then run that again... Quote
stustarz Posted May 26, 2005 Posted May 26, 2005 Me.Invalidate will force the form to repaint itself rather than clear it or 'reset' it. Quote Visit: VBSourceSeek - The VB.NET sourcecode library "A mere friend will agree with you, but a real friend will argue."
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.