Block off buttons until specific button is pressed - vb.net

So, I'm still learning Visual Basic so I'm not entirely sure what I should be searching for however I've just been given a task to make a cash machine simulation, nothing that I can submit for coursework it's just for fun. However I'm trying to find out how to block out any buttons until a button prior to it is pressed. For example, I have a button that simulates entering your credit card and then a progress bar. However, I want the buttons 1 - 9 to be blocked until the progress bar has finished. My current code is:
Public Class Form1
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
txtNumber.Text = txtNumber.Text & "1"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
barProgress.Increment(5)
If barProgress.Value = 100 Then
MsgBox("Please insert your pin into our secure system.")
End If
End Sub
Private Sub btnInsertCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCard.Click
Timer1.Start()
If btnInsertCard.Text = "Insert Your Card" Then
btnInsertCard.Text = "Please wait.."
End If
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
txtNumber.Text = txtNumber.Text & "2"
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
txtNumber.Text = txtNumber.Text & "3"
End Sub
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
txtNumber.Text = txtNumber.Text & "4"
End Sub
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
txtNumber.Text = txtNumber.Text & "5"
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
txtNumber.Text = txtNumber.Text & "6"
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
txtNumber.Text = txtNumber.Text & "7"
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
txtNumber.Text = txtNumber.Text & "8"
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
txtNumber.Text = txtNumber.Text & "9"
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
txtNumber.Text = txtNumber.Text & "0"
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtNumber.Clear()
End Sub
End Class
Any help would be appreciated!

I think what you're wanting to use is the .Enabled property.
In the Form1_Load I'm setting the .Enabled property for all of the buttons to False.
Once the barProgress.Value = 100 I stop the timer and enable the first button.
Then in the click event for each button I set the .Enabled property for the next button to True.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim buttonArray = {btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0}
For Each button In buttonArray
button.Enabled = False
Next
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
txtNumber.Text = txtNumber.Text & "1"
btn2.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
barProgress.Increment(5)
If barProgress.Value = 100 Then
Timer1.Stop()
btn1.Enabled = True
MsgBox("Please insert your pin into our secure system.")
End If
End Sub
Private Sub btnInsertCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertCard.Click
Timer1.Start()
If btnInsertCard.Text = "Insert Your Card" Then
btnInsertCard.Text = "Please wait.."
End If
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
txtNumber.Text = txtNumber.Text & "2"
btn3.Enabled = True
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
txtNumber.Text = txtNumber.Text & "3"
btn4.Enabled = True
End Sub
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
txtNumber.Text = txtNumber.Text & "4"
btn5.Enabled = True
End Sub
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
txtNumber.Text = txtNumber.Text & "5"
btn6.Enabled = True
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
txtNumber.Text = txtNumber.Text & "6"
btn7.Enabled = True
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
txtNumber.Text = txtNumber.Text & "7"
btn8.Enabled = True
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
txtNumber.Text = txtNumber.Text & "8"
btn9.Enabled = True
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
txtNumber.Text = txtNumber.Text & "9"
btn0.Enabled = True
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
txtNumber.Text = txtNumber.Text & "0"
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'txtNumber.Clear()
txtNumber.Text = Nothing
End Sub
End Class
*Edit - Sorry I read your question wrong somehow. Corrected my answer.

Related

how to if combobox selection then directly checkbox unchecked in vb.net

How if ComboBox selection then directly CheckBox unchecked?
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
Me.TextBox1.Text = ""
Me.PopulateDataGridView()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
clearfiltercombobox()
PopulateDataGridView()
End Sub
Put Me.CheckBox1.Checked = False in your ComboBox handler
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted
Me.TextBox1.Text = ""
Me.CheckBox1.Checked = False
Me.PopulateDataGridView()
End Sub

Displaying decrementing value of a primary key

