I've been trying to simulate a cashpoint in visual basic and it's been going okay, I've got buttons from 1-9 and a clear key set up but I removed the code to shorten it for here. I was wondering if there was any alternative ways to make a section of code change when a MsgBox was closed with OK. The section I wish to change specifically is:
If Label1.Text = "Please wait.."
Then
Label1.Text = "Proceed to enter your pin."
End If
which is in the code below, I've tried to use: Threading.Thread.Sleep(5000) but all it does is cause the entire program to freeze until it's done and then carries on to do the whole script. What I really want it to do is change the text in Label1 to what I've already attempted. It might be horribly easy to do but I'm still new to this, so any help would be greatly appreciated!
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, btnClear}
For Each button In buttonArray
button.Enabled = False
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim buttonArray = {btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btnClear}
barProgress.Increment(5)
If barProgress.Value = 100 Then
For Each Button In buttonArray
Button.Enabled = True
Next
Timer1.Stop()
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()
Label1.Text = "Please wait.."
If btnInsertCard.Text = "Insert Your Card" Then
btnInsertCard.Text = "Please wait.."
End If
If Label1.Text = "Please wait.." Then
Label1.Text = "Proceed to enter your pin."
End If
End Sub
End Class
Related
On first click I'd like to see listbox and some buttons disabled.
On second click I'd like to see that listbox and buttons enabled again.
My current code is:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
lstbx_1.Enabled = False
lstbx_2.Enabled = False
outbtn.Enabled = False
Button2.Text = "remove approval"
End Sub
Try this code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
lstbx_1.Enabled = Not (lstbx_1.Enabled)
lstbx_2.Enabled = Not (lstbx_2.Enabled)
outbtn.Enabled = Not (outbtn.Enabled)
If lstbx_1.Enabled = False Then
Button2.Text = "remove approval"
Else
Button2.Text = "Your Text"
End If
End Sub
So I make a form like this
Form1
The picture box will show neutral.png when form is loaded, so
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = Image.FromFile("Images\neutral.png")
End Sub
I make the image on picturebox1 change to x.png while mouse over and disappear when mouse leave, so
Private Sub PictureBox1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
PictureBox1.Image = Image.FromFile("Images\x.png")
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
PictureBox1.Image = Image.FromFile("Images\neutral.png")
End Sub
My question is how I make the x.png image stay on the picturebox1 when I click the picturebox1. Doing this
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
PictureBox1.Image = Image.FromFile("Images\x.png")
End Sub
Doesn't seem work since the mouseleave event still have an effect.
There is example, from my comment
Public Class Form1
Private isClicked As Boolean = False
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = Image.FromFile("images\neutral.jpg")
End Sub
Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs) Handles PictureBox1.Click
If isClicked = False Then isClicked = True Else isClicked = False 'if You click again, everything back
'isClicked = True 'in this case, when You click "x.jpg" will stay always
PictureBox1.Image = Image.FromFile("images\x.jpg")
End Sub
Private Sub PictureBox1_MouseEnter(sender As Object, e As System.EventArgs) Handles PictureBox1.MouseEnter
If isClicked = False Then 'picturebox isn't clicked, so show x.jpg ... otherwise x.jpg will be showed always
PictureBox1.Image = Image.FromFile("images\x.jpg")
End If
End Sub
Private Sub PictureBox1_MouseLeave(sender As Object, e As System.EventArgs) Handles PictureBox1.MouseLeave
If isClicked = False Then 'picturebox isn't clicked, so show neutral image ... otherwise x.jpg will be showed always
PictureBox1.Image = Image.FromFile("images\neutral.jpg")
End If
End Sub
End Class
Use some variable, in this example is isClicked.
Always make checking under MouseEnter and MouseLeave is picturebox clicked or not.
By this example, You can click again on picturebox to, let's say, reset that isClicked, so You can have again neutral and x images.
I want to know the code to the following illustration.
i have one form with some checkboxs and one button,
screen is here
i've try with this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True And CheckBox2.Checked = True And CheckBox3.Checked = True And CheckBox4.Checked = True Then
'when the button is clicked will be the process for moving images
'Like
System.IO.File.Copy(Application.StartupPath + "\File\Pic1.jpg", "D:\File\Pic1.jpg")
End If
End Sub
I was tired with that code, is there a shorter coding ?
for example, if the checkbox1.checked = true and another checkbox not checked then only moving one pict
If I understand the question, you want to copy pictures 1 to 4 if the checkboxes 1 to 4 are checked.
Try this:
Dim SourcePath As string = Application.StartupPath + "\File\"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CopyFile(CheckBox1, "Pic1.jpg")
CopyFile(CheckBox2, "Pic2.jpg")
CopyFile(CheckBox3, "Pic3.jpg")
CopyFile(CheckBox4, "Pic4.jpg")
End Sub
Private Sub CopyFile(CB As CheckBox, FileName As String)
If CB.Checked Then
System.IO.File.Copy(SourcePath + FileName, "D:\File\" + FileName)
End If
End Sub
Hi guys I have another problem which is all about the timer..the form that I would want to show for 3 seconds is only showing for about half a second. Please help me thanks in advance
Main form code:
Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
'question 1
If Label1.Text = "Who invented the airplane?" And TextBox1.Text = "third" Then
Label2.Text = (Label2.Text) + 1
correctmsg.Show()
correctmsg.Hide()
Label1.Text = "Who invented the telephone?"
Return 'Don't do any more checks this time around
ElseIf Label1.Text = "Who invented the airplane?" Then
'Reason ElseIf (In case the question was 'who invented the telephone' then the first errormessage should not not be shown)
wrongmsg.Show()
Return
End If
Splash form code:
Public Class correctmsg
Private Sub correctmsg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim mysplash As New correctmsg
mysplash.Timer1.Interval = 3000
End Sub
End Class
Something like this:
Public Class correctmsg
' correctmsg == mysplash ??? so this is a form??
Private Sub correctmsg_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 3000 ' could be a timer here
End Sub
Public Sub ShowMsg
Timer1.Enabled = true
me.Visible = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Me.Visible = False
End Sub
End Class
I am just showing the form by making it visible. No need to make a new form. When the timer expires, hide the form and disable the timer. To use it:
correctmsg.ShowMsg
' this was hiding the form as soon as it shows:
'correctmsg.Hide()
So I have a code atm that has 2 combo boxes, one to select the make, then it will enable the model, I have 3 model choices, here's code:
Public Class Form2
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub cmb_make_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmb_make.Items.Add("Toyota")
cmb_make.Items.Add("Nissan")
cmb_make.Items.Add("Hyundai")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_finish.Click
If cmb_make.Text = "" Then
MsgBox("Please select your make")
End If
If cmb_model.Text = "" Then
MsgBox("Please select your model")
End If
If cmb_model.Text = ("Supra") Then
Form3.Show()
Me.Close()
End If
If cmb_model.Text = ("MR2") Then
Form4.Show()
Me.Close()
End If
If cmb_model.Text = ("Hilux") Then
Form5.Show()
Me.Close()
End If
If cmb_model.Text = ("R34") Then
Form6.Show()
Me.Close()
End If
If cmb_model.Text = ("R33") Then
Form7.Show()
Me.Close()
End If
If cmb_model.Text = ("R32") Then
Form8.Show()
Me.Close()
End If
If cmb_model.Text = ("Genesis Coupe") Then
Form9.Show()
Me.Close()
End If
If cmb_model.Text = ("RD1 Coupe") Then
Form10.Show()
Me.Close()
End If
If cmb_model.Text = ("Excel") Then
Form11.Show()
Me.Close()
End If
End Sub
Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.Click
End Sub
Private Sub cmb_make_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_make.SelectedIndexChanged
Dim Strchoice As String
Strchoice = cmb_make.SelectedItem
If Strchoice = "Toyota" Then
End If
cmb_model.Items.Clear()
cmb_model.Items.Add("Supra")
cmb_model.Items.Add("MR2")
cmb_model.Items.Add("Hilux")
If Strchoice = "Nissan" Then
cmb_model.Items.Clear()
cmb_model.Items.Add("R34")
cmb_model.Items.Add("R32")
cmb_model.Items.Add("R33")
ElseIf Strchoice = "Hyundai" Then
cmb_model.Items.Clear()
cmb_model.Items.Add("RD1 Coupe")
cmb_model.Items.Add("Genesis Coupe")
cmb_model.Items.Add("Excel")
Once I have selected my model of the car, it takes me to that specific form with a picture of that model, I then want to display individual parts, with individual prices that will add up in a text box above, can someone help me and tell me how? Please this is due tomorrow I'm freaking out!!
You can put the parts into picture boxes on the model's form and have either check boxes or radio buttons (depending on what functionality you are required to do) underneath that have the prices as labels and then use an if structure to assign a value to them that can be totaled in the text box.
Dim total as double
If chk_part1.checked = true then
total += partPrice
If chk_part2.checked = true then
total += partPrice
txtTotal.text = total
Not saying that this code is perfect but you could implement something along those lines to get the results you're looking for.
You can also do a For Each Statement. Such as:
Dim Form As New Form3.ControlCollection(Me)
For Each CheckBox As CheckBox In Form
If CheckBox.Checked = True Then
total += partPrice
End If
Next
So, In essense, it should cycle through all of the check boxes and, if they are checked, it adds the part price to the total.