Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

This should be a very basic question for almost everyone here, but since I dont know alot about vb.net yet, i dont know the answer.

 

In a button's code I want it to add the value of what is in TextBoxes and display it in a label.

 

 

I want it to add then divide the following by 4:

 

AttackBox+DefenseBox+StrengthBox+HitsBox/4

Edited by Lanc1988
Posted

I tried

 

Label14.Text = Math.Round.Label16

 

 

But it says that round failed. How would I use the round function to round whats in Label16 and display it in Label14?

Posted (edited)

Try Label14 = Math.Round(cint(Label16.Text), 0)

 

 

 

*Post Edit

 

 

Label14 = cint(Label16.Text)

 

If label16 is 45.3, then cint(45.3) would give 45 as integers are whole numbers anyway.

 

Just tried it and CInt() rounds a decimal to a whole number so Math.Round is not needed.

Edited by sjn78
Posted (edited)

this is crazy.. it says Value of type 'Integer' cannot be converted to 'System.Windows.Forms.Label'.

 

it underlines CInt(Label16.Text) in blue and says that above error... any ideas?

Edited by Lanc1988
Posted

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

On Error Resume Next

'Assign text box values to variables

Attack = AttackBox.Text

Defense = DefenseBox.Text

Strength = StrengthBox.Text

Hits = HitsBox.Text

Ranged = RangedBox.Text

Magic = MagicBox.Text

Prayer = PrayerBox.Text

 

'Calculates Combat Level

If (Ranged * 1.5) < (Attack + Strength) Then

Label16.Text = (Attack + Defense + Strength + Hits) / 4 + (Magic + Prayer) / 8

End If

'Calculates Combat Level

If (Ranged * 1.5) > (Attack + Strength) Then

Label16.Text = (Defense + Hits) / 4 + (Magic + Prayer) / 8 + Ranged * 0.375

End If

'Calculates how many lvls needed to advance

Label21.Text = Label16.Text / 4 / 8

Label22.Text = Label16.Text / 8 / 2

Label14 = CInt(Label16.Text)

End Sub

Posted

An obvious mistake I found!!, But not sure if you just left it out in the post.

 

You have:

Label14 = Math.Round(Label16.Text, 0)

 

Change to

Label14.Text = Math.Round(Label16.Text, 0)

Posted

i feel pretty stupid.. lol, considering i almost always try adding ".text" when stuff doesnt work right..

 

now i just have one more little question.. is it possible to make it round .5 and lower down instead of rounding the .5 up?

 

like if its 71.5 it would round it down to 70.

 

thanks for your help

Posted

Label14.Text = Math.Round(CDbl(Label16.Text) - 0.01)

 

May have to change the 0.01 depends on how many decimal places you end up with after your calcs.

Posted
Label14.Text = Math.Round(CDbl(Label16.Text) - 0.01)

 

May have to change the 0.01 depends on how many decimal places you end up with after your calcs.

 

Might need Cstr... im not sure...Label14.Text = Cstr(Math.Round(CDbl(Label16.Text) - 0.01))

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

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