Hi all,
I'm a long time programmer/developer but new to Visual Basic and the Visual Studio. I'm mainly an AS/400 RPG programmer, I just started working where I'll need to add Visual Basic to my toolset.
I'm using Visual Studio 2013. I started my VB learning trying to walk through the examples at www.vbtutor.net. I got stuck on www.vbtutor.net/vb2013/vb2013_lesson7.htm.
The instructions were to create a VB project, add a Picture Box, add an Image, add the OpenFileDialog, filter for JPEG Files| *.JPG|GIF Files|*.GIF|Windows Bitmaps|*.BMP.
So far so good. Then it says, quote,
>>Next, double-click on the View button and enter the following code:
<<
I did that. Below is my code.
>>
<<
I get the error
BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
I googled the error... according to what I googled I should add a WithEvents.
If so that should have been in the tutorial, but in any case, when I do that I get another error.
BC30242: 'WithEvents' is not valid on a method declaration.
>>
<<<<<<
I'm sure I'm missing something simple, but I'm stuck. I tried many variations of where to put the WithEvents.
I'm going to move on to the next lesson. Hopefully someone can clue me in what's happening with this one.
Regards,
Charlie
I'm a long time programmer/developer but new to Visual Basic and the Visual Studio. I'm mainly an AS/400 RPG programmer, I just started working where I'll need to add Visual Basic to my toolset.
I'm using Visual Studio 2013. I started my VB learning trying to walk through the examples at www.vbtutor.net. I got stuck on www.vbtutor.net/vb2013/vb2013_lesson7.htm.
The instructions were to create a VB project, add a Picture Box, add an Image, add the OpenFileDialog, filter for JPEG Files| *.JPG|GIF Files|*.GIF|Windows Bitmaps|*.BMP.
So far so good. Then it says, quote,
>>Next, double-click on the View button and enter the following code:
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If OFGSelectImage.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OFGSelectImage.FileName)
End If
End Sub
I did that. Below is my code.
>>
Code:
Public Class Form1
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, OFGSelectImage.HelpRequest
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OFGSelectImage.FileOk
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If OFGSelectImage.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OFGSelectImage.FileName)
End If
End Sub
End Class
I get the error
BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
I googled the error... according to what I googled I should add a WithEvents.
If so that should have been in the tutorial, but in any case, when I do that I get another error.
BC30242: 'WithEvents' is not valid on a method declaration.
>>
Code:
Public Class Form1
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, OFGSelectImage.HelpRequest
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OFGSelectImage.FileOk
End Sub
Private WithEvents Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If OFGSelectImage.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OFGSelectImage.FileName)
End If
End Sub
End Class
I'm sure I'm missing something simple, but I'm stuck. I tried many variations of where to put the WithEvents.
I'm going to move on to the next lesson. Hopefully someone can clue me in what's happening with this one.
Regards,
Charlie