Private Sub TblCustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.TblCustomerBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CustomerDataDataSet)
End Sub
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomerDataDataSet.tblCustomer' table. You can move, or remove it, as needed.
Me.TblCustomerTableAdapter.Fill(Me.CustomerDataDataSet.tblCustomer)
End Sub
Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Try
TblCustomerBindingSource.EndEdit()
TblCustomerTableAdapter.Update(CustomerDataDataSet.tblCustomer)
MessageBox.Show("Registered successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Form5.Show()
Me.Hide()
Form5.TblReservationBindingSource.AddNew()
Form5.Label2.Text = Customer_IDTextBox.Text
Form5.Label3.Text = FirstNameTextBox.Text & " " & LastNameTextBox.Text
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
FirstNameTextBox.Text = ""
LastNameTextBox.Text = ""
Contact_NoTextBox.Text = ""
Email_AddressTextBox.Text = ""
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Form1.Show()
Me.Hide()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Date_Of_RegistrationTextBox.Text = Format(Now, "MM/dd/yyyy, hh:mm:ss tt")
End Sub
When I try to add a new record vb.net automatically display the primary key in a decrementing value but when I click register and check my ms access file it displays the correct value for my primary key.
Here's my program

Get highest value from scales and remove unnecessary words

I created a little program to get weight from scales via COM port. But then I turn on program. It's start to loop (creating long list) SV 0 KG in Label. And if weight increase it's also loop, for e.g. SV 0 KG, SV 50 KG, SV 48 KG, SV 0 KG and etc..
So my question is how to stop loop and always show one value?
And second question can I use Replace("SV", " ") or there is other better method?
Dim myPort As Array
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
cmbBaud.Items.Add(9600)
cmbBaud.Items.Add(19200)
cmbBaud.Items.Add(38400)
cmbBaud.Items.Add(57600)
cmbBaud.Items.Add(115200)
For i = 0 To UBound(myPort)
cmbPort.Items.Add(myPort(i))
Next
cmbPort.Text = cmbPort.Items.Item(0)
cmbBaud.Text = cmbBaud.Items.Item(0)
btnDisconnect.Enabled = False
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
SerialPort1.PortName = cmbPort.Text
SerialPort1.BaudRate = cmbBaud.Text
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.DataBits = 8
SerialPort1.Open()
btnConnect.Enabled = False
btnDisconnect.Enabled = True
End Sub
Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
SerialPort1.Close()
btnConnect.Enabled = True
btnDisconnect.Enabled = False
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
SerialPort1.Write(txtTransmit.Text & vbCr)
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If Me.rtbReceived.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.rtbReceived.Text &= [text]
End If
End Sub
Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged
If SerialPort1.IsOpen = False Then
SerialPort1.PortName = cmbPort.Text
Else
MsgBox("Valid only if port is Closed", vbCritical)
End If
End Sub
Private Sub cmbBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBaud.SelectedIndexChanged
If SerialPort1.IsOpen = False Then
SerialPort1.BaudRate = cmbBaud.Text
Else
MsgBox("Valid only if port is Closed", vbCritical)
End If
End Sub
Private Sub rtbReceived_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbReceived.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
rtbReceived.Text = " "
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SerialPort1.Write(txtTransmit.Text & vbCr)
End Sub

String cannot be converted to System.Uri

Codeļ¼š
Imports System
Imports System.IO
Imports System.Text
Public Class Browser
Dim Tab1Url As String = ""
Dim Tab2Url As String = ""
Dim TabNumber As Integer = 1
Dim DefaultHomePageSavedLocation As String = "C:\ToolBoxData\TinyBrowser\Home.txt"
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
Label2.Text = "[BROWSER] Loading in Progress......"
ProgressBar1.Value = 50
End Sub
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
WebBrowser1.GoBack()
Label2.Text = "[BROWSER] Going to Last History......"
ProgressBar1.Value = 0
End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
'Next
WebBrowser1.GoForward()
Label2.Text = "[BROWSER] Going to Next History......"
ProgressBar1.Value = 0
End Sub
Private Sub HomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeToolStripMenuItem.Click
'Home
Dim HomeLink As String = My.Computer.FileSystem.ReadAllText(DefaultHomePageSavedLocation)
WebBrowser1.Navigate(HomeLink)
Label2.Text = "[BROWSER] Going Home......"
ProgressBar1.Value = 0
End Sub
Private Sub ToolStripTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripTextBox1.Click
Label2.Text = "[USER] Inserting / Copying URL......"
End Sub
Private Sub GoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoToolStripMenuItem.Click
If TabNumber = 1 Then
Tab1Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab1Url)
Button1.Text = ToolStripTextBox1.Text
ElseIf TabNumber = 2 Then
Tab2Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab2Url)
Button2.Text = ToolStripTextBox1.Text
End If
ProgressBar1.Value = 0
End Sub
Private Sub ReloadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadToolStripMenuItem.Click
WebBrowser1.Refresh()
Label2.Text = "[BROWSER] Refreshing......"
ProgressBar1.Value = 0
End Sub
Private Sub TinyBrowserV10ByToolBoxWeeblyComToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TinyBrowserV10ByToolBoxWeeblyComToolStripMenuItem.Click
WebBrowser1.Navigate("http://tool-box.weebly.com/")
Label2.Text = "[BROWSER] Redirecting to Our Website......"
ProgressBar1.Value = 0
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Label2.Text = "[BROWSER] Loading Completed."
ToolStripTextBox1.Text = WebBrowser1.Url.ToString
ProgressBar1.Value = 100
End Sub
Private Sub ToolStripTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ToolStripTextBox1.KeyPress
If e.KeyChar = Chr(13) Then
If TabNumber = 1 Then
Tab1Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab1Url)
Button1.Text = ToolStripTextBox1.Text
ElseIf TabNumber = 2 Then
Tab2Url = ToolStripTextBox1.Text
WebBrowser1.Navigate(Tab2Url)
Button2.Text = ToolStripTextBox1.Text
End If
ProgressBar1.Value = 0
End If
End Sub
Private Sub Browser_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Back) Then
WebBrowser1.GoBack()
ProgressBar1.Value = 0
End If
End Sub
Private Sub OptionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionToolStripMenuItem.Click
Setting.Show()
End Sub
Private Sub Browser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.FileExists(DefaultHomePageSavedLocation) = False Then
My.Computer.FileSystem.CreateDirectory("C:\ToolBoxData\TinyBrowser\")
My.Computer.FileSystem.WriteAllText(DefaultHomePageSavedLocation, "http://hk.yahoo.com", True)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TabNumber = 1 Then
TabNumber = 1
ChangeTab()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not TabNumber = 2 Then
TabNumber = 2
ChangeTab()
End If
End Sub
Private Sub ChangeTab()
If TabNumber = 1 Then
WebBrowser1.Url = Tab1Url
ElseIf TabNumber = 2 Then
WebBrowser1.Url = Tab2Url
End If
End Sub
End Class
And the error is:
Value of type "String" cannot be converted to "System.Uri" (Line 121, 123)
What's the problem?
I've found the solution at another website.
Solution:
Line 121:
WebBrowser1.Url = New Uri(Tab1Url)
Line 123:
WebBrowser1.Url = New Uri(Tab2Url)
Thanks for all your help!

Multiple camera shots in vb

See I have this simple vb.net codes that counts from 5 to 1 then says capture! I need to do this 4 consecutive times after the start button is clicked .. I tried a do until loop but it didn't work, I'm a newbie here so please help..
Public Class Form_welcome
Dim Count As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Count -= 1
Label2.Text = Count
If (Count = 0) Then
Timer1.Enabled = False
Label2.Hide()
Label3.Show()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Count = 5
Timer1.Enabled = True
Label2.Text = Count
Timer1.Interval = 1000
End Sub
End Class
something like this?
Public Class Form_welcome
Dim Count As Integer
Dim pictureCount as integer = 4
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Count -= 1
Label2.Text = Count
If (Count = 0) Then
pictureCount -=1
If pictureCount = 0 then
Timer1.Enabled = False
End If
'take a picture
Label2.Hide()
Label3.Show()
Count = 5
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Count = 5
Timer1.Enabled = True
Label2.Text = Count
Timer1.Interval = 1000
End Sub
End Class
Public Class Form_welcome
Dim Count As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Admin_Login.Show()
Me.Hide()
End Sub
Private Sub Form_welcome_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Application.Exit()
End Sub
Private Sub Form_welcome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button4.Hide()
Button5.Hide()
Button6.Hide()
'Timer1.Enabled = True
'Label2.Text = Count
'Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Count -= 1
'Label2.Text = Count
If (Count = -1) Then
Timer1.Enabled = False
Label3.Show()
Label3.Hide()
Label2.Hide()
Button4.Show()
Button5.Show()
Button6.Show()
PictureBox4.Hide()
PictureBox3.Show()
pict1.Show()
pict2.Show()
pict3.Show()
pict4.Show()
Button2.Hide()
End If
If (Count Mod 3) = 0 Then
Label2.Text = "Captured!"
Else
Label2.Text = Count
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Count = 12
Timer1.Enabled = True
Label2.Text = Count
Label2.Show()
Timer1.Interval = 1000
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Application.Exit()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Button2.Show()
Button4.Hide()
Button5.Hide()
Button6.Hide()
PictureBox3.Hide()
pict1.Hide()
pict2.Hide()
pict3.Hide()
pict4.Hide()
PictureBox4.Show()
End Sub
End Class