newbie help

  • Thread starter Thread starter Meissa
  • Start date Start date
M

Meissa

Hi,

I am trying to hide a button on a windows form if the value of a label
is either 2 or 4

I am struggling here and would appreciate any help you could give me
please.

I have tried:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim MyValue As Integer
Randomize() ' Initialize random-number generator.
MyValue = CInt(Int((6 * Rnd()) + 1)) ' Generate random value
between 1 and 6.


Label2.Text = MyValue
If Label1.Text =(2,4) Then
Button1.Visible = True

Else : Button1.Visible = False
End If

End Sub


Could some kind soul show me the error of my ways please.

TIA
 
Label2.Text = MyValue
Select case MyValue
Case 2, 4
Button1.Visible = True
case else
Button1.Visible = False
end Select
 
Meissa said:
Hi,

I am trying to hide a button on a windows form if the value of a
label is either 2 or 4

I am struggling here and would appreciate any help you could give
me please.

I have tried:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Dim MyValue As Integer
Randomize() ' Initialize random-number generator.
MyValue = CInt(Int((6 * Rnd()) + 1)) ' Generate random
value
between 1 and 6.


Label2.Text = MyValue
If Label1.Text =(2,4) Then
Button1.Visible = True

Else : Button1.Visible = False
End If

End Sub


Could some kind soul show me the error of my ways please.

First, enable Option Strict in the project properties. Will help you find
errors earlier.

Code:
Dim MyValue As Integer
Randomize() ' Initialize random-number generator.
MyValue = CInt(Int((6 * Rnd()) + 1)) ' Generate random value

Label2.Text = MyValue.ToString
If MyValue = 2 OrElse MyValue = 4 Then
Button1.Visible = True
Else
Button1.Visible = False
End If

Or the short version:
Button1.Visible = MyValue = 2 OrElse MyValue = 4


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Another easy way:

On the textbox1.textchanged event:

if textbox1.text = "2" or textbox1.text = "4" then
button1.visible = false
else
button1.visible = true
endif
 
Thanks Guys

Armin Zingler said:
First, enable Option Strict in the project properties. Will help you find
errors earlier.

Code:
Dim MyValue As Integer
Randomize() ' Initialize random-number generator.
MyValue = CInt(Int((6 * Rnd()) + 1)) ' Generate random value

Label2.Text = MyValue.ToString
If MyValue = 2 OrElse MyValue = 4 Then
Button1.Visible = True
Else
Button1.Visible = False
End If

Or the short version:
Button1.Visible = MyValue = 2 OrElse MyValue = 4
 
Back
Top