Vb.net animation sonic the hedgehog - visual-studio-2010

Why does my walk not work but the run works properly sonic the hedgehog animation.
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PictureBox1.Image = My.Resources.SONICRUN1_removebg_preview
Timer1.Stop()
Timer2.Start()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
PictureBox1.Image = My.Resources.SONICRUN2_removebg_preview
Timer2.Stop()
Timer1.Start()
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
PictureBox1.Image = My.Resources.SONICRUN3_removebg_preview
Timer3.Stop()
Timer2.Start()
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
PictureBox1.Image = My.Resources.SONICRUN4_removebg_preview
Timer4.Stop()
Timer3.Start()
End Sub
Private Sub btnRUN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRUN.Click
Timer1.Enabled = True
Timer5.Enabled = False
End Sub
Private Sub btnWALK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWALK.Click
Timer5.Enabled = True
Timer1.Enabled = False
End Sub
Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
PictureBox1.Image = My.Resources.SONICWALK1_removebg_preview
Timer5.Stop()
Timer4.Start()
End Sub
Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
PictureBox1.Image = My.Resources.SONICWALK2_removebg_preview
Timer6.Stop()
Timer5.Start()
End Sub
Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
PictureBox1.Image = My.Resources.SONICWALK3_removebg_preview
Timer7.Stop()
Timer6.Start()
End Sub
Private Sub Timer8_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer8.Tick
PictureBox1.Image = My.Resources.SONICWALK4_removebg_preview
Timer8.Stop()
Timer7.Start()
End Sub
Private Sub Timer9_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer9.Tick
PictureBox1.Image = My.Resources.SONICWALK5_removebg_preview
Timer9.Stop()
Timer8.Start()
End Sub
Private Sub Timer10_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer10.Tick
PictureBox1.Image = My.Resources.SONICWALK6_removebg_preview
Timer10.Stop()
Timer9.Start()
End Sub
Private Sub Timer11_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer11.Tick
PictureBox1.Image = My.Resources.SONICWALK7_removebg_preview
Timer11.Stop()
Timer10.Start()
End Sub
Private Sub Timer12_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer12.Tick
PictureBox1.Image = My.Resources.SONICWALK8_removebg_preview
Timer12.Stop()
Timer11.Start()
End Sub
End Class
I tried doing it again erased it and it still didn't walk he was still running.
When I press the run it works ok. But when I press the walk it won't do the walk animation! Also when I start the program it starts running already. I want it to not run when the program is started I want it to run when I press the buttons.

The Run command starts Timer1. When Timer1 is done it starts Timer2. When Timer2 is done it goes back to Timer1. So run is just toggling back and forth between Timer1 and Timer2.
The Walk command starts Timer5, which starts Timer4 --> Timer3 --> Timer2 --> Timer1...and then gets stuck in the Run cycle toggling between Timer1 and Timer2.
What should the Walk sequence be?
If you don't want anything to be animating, then select each Timer and set the Enabled property to FALSE. Make sure you aren't turning any Timers on in the Load() event of your Form.
Try something like this out:
Public Class Form1
Private runSequence() As Image
Private walkSequence() As Image
Private runIndex As Integer = -1
Private walkIndex As Integer = -1
Private WithEvents trmRun As New System.Windows.Forms.Timer
Private WithEvents trmWalk As New System.Windows.Forms.Timer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
runSequence = {My.Resources.SONICRUN1_removebg_preview, My.Resources.SONICRUN2_removebg_preview,
My.Resources.SONICRUN3_removebg_preview, My.Resources.SONICRUN4_removebg_preview}
walkSequence = {My.Resources.SONICWALK1_removebg_preview, My.Resources.SONICWALK2_removebg_preview,
My.Resources.SONICWALK3_removebg_preview, My.Resources.SONICWALK4_removebg_preview,
My.Resources.SONICWALK5_removebg_preview, My.Resources.SONICWALK6_removebg_preview,
My.Resources.SONICWALK7_removebg_preview, My.Resources.SONICWALK8_removebg_preview}
trmRun.Interval = 100
trmRun.Enabled = False
trmWalk.Interval = 100
trmWalk.Enabled = False
End Sub
Private Sub btnRUN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
trmWalk.Stop()
trmRun.Start()
End Sub
Private Sub btnWALK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWalk.Click
trmRun.Stop()
trmWalk.Start()
End Sub
Private Sub trmRun_Tick(sender As Object, e As EventArgs) Handles trmRun.Tick
runIndex = runIndex + 1
If runIndex = runSequence.Length Then
runIndex = 0
End If
PictureBox1.Image = runSequence(runIndex)
End Sub
Private Sub trmWalk_Tick(sender As Object, e As EventArgs) Handles trmWalk.Tick
walkIndex = walkIndex + 1
If walkIndex = walkSequence.Length Then
walkIndex = 0
End If
PictureBox1.Image = walkSequence(walkIndex)
End Sub
End Class

