Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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?

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted

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

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