My progress bar goes over its specified amount - vb.net

I created a simple program called poodle doodle where you just click buttons to add to a progress bar but they could easily crash the program by just going 1 over the max amount but i cant figure out how to stop it from doing that. How can I?
Here's my current code
Public Class Form1
Private Sub poodle_Click(sender As Object, e As EventArgs) Handles poodle.Click
doodle.Visible = True
poodle.Visible = False
pdb1.Value = pdb1.Value + 1
End Sub
Private Sub doodle_Click(sender As Object, e As EventArgs) Handles doodle.Click
poodle.Visible = True
doodle.Visible = False
End Sub
Private Sub pdb1_Click(sender As Object, e As EventArgs) Handles pdb1.Click
If pdb1.Value = 100 Then
MessageBox.Show("You Poddled And Doodled To Victory!", "Poodle Doodle Champion")
pdb1.Value = pdb1.Value = 0
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
pdb1.Maximum = TextBox1.Text
End Sub

Change the poodle_Click method to check that the value is less than 100 like this:
Private Sub poodle_Click(sender As Object, e As EventArgs) Handles poodle.Click
doodle.Visible = True
poodle.Visible = False
' This bit
If pdb1.Value < 100 Then
pdb1.Value += 1
End If
End Sub
You'll probably want to add other logic to disable the poodle/doodle buttons when the player wins and a way to restart the game.
I'm not sure why you put pdb1.Value = pdb1.Value = 0 in the pdb1_Click method, it should just be pdb1.Value = 0.

Related

Timer.tick within 1 min back-forth

I have 2 Form and i want it to be slide show back & forth within 1 minute.
Please write down the code thank you!
My Code:
Form 1
Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles BunifuCheckbox1.OnChange
If BunifuCheckbox1.Checked Then
tmrSLIDE.Enabled = True
tmrSLIDE.Start()
Else
tmrSLIDE.Stop()
End If
End Sub
Private Sub tmrSLIDE_Tick(sender As Object, e As EventArgs) Handles tmrSLIDE.Tick
trs1.ShowSync(Form2)
Me.Hide()
End Sub
Form 2:
Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles BunifuCheckbox1.OnChange
If BunifuCheckbox1.Checked Then
tmrSLIDE2.Enabled = True
tmrSLIDE2.Start()
Else
tmrSLIDE2.Stop()
End If
End Sub
Private Sub tmrSLIDE_Tick(sender As Object, e As EventArgs) Handles tmrSLIDE2.Tick
trs2.ShowSync(Form1)
Me.Hide()
End Sub
Property tmrSLIDE interval = 60000
property tmrSLIDE2 interval = 120000
I just Want to have 1 Checkbox with a simplified code thank you!

How can I make a button move up in size (by going vertically up), but not in total size?

I'm having a slight conflict with a button which I've been working with in Visual Basic NET.
My first code sample is for my Button_Height_Tick, which controls changing the button's height:
Dim ChangeHeight As Boolean = False
Private Sub Button_Height_Tick(sender As Object, e As EventArgs) Handles Button_Height.Tick
If Not ChangeHeight Then
Do Until FlatButton1.Height = 63
FlatButton1.Height += 1
System.Threading.Thread.Sleep(1)
Loop
ChangeHeight = True
Else
End If
End Sub
And for my FlatButton1_MouseHover.
Private Sub FlatButton1_MouseHover(sender As Object, e As EventArgs) Handles FlatButton1.MouseHover
Button_Height.Enabled = True
Button_Height.Start()
End Sub
Now, as you can see in the Button_Height_Tick sub, the code changes the height of the button to 63, however, when this code is ran, the buttons total height is changed.
Here are some photos in-case I haven't explained it well.
What my original button looks like
What I want it to do
What it's doing (going up in size vertically going down, when I want it to go up)
Please comment below if you don't understand this question.
You need to change the 'Top' position and also I notice you have a timer then just go in a do a loop. In your example there's no need for a timer.
I'll give an example using a timer and hopefully you'll understand it and can use it for what you want. I've changed 'hover' to 'enter' and 'leave'.
If it's too slow just change the increment amount.
Dim ChangeHeight As Boolean = False
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ChangeHeight Then
FlatButton1.Height += 2
FlatButton1.Top -= 2
If FlatButton1.Height < 63 Then Exit Sub
FlatButton1.Height = 63
Timer1.Enabled = False
Else
FlatButton1.Height -= 2
FlatButton1.Top += 2
If FlatButton1.Height > 31 Then Exit Sub
FlatButton1.Height = 31
Timer1.Enabled = False
End If
End Sub
Private Sub FlatButton1_MouseEnter(sender As Object, e As EventArgs) Handles FlatButton1.MouseEnter
ChangeHeight = True
If Timer1.Enabled Then Exit Sub
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub FlatButton1_MouseLeave(sender As Object, e As EventArgs) Handles FlatButton1.MouseLeave
ChangeHeight = False
If Timer1.Enabled Then Exit Sub
Timer1.Enabled = True
Timer1.Start()
End Sub
Hello and welcome to StackOverflow. I did a little example of how to achieve what you are looking for.
Code:
Public Class Form1
Dim buttonXCoordinate As Integer
Dim buttonYCoordinate As Integer
Dim buttonOriginalHeight As Integer
Dim buttonOriginalLocation As Point
Private Sub GetButtonCoordinate()
buttonXCoordinate = testBtn.Left
buttonYCoordinate = testBtn.Top
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buttonOriginalHeight = testBtn.Height
buttonOriginalLocation = testBtn.Location
GetButtonCoordinate()
End Sub
Private Sub testBtn_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles testBtn.MouseEnter
Dim buttonLocation As Point = Nothing
GetButtonCoordinate()
buttonLocation.X += buttonXCoordinate
buttonLocation.Y += buttonYCoordinate - buttonOriginalHeight
testBtn.Height += buttonOriginalHeight
testBtn.Location = buttonLocation
End Sub
Private Sub testBtn_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles testBtn.MouseLeave
testBtn.Height = buttonOriginalHeight
testBtn.Location = buttonOriginalLocation
End Sub
End Class
I did it really fast but it's enough to give you an idea to how to achive your goal.
In my example there is a button called testBtn, when you go over it with the mouse it the button's height is increased and it returns back to normal when you move your mouse out of it

