Heresh Heresh - 1 year ago 67 Question

Learning vba but not working

I am working in visual studio and writing according to

in the Form1_Load procedure.

private void Form1_Load(object sender, EventArgs e)
Dim anInteger As Integer = 42
Dim aSingle As Single = 39.345677
Dim aString As String = "I like candy"
Dim aBoolean As Boolean = true

and the I click F5 to run it but I get 38 errors?!?!

Severity Code Description Project File Line Suppression State
Error CS1002 ; expected Variables c:\users\owner\desktop\documents\visual studio 2015\Projects\Variables\Variables\Form1.cs 22 Active

Answer Source

You've accidentally created a C# project instead of a VB one.

Typical signs to look out for if you're writing quick bits of code in either VB or C# and I, err... someone, didn't pay attention, are braces ({ and }, a.k.a. squiggly brackets) and the keyword void instead of Sub:

private void Form1_Load(object sender, EventArgs e)

as compared to the VB signatuer for the same method:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

As you haven't written much, the best course of action would be to go File->New->Project (discard the current one) and carefully choose "Visual Basic" under Templates, and you'll want a Windows Forms Application.

P.S. VBA is Visual Basic for Applications, which is a bit different from VB.NET.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download