newbie help

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
 
K

Kenneth

Label2.Text = MyValue
Select case MyValue
Case 2, 4
Button1.Visible = True
case else
Button1.Visible = False
end Select
 
A

Armin Zingler

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
 
B

Bill English

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
 
M

Meissa

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Random numbering 3
Bug in IDE? 9
Running text in the buttons 1
Absolute Beginner and Timer Class 4
Opening up in RichTextBox2 ? 26
Copying files with progress bar 6
OleDbSelect Help 3
Why not work? 3

Top