Change PictureBox Visibility After Certain Time VB.Net

I currently have it to where picturebox1 is visible on loadup and I would like to change it to where picturebox2 is visible and picturebox1 is not after 3 seconds. I have been unable to get this to visibly work. Any suggestions? I have looked around and saw the Picturebox.refresh & picturebox.update but have not been able to get these to work. I am open to suggestions on how to do this differently as well. Thanks for the help!
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.BackgroundImage = My.Resources.Resources._024689
PictureBox2.BackgroundImage = My.Resources.Resources._152522206296244269
PictureBox1.Visible = True
PictureBox2.Visible = False
InitializeComponent()
'starts timer
StartTimer.Interval = 1000
StartTimer.Start()
End Sub
Private Sub StartTimer_Tick(sender As Object, e As EventArgs) Handles StartTimer.Tick
time += 1
Debug.Print("Time = " & time)
If time = 3 Then
PictureBox2.Visible = True
PictureBox1.Visible = False
StartTimer.Stop()
End If
End Sub
For the record, this worked exactly as expected:
'Ensure that resources are loaded once only.
Private ReadOnly firstImage As Image = My.Resources.Capture__56x81_
Private ReadOnly secondImage As Image = My.Resources.Capture__70x264_
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.Image = firstImage
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
PictureBox1.Image = secondImage
End Sub
Note that the Interval of Timer1 was set to 3000 in the designer.

Enable a counter at a specific time everyday

I setup a counter which needs to be enabled at specific time everyday. for an example lets say at (3 PM) everyday. what i came up with is following piece of code. but it gives me an error when it reach the time saying parameter is not valid please help me,
Private t As Integer = 0
Private Sub Home_monitoring_tab_Load(sender As Object, e As EventArgs) Handles MyBase.Load
rs.FindAllControls(Me)
Execute()
End Sub
Private Sub Execute()
If DateTime.Now.ToString("HH:mm") = "15:00" Then
shift1_timer.Enabled = True
End If
End Sub
Private Sub shift1_timer_Tick(sender As Object, e As EventArgs) Handles shift1_timer.Tick
t += 1
Label14.Text = CStr(t)
End Sub
Try this, add a timer to your program and call it CheckTimer and update your code like this :
Private t As Integer = 0
Private Sub Home_monitoring_tab_Load(sender As Object, e As EventArgs) Handles MyBase.Load
rs.FindAllControls(Me)
CheckTimer.Interval = 1
CheckTimer.Start
End Sub
Private Sub CheckTimer_Tick(sender As Object, e As EventArgs) Handles CheckTimer.Tick
If DateTime.Now.ToString("HH:mm") = "15:00" Then
shift1_timer.Enabled = True
End If
End Sub
Private Sub shift1_timer_Tick(sender As Object, e As EventArgs) Handles shift1_timer.Tick
t += 1
Label14.Text = CStr(t)
End Sub
Hope it helped :)

Panel Location Sliding Effect in VB.NET

what's wrong in my code? my syntax is right, the logic and concept is right.
but when i run the program and pressed the button(that make the panel slides UPWARD) the panel doesn't stop. even though I put a condition inside the timer.
here's the code;
Private Sub btn_existing_Click(sender As Object, e As EventArgs) Handles btn_existing.Click
timerPanelSlider3.Start()
pnl_info1.Enabled = False
pnl_options.Enabled = False
End Sub
Private Sub timerPanelSlider3_Tick(sender As Object, e As EventArgs) Handles timerPanelSlider3.Tick
yy -= 5
pnl_existing.Location = New Point(4, yy)
'pnl_existing.BringToFront()
If pnl_existing.Location.Y = 225 Then
timerPanelSlider3.Stop()
End If
End Sub
Your Location.Y is not hitting 225 you can check if it gets below 225. Or change it's starting position to 625.
Private Sub btn_existing_Click(sender As Object, e As EventArgs) Handles btn_existing.Click
timerPanelSlider3.Start()
pnl_info1.Enabled = False
pnl_options.Enabled = False
End Sub
Private Sub timerPanelSlider3_Tick(sender As Object, e As EventArgs) Handles timerPanelSlider3.Tick
yy -= 5
pnl_existing.Location = New Point(4, yy)
'pnl_existing.BringToFront()
If pnl_existing.Location.Y < 225 Then
timerPanelSlider3.Stop()
End If
End Sub