BC30205 End of statement expected in VB - vb.net

I'm having issues with VB.net.
I'm trying to make a file pumper for myself, but I'm not really having much luck with it. upon typing a whole line of code, I eventually stumble upon the error of "BC30205 End of statement expected". I know this error has been asked here before, but my code is different.. I guess...Thhe specific line that gives me an error is:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load rbtnMegaByte.Checked = True
Visual Studio recommends me to delete both "System" in the code and keep it as "Object" and "EventArgs" but upon listening to Visual Studio I still have the "End of statement expected" error.
I'm not really the best at this, so sorry if this is a really easy mistake.

That one line of code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load rbtnMegaByte.Checked = True
Should be two lines:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
rbtnMegaByte.Checked = True
I guess you have copied and pasted this from somewhere and it hasn't preserved the carriage returns?
You will also need End Sub further down but I assume that you have that already? So your subroutine should look like this:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
rbtnMegaByte.Checked = True
'Any other code here
End Sub

This error may raised if you forget to close any block, check your blocks i.e check end if for any if or check end sub for sub etc. it would be better if you share some more code of that module

Related

getting problems with Me.close

so im trying to make it that when you click an image, it will close the current form. but I'm getting this error.
Property access must assign to the property or use its value.
and here's the code
Private Sub PictureBox4_Click(sender As System.Object, e As System.EventArgs) Handles close.Click, close.Click
Me.close()
form1.Show()
End Sub
that's everything. thanks!
the handles event gets problem. remove close.click,close.clic and Copy the PictureBox1.Click after Handles in your click function
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

Visual Studio 2019 (vb) - issue with Reading/Writing My.Settings

I'm just starting to develop and so there are some concepts that are not clear to me, I need you to try to understand what I'm doing wrong.
My goal is to have a series of ComboBoxes that contain some strings, for example a string is this one, the ComboBox is called TYPE:
I am storing these strings in My.Settings for my convenience and to edit them directly from the app.exe.config file (these information are stored there right?).
I'm using this code
Private Sub AdminPanel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each item In My.Settings.TYPE
ComboBoxType.Items.Add(item)
Next
End Sub
My issue is that, I'm unable to read from My.Settings.TYPE and when I try to write into it with the following code I doesn't find any strings added into My.Settings menu neither into app.exe.config.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ButtonTYPEAddValue.Click
ComboBoxType.Items.Add(TextBoxType.Text)
ComboBoxType.Text = TextBoxType.Text
TextBoxType.Clear()
MsgBox("Item added!")
End Sub
what is wrong?
In your code, it seems like you've used String to add/remove the ComboBoxType items. Follow the steps to achieve your requirement:
In this screenshot, you can see I've set the Type as System.Collection.Specialized.StringCollection to separate each time for future use.
Now, you may use the following code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.tests.Add(TextBox1.Text)
My.Settings.Save()
ComboBox1.Items.Add(TextBox1.Text)
End Sub
Private Sub AdminPanel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each item In My.Settings.tests
ComboBox1.Items.Add(item)
Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
My.Settings.tests.Remove(TextBox1.Text)
My.Settings.Save()
ComboBox1.Items.Remove(TextBox1.Text)
End
It's noticeable that you can change the variable names, they're differ a bit than yours in my code.
Form structure for the code:
On the MyBase.Load event, all the items containing in My.Settings.tests will be added using For Each loop (benefit of StringCollection).
Working example of the form [adding - removing using My.Settings]:
I hope you've got your answer.

What does Handles do?

I got my first progamming experience at Visual Basic 6.0. So now, I use Visual Basic 2015. And I See some Different at the Code.
In Visual Basic 2015
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
So in VB 6.0 I didn't found such a code like "Handles MyBase.Load", what does Handles mean and what is it do?
From a VB6 perspective, it allows you to name your event handler procedure whatever you want. In VB6, you are required to have the format MyControl_someEvent, where MyControl is the name of the control and someEvent is the name of the event being handled. In VB.Net, you can call your event whatever you want. For example, the code you have above:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Could be written thus:
Private Sub HowAboutThemCUBS(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
And it would still fire when the MyBase.Load event got triggered.
You should read the links that the other responders have posted, too. There is more that you ought to know about the differences than just this (for example, this structure allows you to have a single handler that handles more than one type of event, which you couldn't do in VB6).
Handles will listen for the events that follow eg. MyBase.Load, and when one of those events happens, the method will run
Try reading the documentation for Handles it has a good explination about them:
msdn.microsoft.com/en-us/library/6k46st1y.aspx

How do you get to the .enter code automatically in visual basic?

Okay I realize the question is ambiguous, but I didn't know what else to name it. As all of you know if I double click a textbox in visual basic it gives me this code automatically.
Private Sub textBox1_Click(sender As Object, e As EventArgs) Handles textBox1.Click
'do stuff here
End Sub
What do you click or otherwise have to do to get this to show up automatically?
Private Sub textBox1_Enter(sender As Object, e As EventArgs) Handles textBox1.Enter
'do stuff here
End Sub
What about this one as well
Private Sub textBox1_TextChanged(sender As Object, e As EventArgs) Handles textBox1.TextChanged
'do stuff here
End Sub
Select the textbox. In the Properties pane/window (press F4 if can't see it), click the icon which looks a bit ilke a lightning bolt to get a list of the available handlers. Double-click the one you want and it will create the template for you.

Why do I get an InvalidOperationsException error?

Here's the deal. I tried using classes instead of the usual modules(in an attempt to try a different approach[aside from what I know that is] to OOP). So I used classes and in a simple showing and hiding of forms, I got an InvalidOperationsException error. Weirded out, I removed the OOP parts and just tried calling the other form directly on the form itself and still got the same error.
Here's the error I get:
An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'
Here's the code:
Private Sub btnNewSales_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewOrder.Click
'This ought to have opened the new form via a method in the class
'order.NewOrder()
frmNewOrder.Show()
Me.Hide()
End Sub
either way, I get the same error.
Tried using modules instead. Here's the code:
Public Sub ShowForm(ByVal frmName As String)
If frmName = "Order" Then
frmOrders.Show()
ElseIf frmName = "AddOrder" Then
frmAddOrder.Show()
End If
End Sub
Now so far (in all my programming experience) this ought to work just fine, but it still returns the same error..
Update!
Tried removing all OOP aspects in form calling and left a module to simply show or hide some controls in one form.
Here's the code in the module:
Public Sub DesignSelect(ByVal design As String)
If design = "Basic" Then
frmAddOrder.lblD3.Hide()
frmAddOrder.cmbD3Color.Hide()
frmAddOrder.cmbD3Type.Hide()
frmAddOrder.lblD4.Hide()
frmAddOrder.cmbD4Color.Hide()
frmAddOrder.cmbD4Type.Hide()
Else
End If
End Sub
Now correct me if I'm wrong, but I do believe nothing is wrong with it right?
Now here's the code of the form where the module was used:
Dim selectedDesign As String = ""
Private Sub frmSalesTrans_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub frmSalesTrans_FormClosing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosing
'ShowForm("Order")
frmOrders.Show()
End Sub
Private Sub rdbBasic_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbBasic.CheckedChanged
selectedDesign = "Basic"
DesignSelect(selectedDesign)
End Sub
And here's the code of the form that calls the form above:
Private Sub frmSales_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnNewSales_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewOrder.Click
Me.Hide()
frmAddOrder.Show()
End Sub
Now it just boggles me why I get this error.. If I removed all OOP (including the subprocedure DesignSelect), it works fine. Kindly enlighten me on this...