Multiple conditions on Timer - vb.net

Can someone guide me or correct my code. I have multiple conditions in my Timer.
Each Button runs on 1 Timer but each Button clicked has different code or conditions on the timer. The problem is, only one condition will work.
If I click the first Button, the condition for the first Button will run but when I click the second Button, the first condition will still run.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
''progressbar(KryptonBorderEdge2) timer
KryptonBorderEdge2.Width = KryptonBorderEdge2.Width + 1
Dim curWidth = KryptonBorderEdge2.Width
Dim percentage = (Double.Parse(curWidth) / Double.Parse(404) * 100.0).ToString("#0.00") ''to get percentage
KryptonLabel5.Text = percentage.ToString + " %" ''404 is the max width or the 100%
If KryptonBorderEdge2.Width = 404 Then
Timer1.Enabled = False
End If
''CONNECT button is clicked
If hardwareConnect = True Then
If KryptonLabel5.Text = "50.00 %" Then
Timer1.Interval = 10
Label2.Text = "Hardware Found. Now attempting to connect."
ElseIf KryptonLabel5.Text.Contains("100") Then
KryptonComboBox1.Text = "OMNIKEY"
Label2.Text = "Hardware successfully connected!"
hardwareConnect = False
Timer1.Enabled = False
End If
End If
''CHECK PORT button is clicked
If checkingPort = True Then
If KryptonLabel5.Text.Contains("100") Then
MsgBox("Card format: JCOP S3CC9P9" + vbNewLine + "Connected on COM4", vbOKOnly)
KryptonComboBox2.Text = "JCOP S3CC9P9"
Label2.Text = "..."
checkingPort = False
Timer1.Enabled = False
End If
End If
''REMOVE SAVED DATA is clicked
If KryptonLabel5.Text = "89.00 %" Then
Label2.Text = "Finishing things up."
If KryptonLabel5.Text.Contains("100") Then
removeAll()
MsgBox("Data Successfully Removed!", MsgBoxStyle.OkOnly)
Label2.Text = "..."
Timer1.Enabled = False
End If
End If
''START/WRITE DATA button is clicked
If writeData = True Then
If KryptonLabel5.Text = "20.00 %" Then
Label2.Text = "Blank Card detected."
ElseIf KryptonLabel5.Text = "30.00 %" Then
Label2.Text = "Writing account name..."
ElseIf KryptonLabel5.Text = "40.00 %" Then
Label2.Text = "Inserting ARQC Key and Master Key..."
ElseIf KryptonLabel5.Text = "50.00 %" Then
Label2.Text = "Confirming Expiry Date..."
ElseIf KryptonLabel5.Text = "60.00 %" Then
Label2.Text = "Generating PIN..."
ElseIf KryptonLabel5.Text = "70.00 %" Then
Label2.Text = "Writing PIN and CVV..."
ElseIf KryptonLabel5.Text = "80.00 %" Then
Label2.Text = "Confirming Track1/Track2/Track3..."
ElseIf KryptonLabel5.Text = "90.00 %" Then
Label2.Text = "Finalizing everything. Please wait for a while..."
Timer1.Interval = 1000
ElseIf KryptonLabel5.Text.Contains("100") Then
Label2.Text = "Successfully writing data to the card!"
Timer1.Enabled = False
writeData = False
End If
End If
End Sub

If you want only one condition to be true at a given time, don't use Booleans. Instead, create an enum with possible operations and a variable to store the current operation
Enum Operation
None
HardwareConnect
CheckingPort
WriteData
End Enum
Dim currentOperation As Operation
Now, when a button is clicked set the current operation. Like this only one type of operation can be active.
Private Sub ConnectButton_Click(sender As Object, e As EventArgs) Handles ConnectButton.Click
currentOperation = Operation.HardwareConnect
End Sub
Your sub then looks like this:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'progressbar(KryptonBorderEdge2) timer
KryptonBorderEdge2.Width = KryptonBorderEdge2.Width + 1
Dim curWidth = KryptonBorderEdge2.Width
Dim percentage = (Double.Parse(curWidth) / Double.Parse(404) * 100.0).ToString("#0.00") ''to get percentage
KryptonLabel5.Text = percentage.ToString + " %" ''404 is the max width or the 100%
If KryptonBorderEdge2.Width = 404 Then
Timer1.Enabled = False
End If
If currentOperation = Operation.HardwareConnect Then 'CONNECT button is clicked
...
ElseIf currentOperation = Operation.CheckingPort Then 'CHECK PORT button is clicked
...
End If
' REMOVE SAVED DATA is clicked
If KryptonLabel5.Text = "89.00 %" Then
...
End If
If currentOperation = Operation.WriteData Then
' START/WRITE DATA button is clicked
...
End If
End Sub
Instead of setting the Booleans to False you can set currentOperation = Operation.None
Sub StopOperations()
Timer1.Enabled = False
currentOperation = Operation.None
End Sub

