Question:
Visual Basic Check Boxes part 2.?
anonymous
2008-02-12 21:05:30 UTC
For Visual Basic. I need to be able to check the box, and have the values correspond in the labels. Then when I click the box again, I need to have the values dissapear. How do I do this?

Ive tried the chkAdd.checked = false

and thats just makes the check not appear in the check box when i click it


My Code for one of the sections is..

Private Sub chkAdd_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles chkAdd.Click
'declare local variables
Dim dblFirstNum As Double 'FirstNumber to add
Dim dblSecondNum As Double 'SecondNumber to add
Dim dblAnswer As Double 'Sum of FirstandSecond

'import data from interface
dblFirstNum = CDbl(txtFirstNum.Text)
dblSecondNum = CDbl(txtSecondNum.Text)

'calculations
dblAnswer = dblFirstNum + dblSecondNum

'display results
lblAddAns.Text = dblAnswer


I need to know how to make the value in the label for lets say add answer go away when I click the check again
Three answers:
?
2008-02-13 02:29:59 UTC
All a label does is display what you put in its text property.



So MyLabel.text = "Hello" places the string "Hello" into the lable's text property and it is displayed in teh label.



To erase the label's display you assign a new value to the label text property which doesn't contain any characters.



MyLabel.Text = "" Note the string enclosed by the double quotes "" doesn't have any characters in it.





To make this work in your problem you use an IF statment that looks at the state of a check box. If the checkbox is true you place characters in the text property like "Hello". If the checkbox is false you erase the label by loading "" into the labels text property
anonymous
2008-02-12 21:20:17 UTC
you add this code to that function

If (chkAdd.Checked = False) Then

lblAddAns.Visible = False

End If

when you click the check box again then the label will hide
liza
2016-05-27 06:20:24 UTC
Your formula is wrong. It's discounted_price = price - (discount [as a decimal] * price) So If RadioButton2.Checked Then Lbl6.Text = FormatCurrency(Lbl6.Text - (Lbl6.Text / (10/100)) * seats)) ElseIf RadioButton3.Checked Then Lbl6.Text = FormatCurrency(Lbl6.Text - (Lbl6.Text / (25/100)) * seats)) or If RadioButton2.Checked Then Lbl6.Text = FormatCurrency(Lbl6.Text - (Lbl6.Text * seats) / (10/100)) ElseIf RadioButton3.Checked Then Lbl6.Text = FormatCurrency(Lbl6.Text - (Lbl6.Text * seats) / (25/100))


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...