Related

VBa : multiple pictures on multiple picturebox

hi its a catalogue application
I have 50 pictures on my folder but i want in the app load show 12 pictures in 12 picturebox
i use this code but it gives me nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pic As PictureBox
For i = 0 To 12
pic = Me.Controls("picturebox" & i)
pic.Image = Image.FromFile("C:\Dev\Images\TEST400.jpg")
Next i
End Sub
Help plz
Your image files should be saved as TEST1.jpg,TEST2.jpg, ......TEST12.jpg etc.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim pic As PictureBox
For i = 1 To 12
pic = Me.Controls("picturebox" & i)
pic.Image = Image.FromFile(#"C:\Dev\Images\TEST" + i.ToString +".jpg")
Next i
End Sub
Note: I just wrote this code here only. Its not tested.

Visual Basic 2010 Express - How do you switch back and forth between two images that are on top of each other?

I really need some help with this dilemma.
I have two pictures of a light bulb. In one picture the light bulb is shining brightly and in the other it’s turned off. I’m supposed to overlap these pics and make it turn on and off by clicking on the image but I just can’t figure out the code for it. How do you toggle between these images? I am not allowed to use a button to do this. I've got to click on the pic to change it. Please help! Link below as I do not have enough rep to post actual images yet.
http://i1293.photobucket.com/albums/b598/BentoBoy1/ScreenHunter_02Sep202252_zps75800aea.png
Public Class Form1
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
'Close the program
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'Print the form in the print preview window
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Turn the light bulb on.
MessageLabel.Text = "Turn on the light"
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MessageLabel.Click
'Display different messages when the light bulbs are clicked.
End Sub
Private Sub RedRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedRadioButton.CheckedChanged
'Set the MessageLabel text to Red.
MessageLabel.ForeColor = Color.Red
End Sub
Private Sub BlackRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlackRadioButton.CheckedChanged
'Set the MessageLabel text to Black.
MessageLabel.ForeColor = Color.Black
End Sub
Private Sub BlueRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueRadioButton.CheckedChanged
'Set the MessageLabel text to Blue.
MessageLabel.ForeColor = Color.Blue
End Sub
Private Sub GreenRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenRadioButton.CheckedChanged
'Set the MessageLabel text to Green.
MessageLabel.ForeColor = Color.Green
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgrammedByLabel.Click
'Programmed by me.
End Sub
Private Sub ColorsGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorsGroupBox.Enter
'Group of different colors.
End Sub
Private Sub NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameTextBox.TextChanged
'Name field.
End Sub
Private Sub PictureBox1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightOnPictureBox.Click
'Light bulb is on.
LightOnPictureBox.Image = My.Resources.lighton
MessageLabel.Text = "Thanks for turning me on, " & NameTextBox.Text
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightOffPictureBox.Click
'Light bulb is off.
LightOffPictureBox.Image = My.Resources.lightoff
MessageLabel.Text = "Thanks for turning me off, " & NameTextBox.Text
End Sub
Private Sub NameLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameLabel.Click
'Name label.
End Sub
End Class
Firstly, i think that you should take a look here in order to understand the way images comparisson takes place. Secondly, the proper event to change the picture is the PictureBox.Click...
The code should be like the following one:
Public Class Form1
Dim imageBulbOff As Image = My.Resources.BulbOff
Dim imageBulbOn As Image = My.Resources.BulbOn
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = imageBulbOff
End Sub
Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
If PictureBox1.Image Is imageBulbOff Then
PictureBox1.Image = imageBulbOn
Else
PictureBox1.Image = imageBulbOff
End If
End Sub
End Class

visual basic twittervb issue

This code is throwing TwitterAPIException on this line
profilepic.ImageLocation = twitter.AccountInformation.ProfileImageUrl
I have a feeling it may be because it isn't authenticating but I'm not sure. any idea why i might be getting this, also how can i in my code check if twitter has authenticated me before trying to actually read data?
I have removed the private keys for privacy
Imports TwitterVB2
Public Class Form1
Dim twitter As New TwitterAPI
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles verify_btn.Click
twitter.AuthenticateWith("", "", "", "")
profilepic.BackColor = Color.White
profilepic.ImageLocation = twitter.AccountInformation.ProfileImageUrl
tw_name.Text = "HI" + twitter.AccountInformation.Name
For Each Tweet As TwitterStatus In twitter.HomeTimeline
tweets.AppendText(vbNewLine + vbNewLine + Tweet.User.ScreenName + vbNewLine + Tweet.Text + vbNewLine + Tweet.CreatedAtLocalTime + vbNewLine + vbNewLine + "..............................")
Next
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tw_name.Click
End Sub
Private Sub profilepic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles profilepic.Click
End Sub
End Class
I'm the developer of TwitterVB. :)
Because I stopped updating the library in 2011, TwitterVB was never updated to work with version 1.1 of the Twitter API. I've gotten many, many requests to address this specific issue, so I have made an updated version of the DLL available here:
https://github.com/DWRoelands/TwitterVB/releases/tag/3.1.1
Please note that I have done no testing and that this DLL should be considered "pre-release". If you have questions or issues, I'll do my best to answer them. You can reach me via my GitHub page:
https://github.com/DWRoelands

Programmatically adding event handler to array of radio buttons

Trying to add event handlers to radio buttons that are created on user input, looking at this and this as examples.
However I get an error that answerOptions is not an event.
Create the radio buttons
Private answerOptions(n) As RadioButton
...
Private Sub showQuestion(n As Integer)
For i = 0 To answerOptions.Length - 1
answerOptions(i) = New RadioButton
AddHandler answerOptions, AddressOf Me.Radios_Click
With answerOptions(i)
' --------- SET TEXT, LOCATION ETC.
End With
Me.Controls.Add(answerOptions(i))
Next
End Sub
Planning on then handling events with
Private Sub Radios_Click(sender As Object, e As EventArgs) Handles answerOptions.checked
End Sub
I want things to happen when the radios are checked. Don't want to use checkboxes as I want to limit one selection at a time.
Try this in your form or page
Private Sub ClickButton(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim Rbtn As RadioButton
Rbtn = CType(sender, RadioButton)
MsgBox(Rbtn.Text)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim Rbtn As New RadioButton()
For i = 0 To 19
Rbtn = New RadioButton()
With Rbtn
.Name = "RBtn" & i
.Text = .Name
.Checked = False
.Left = 20
.Top = (i * 20)
.Visible = True
Me.Controls.Add(Rbtn)
AddHandler Rbtn.Click, AddressOf ClickButton
End With
Next
End Sub

Adjusting Windows Speaker Volume VB.NET

How do I change the Windows Speaker Volume (The Main Output Volume Control Volume Value) via VB.NET? I want a way to like indirectly change the whole system's volume like we do it from the Volume Control application on Windows 7
From:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/8308f020-b9e6-472c-aaac-93619a8a5a7d/vbnet-control-the-system-volume-mute-and-output-the-current-level-to-the-user?forum=vbgeneral
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Const WM_APPCOMMAND As UInteger = &H319
Const APPCOMMAND_VOLUME_UP As UInteger = &HA
Const APPCOMMAND_VOLUME_DOWN As UInteger = &H9
Const APPCOMMAND_VOLUME_MUTE As UInteger = &H8
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H30292, APPCOMMAND_VOLUME_UP * &H10000)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H30292, APPCOMMAND_VOLUME_DOWN * &H10000)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H200EB0, APPCOMMAND_VOLUME_MUTE * &H10000)
End Sub
End Class
I was able to throw this together in a minute no problems.

Resources