Related

Async FileDownloader that compare files with hash codes from a list

I want to make a launcher for my game. The launcher should make a check for the files when I click on the "Play" button.
I want to check the hash codes (for example the patch files) that are already installed and the patch files on my server. The files that I want to check should be in a .txt file list.
When the code is not a match with the files on the server, I want to overwrite the local files.
After downloading the file the next one should start until all files are downloaded. I want to show progress with a ProgressBar.
I tested that with only one file that is hard coded. With more files I didn't find a solution.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim URL As String = "http://213.196.154.200/downloads/WOTLK/WOTLK/Data/patch-3.MPQ"
Application.DoEvents()
hhtpclient.DownloadFileAsync(New Uri(URL), Pfad + "/data/patch-3.mpq", Stopwatch.StartNew)
Application.DoEvents()
Label2.Visible = True
Label3.Visible = True
ProgressBar1.Visible = True
Button2.Visible = True
Button1.Enabled = False
Label5.Visible = False
Catch ex As Exception
MsgBox("Download fehlgeschlagen!" & vbNewLine & ex.ToString, MsgBoxStyle.Critical, "Error")
End
End Try
End Sub
Private Sub hhtpclient_DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles hhtpclient.DownloadFileCompleted
If Abbort = "0" Then
Dim customMsgbox1 = New Form2("Download erfolgreich!")
customMsgbox1.btnCustomNo.Visible = False
customMsgbox1.btnCustomYes.Location = New Point(179, 229)
customMsgbox1.ShowDialog()
Label2.Visible = False
Label3.Visible = False
ProgressBar1.Visible = False
Abbort = "0"
PictureBox8.Visible = False
Else
Dim customMsgbox2 = New Form2("Download abgebrochen!")
customMsgbox2.btnCustomNo.Visible = False
customMsgbox2.btnCustomYes.Location = New Point(179, 229)
customMsgbox2.ShowDialog()
Label2.Visible = False
Label3.Visible = False
ProgressBar1.Visible = False
Abbort = "0"
End If
Button2.Visible = False
Button1.Enabled = True
Label5.Visible = True
End Sub
Private Sub hhtpclient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles hhtpclient.DownloadProgressChanged
Dim SW As Stopwatch
SW = Stopwatch.StartNew
Me.ProgressBar1.Value = e.ProgressPercentage
Dim totalbytes As Double = e.TotalBytesToReceive
Dim bytes As Double = e.BytesReceived
If totalbytes >= "1000000000" Then
Label2.Text = Math.Round(bytes / 1024000000.0, 2) & " / " & Math.Round(totalbytes / 1024000000.0, 2) & " GB"
ElseIf totalbytes >= "1000000" Then
Label2.Text = Math.Round(bytes / 1024000.0, 2) & " / " & Math.Round(totalbytes / 1024000.0, 2) & " MB"
End If
If bytes >= "1000000" Then
Label3.Text = (e.BytesReceived / 1024000.0 / (DirectCast(e.UserState, Stopwatch).ElapsedMilliseconds / 1000.0#)).ToString("0.0") & " MB/s"
ElseIf bytes >= "1000" Then
Label3.Text = (e.BytesReceived / 1024.0 / (DirectCast(e.UserState, Stopwatch).ElapsedMilliseconds / 1000.0#)).ToString("0.0") & " KB/s"
End If
End Sub
I tried this code. The Files will download but I don't how to add a ProgressBar and the application freeze when the files downloading:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'===Downloadvorgang===
Dim Einl() As String = Split(My.Computer.FileSystem.ReadAllText("D:/Test.txt"), vbNewLine)
For i As Long = 0 To UBound(Einl)
Dim l() As String = Split(Einl(i), ";")
Dim url As String = l(0)
Dim dateiname As String = l(1)
My.Computer.Network.DownloadFile(url, "D:/" & dateiname, "", "", False, 100000, True)
Next
MsgBox("Die Dateien wurden erfolgreich heruntergeladen!", MsgBoxStyle.OkOnly, "Download beendet")
'===Downloadvorgang Ende====
End Sub

Counter using KeyPress events

First time posting here, although I'm a frequent visitor when I'm looking for answers. I am new to VB and programming.
My problem is this. I had this figured out in VBA, but I want to convert my "program" to a standalone executable with VB (using Visual Studio 2015)
I want to keep track of certain keypresses done on a textbox, and so far I figured out something that works, but it seems messy.
Can anyone think of a better way of doing
Public Class Form1
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case UCase(e.KeyChar) 'For capturing keypresses and adding them
Case "W" : Label3.Text = Val(Label3.Text) + 1
Case "R" : Label4.Text = Val(Label4.Text) + 1
End Select
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = "" 'Clears the text box after each keypress
End Sub
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim WcountA As Integer
Dim RcountA As Integer
Dim WcountB As Integer
Dim RcountB As Integer
Dim Wavg As Single
Dim Ravg As Single
Select Case Button1.Text
Case "Finish A" 'Finishes first count and stores results in labels
WcountA = Convert.ToInt32(Label3.Text)
RcountA = Convert.ToInt32(Label4.Text)
Button1.Text = "Finish B"
Label5.Text = WcountA
Label7.Text = RcountA
TextBox1.Focus()
Label3.Text = ""
Label4.Text = ""
Case "Finish B" 'Finishes second count and stores in labels
WcountB = Convert.ToInt32(Label3.Text)
RcountB = Convert.ToInt32(Label4.Text)
With Button1
.Text = "Finished"
.Enabled = False
End With
Label6.Text = WcountB
Label8.Text = RcountB
Label3.Text = ""
Label4.Text = ""
WcountA = Label5.Text
RcountA = Label7.Text
WcountB = Label6.Text
RcountB = Label8.Text
Wavg = (WcountA + WcountB) / 2
Ravg = (RcountA + RcountB) / 2
MsgBox("W average = " & Wavg & vbNewLine & "R average = " & Ravg)
End Select
End Sub
End Class
On the form I have the textbox that logs the keypress event, labels that increase by 1 with each specific keypess ("W" and "R"), a button that changes its function with each click(finish first count, finish second count) and some labels I had to use to store the first and second count for the final calculation.
Any suggestion will be appreciated.
Thanks in advance!
First of al, you need to take out the counters of the key pres handler like so;
Because they are gone every time the Button1_Click sub ends.
Public Class Form1
Dim WcountA As Integer
Dim RcountA As Integer
Dim WcountB As Integer
Dim RcountB As Integer
Dim Wavg As Single
Dim Ravg As Single
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case UCase(e.KeyChar) 'For capturing keypresses and adding them
Case "W" : Label3.Text = Val(Label3.Text) + 1
Case "R" : Label4.Text = Val(Label4.Text) + 1
End Select
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = "" 'Clears the text box after each keypress
End Sub
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Select Case Button1.Text
Case "Finish A" 'Finishes first count and stores results in labels
WcountA = Convert.ToInt32(Label3.Text)
RcountA = Convert.ToInt32(Label4.Text)
Button1.Text = "Finish B"
Label5.Text = WcountA
Label7.Text = RcountA
TextBox1.Focus()
Label3.Text = ""
Label4.Text = ""
Case "Finish B" 'Finishes second count and stores in labels
WcountB = Convert.ToInt32(Label3.Text)
RcountB = Convert.ToInt32(Label4.Text)
With Button1
.Text = "Finished"
.Enabled = False
End With
Label6.Text = WcountB
Label8.Text = RcountB
Label3.Text = ""
Label4.Text = ""
WcountA = Label5.Text
RcountA = Label7.Text
WcountB = Label6.Text
RcountB = Label8.Text
Wavg = (WcountA + WcountB) / 2
Ravg = (RcountA + RcountB) / 2
MsgBox("W average = " & Wavg & vbNewLine & "R average = " & Ravg)
End Select
End Sub
End Class
This is what I ended up doing, works better and looks cleaner. Thanks Lectere for pointing me to the right path!
Public Class Form1
Dim WcountA As Integer
Dim RcountA As Integer
Dim WcountB As Integer
Dim RcountB As Integer
Dim Wavg As Single
Dim Ravg As Single
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case UCase(e.KeyChar) 'For capturing keypresses and adding them
Case "W" : lblWcount.Text = Val(lblWcount.Text) + 1
Case "R" : lblRcount.Text = Val(lblRcount.Text) + 1
Case Convert.ToChar(13) : Button1_Click(sender, e)
End Select
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = "" 'Clears the text box after each keypress
End Sub
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Select Case Button1.Text
Case "Finish A" 'Finishes first count and stores results in variables
If lblWcount.Text = vbNullString Then 'checks for empty values and treats them as 0
WcountA = 0
Else
WcountA = lblWcount.Text
End If
If lblRcount.Text = vbNullString Then 'checks for empty values and treats them as 0
RcountA = 0
Else
RcountA = lblRcount.Text
End If
Button1.Text = "Finish B"
lbl_1.Text = WcountA
lbl_2.Text = RcountA
TextBox1.Focus()
lblWcount.Text = vbNullString
lblRcount.Text = vbNullString
lblcount.Text = "Count B"
Case "Finish B" 'Finishes second count and stores results in variables
lblcount.Text = vbNullString
If lblWcount.Text = vbNullString Then
WcountB = 0
Else
WcountB = lblWcount.Text
End If
If lblRcount.Text = vbNullString Then
RcountB = 0
Else
RcountB = lblRcount.Text
End If
With Button1
.Text = "Reset"
End With
lbl_3.Text = WcountB
lbl_4.Text = RcountB
lblWcount.Text = vbNullString
lblRcount.Text = vbNullString
Wavg = (WcountA + WcountB) / 2
Ravg = (RcountA + RcountB) / 2
MsgBox("W average = " & Wavg & vbNewLine & "R average = " & Ravg)
Button1.Focus()
Case "Reset" 'Resets values
Dim i As Integer
For i = 1 To 4 'clears labels that start with lbl_ (1 through 4)
Dim myLabel As Label = CType(Controls("lbl_" & i), Label)
myLabel.Text = vbNullString
Next
Initial() ' calls initial form state
End Select
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Initial() 'calls initial form state at load up
End Sub
Private Sub Initial() 'initial state sub
lblcount.Text = "Count A"
TextBox1.Focus()
Button1.Text = "Finish A"
End Sub
End Class
I managed to use loops for clearing labels, and also made pressing Enter during the KeyPress event be treated as a button click.
Loving this feeling of accomplishment when I finally figure something out on something new to me! Love pages like this one where one can learn so much!

Web Browser auto login error (Object reference not set to an instance of an object.)

I have 2 buttons on my form and here is the two bits of code.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If LoggedInToAdastra = True Then
LogOutOfAdastra()
Exit Sub
End If
strUsername = txtUsername.Text
strPassword = txtPassword.Text
LoggedInToAdastra = False
ProgressBar1.Value = 10
Try
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("https://nww.awv.nems.nhs.uk/AWA/login.aspx?ReturnUrl=%2fAWA%2fdefault.aspx")
WaitForPageLoad()
WebBrowser1.Document.All("ctl00$MainContent$txtUserName").SetAttribute("value", strUsername)
WebBrowser1.Document.All("ctl00$MainContent$txtPassWord").SetAttribute("value", strPassword)
WebBrowser1.Document.All("ctl00$MainContent$btnLogin").InvokeMember("click")
ProgressBar1.Value = 40
WaitForPageLoad()
ProgressBar1.Value = 80
WebBrowser1.Document.All("ctl00$MainContent$ctl01").InvokeMember("click")
WaitForPageLoad()
ProgressBar1.Value = 100
LoggedInToAdastra = True
txtPassword.Enabled = False
txtUsername.Enabled = False
Button2.Enabled = False
Button1.Text = "Log Out"
Button2.BackColor = Color.MintCream
Button1.BackColor = Color.MintCream
txtPassword.BackColor = Color.MintCream
txtUsername.BackColor = Color.MintCream
ProgressBar1.Value = 0
btnUpdate.Enabled = True
btnDoAll.Enabled = True
btnSearchSelected.Enabled = True
doc = Nothing
Catch ex As Exception
MsgBox("Login Failed")
Button2.BackColor = Color.MistyRose
Button1.BackColor = Color.MistyRose
txtPassword.BackColor = Color.MistyRose
txtUsername.BackColor = Color.MistyRose
txtUsername.Text = ""
txtPassword.Text = ""
ProgressBar1.Value = 0
End Try
End Sub
And the second button, once logged in, you should be able to search for a patient using this button and choosing a patient from a listbox...
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
If LoggedInToAdastra = False Then
MsgBox("Please re-login to Adastra")
End If
strPatientNHS = lstPatients.SelectedItems(0).SubItems(0).Text
EditNote(strPatientNHS)
End Sub
Public Sub EditNote(strPatientNHS As String)
'Try
doc = WebBrowser1.Document
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Document.OpenNew(True)
WebBrowser1.Navigate("https://nww.awv.nems.nhs.uk/AWA/login.aspx?ReturnUrl=%2fAWA%2fdefault.aspx")
ProgressBar1.Value = 10
WaitForPageLoad()
ProgressBar1.Value = 20
WebBrowser1.Document.All("ctl00$MainContent$txtUserName").SetAttribute("value", strUsername)
WebBrowser1.Document.All("ctl00$MainContent$txtPassWord").SetAttribute("value", strPassword)
WebBrowser1.Document.All("ctl00$MainContent$btnLogin").InvokeMember("click")
'WebBrowser1.Navigate("https://nww.awv.nems.nhs.uk/AWA/MainMenu.aspx")
WaitForPageLoad()
ProgressBar1.Value = 30
WebBrowser1.Document.All("ctl00$MainContent$ctl01").InvokeMember("click")
WaitForPageLoad()
ProgressBar1.Value = 40
WebBrowser1.Document.GetElementById("ct100_MainContent_txtNationalNumber").SetAttribute("value", strPatientNHS)
WebBrowser1.Document.GetElementById("ct100_MainContent_cboSurgery2").SetAttribute("value", "All Practices")
WebBrowser1.Document.All("ct100$MainContent$bSearch").InvokeMember("click")
End Sub
It errors here on the EditNote sub
WebBrowser1.Document.GetElementById("ct100_MainContent_txtNationalNumber").SetAttribute("value", strPatientNHS)
WebBrowser1.Document.GetElementById("ct100_MainContent_cboSurgery2").SetAttribute("value", "All Practices")
WebBrowser1.Document.All("ct100$MainContent$bSearch").InvokeMember("click")
I have tried all sorts, but not sure why its bringing through the Error (Object reference not set to an instance of an object.)
The control does exist on the web page, and that is the correct ID for it. I have tried using Document.All and looking for the element too but to no avail.
I did resolve this in the end, in quite bizarre fashion...
so it was giving me an error basically because it couldn't find the control
WebBrowser1.Document.All("ctl00$MainContent$txtUserName")
so as a last resort, I copied and pasted the exact control from the page source and it worked... even though every character was the same...
This fixed my problem anyway. Don't type the control out, copy and paste it! Maybe someone with more knowledge can explain how this works? is there hidden characters in the HTML?

Visual Basic Radio Buttons with Submit Button

I want the user to click on a radio button and then click the submit button. Once the submit button is pressed it changes a textbox value. However Visual Studio is telling me that I need to use a 'Raised Event'. I don't know how to use that or is it even needed? Here is the code:
Private Sub create_Click(sender As Object, e As RoutedEventArgs)
If RadioButton1.Checked = True Then
Me.creflag.Text += "1"
ElseIf RadioButton2.Checked = True Then
Me.creflag.Text += "4224"
ElseIf RadioButton3.Checked = True Then
Me.creflag.Text += "2"
ElseIf RadioButton4.Checked = True Then
Me.immune.Text += "619659263"
Me.typeflag.Text += "4"
End If
End Sub
In your XAML markup you have
.... Click="Button_Click"
this means that you need to have a RouterEventHandler named Button_Click not create_Click
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
If RadioButton1.Checked = True Then
Me.creflag.Text += "1"
ElseIf RadioButton2.Checked = True Then
Me.creflag.Text += "4224"
ElseIf RadioButton3.Checked = True Then
Me.creflag.Text += "2"
ElseIf RadioButton4.Checked = True Then
Me.immune.Text += "619659263"
Me.typeflag.Text += "4"
End If
End Sub
See MSDN docs and examples
Ok so I found out that I was mixing windows forms and WPF together. In windows forms it's .Checked but in WPF that is an event thus why it was giving me errors. The correct way in WPF is .IsChecked
Final Code:
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs) Handles Button.Click
If RadioButton1.IsChecked = True Then
Me.creflag.Text += "1"
ElseIf RadioButton2.IsChecked = True Then
Me.creflag.Text += "4224"
ElseIf RadioButton3.IsChecked = True Then
Me.creflag.Text += "2"
ElseIf RadioButton4.IsChecked = True Then
Me.immune.Text += "619659263"
Me.typeflag.Text += "4"
End If
End Sub

looking for a way to re enable labels without specifying which ones vb.net

I am looking for a way, if its even possible, to re enable a label without actually needing to use its label name?
I have a game with labels I am using as click able boxes. The first box becomes disabled after the click event occurs, I want after the second box is clicked to re enable that first box. Any Ideas? Here is the code for the first two box click events.
Edit: there will be 15 labels, 2 can be chosen at a time. The first will be disabled so that it can't be chosen a second time.
Private Sub lblMemory1_Click(sender As Object, e As EventArgs) Handles lblMemory1.Click
Dim intClickBox As Integer = 1
Dim intClickAnswer As Integer
intClickAnswer = GuessClick(intClickBox)
If blnActive = False Then
blnActive = True
whatClicked1 = intClickBox
lblMemory1.BackColor = Color.Green
lblMemory1.Text = intClickAnswer.ToString
lblMemory1.Refresh()
System.Threading.Thread.Sleep(2000)
lblMemory1.BackColor = Color.Cyan
lblMemory1.Text = "X"
lblMemory1.Enabled = False
End If
If blnActive = True Then
whatClicked2 = intClickBox
lblMemory1.BackColor = Color.Green
lblMemory1.Text = intClickAnswer.ToString
lblMemory1.Refresh()
System.Threading.Thread.Sleep(2000)
lblMemory1.BackColor = Color.Cyan
lblMemory1.Text = "X"
blnActive = False
End If
End Sub
Private Sub lblMemory2_Click(sender As Object, e As EventArgs) Handles lblMemory2.Click
Dim intClickBox As Integer = 2
Dim intClickAnswer As Integer
intClickAnswer = GuessClick(intClickBox)
If blnActive = False Then
blnActive = True
whatClicked1 = intClickBox
lblMemory2.BackColor = Color.Green
lblMemory2.Text = intClickAnswer.ToString
lblMemory2.Refresh()
System.Threading.Thread.Sleep(2000)
lblMemory2.BackColor = Color.Cyan
lblMemory2.Text = "X"
lblMemory2.Enabled = False
End If
If blnActive = True Then
whatClicked2 = intClickBox
lblMemory2.BackColor = Color.Green
lblMemory2.Text = intClickAnswer.ToString
lblMemory2.Refresh()
System.Threading.Thread.Sleep(2000)
lblMemory2.BackColor = Color.Cyan
lblMemory2.Text = "X"
blnActive = False
End If
End Sub
you can do something like
Public Sub game(sender As Object)
Dim lbl As Label = sender
If lbl.Enabled Then
For i = 0 To Me.Controls.Count - 1
Dim lbl2 As Label = Me.Controls(i)
If Not (lbl2.Enabled) Then
lbl2.Enabled = True
GoTo exitLoop
End If
Next
End If
exitLoop:
lbl.Enabled = False
End Sub
then in each label just call the game sub and pass sender like so...
Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles Label1.Click
game(sender)
End Sub
this will allow only 1 label to be diabled at any give time...
you can also (within the loops) use lbl and lbl2 to set the properties for each label.
if you use a var to save the name of the first textbox you can also specifically re-enable only that box...
let me know if you want the code for that too.