BC30455 Argument not specified for parameter 'sender' of - vb.net

i need help with my code
Public Class Forma
Private Sub ProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ProjectToolStripMenuItem.Click
If ProjectToolStripMenuItem_Click() Then
Print(Form_load)
End If
End Sub
Private Sub Form_load(FormB As Object)
End Sub
End Class
but i keep getting BC30455 Argument not specified for parameter 'sender' of. What am i doing wrong

Your condition want to check the result of the event ProjectToolStripMenuItem_Click (click event of ProjectToolStripMenuItem). On this function you don't define the sender and e parameter.
You should review your code and fix the issues:
Public Class Forma
Private Sub ProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ProjectToolStripMenuItem.Click
If exampleFunction() Then '<-- choose the correct function or variable
Print(Form_load) '<-- Form_load?? maybe FormB??
End If
End Sub
Private Sub Form_load(FormB As Object)
End Sub
End Class
Some basics you should know:
A Sub doesn't return a value, so you can't use a Sub on a condition (only functions, variables and values can be used on a condition).
It looks like you check if the button / menu item was clicked by the user. You don't need to check because the event ProjectToolStripMenuItem_Click is called automatically if the user click on ProjectToolStripMenuItem. At the point you try to check the button / menu item was clicked it was actually clicked. You can find more information about Event Handlers on the official .NET docs.
The error message should be clear enough to solve the issue:
You have not supplied an argument for a required parameter.
To correct this error:
Supply an argument for the specified parameter.
source: https://learn.microsoft.com/en-us/dotnet/visual-basic/misc/bc30455
You try to print the form on button click?
Public Class Forma
Private printForm as Object
Private Sub ProjectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ProjectToolStripMenuItem.Click
If ConditionIsTrue() Then '<-- choose the correct Sub or Function
Me.printForm.Print()
End If
End Sub
Private Sub Form_load(FormB As Object)
'... maybe some other stuff
Me.printForm = FormB
'... maybe some other stuff
End Sub
End Class

You cannot pass a Sub as a Parameter Print(Form_load). FormB.Print() might be what you are looking for.

This looks like a problem : If ProjectToolStripMenuItem_Click() Then
It's a call to the same sub and it has no parameters specified.

Related

declared event which fires, but is not heard

I have a vb.net application which contains two forms. One is called "MapComponentForm" and another called "ComponentPropertiesForm". In the MapComponentForm I have defined an event which I want fired when the OK button is clicked. If the ComponentPropertiesForm is open, I want it to "hear" this event and act accordingly. Stepping through the code the event seems to fire as expected but the ComponentPropertiesForm seems to be oblivious to this. I've attached the code from the two forms after stripping out the non relevant code in hopes that someone can tell me why my event goes unheeded. I used the information here:
https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/events/walkthrough-handling-events
in constructing my own code.
Thanks for any suggestions.
Public Class MapComponentForm
Public Event PartMapped(ByRef status As Boolean)
Public Sub New(shape As Visio.Shape)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
_shape = shape
End Sub
Private Sub OkButton_Click(sender As Object, e As EventArgs) Handles OkButton.Click
'If the component properties window is open, refresh it
If Application.OpenForms().OfType(Of ComponentPropertiesForm).Any Then
RaiseEvent PartMapped(True)
End If
end sub
end class
Public Class ComponentPropertiesForm
Private WithEvents mPartMap As MapComponentForm
Private Sub ComponentPropertiesForm_Load(sender As Object, e As EventArgs) Handles Me.Load
mPartMap = New MapComponentForm(Nothing)
End Sub
Private Sub mPartMap_PartMapped(ByRef status As Boolean) Handles mPartMap.PartMapped
If status = True Then
MsgBox("something got mapped")
End If
End Sub
end class

Program ignoring code

Private Sub Play_Click(sender As Object, e As EventArgs) Handles Play.Click
WordGeneration()
userInput()
Once the user has clicked a button which has been implemented into my form it will then run each sub specified . However the problem is , i do not want the sub WordGeneration() being run more than once . Is there a way for me to program into my code to stop WordGeneration() from being run more than once so it doesnt keep randomly generating a word , as i only want it to generate one word.
Create a Boolean variable which you can set to True once you have called the code:
Public Class Form1
Private _codeCalled As Boolean = False
Private Sub Play_Click(sender As Object, e As EventArgs) Handles Play.Click
If Not _codeCalled Then
WordGeneration()
End If
userInput()
End Sub
End Class
So in your WordGeneration method set the variable _codeCalled = True.
This should then only call the method once. Anytime you want to call the method again look at setting _codeCalled = False. You may also want to give it a different name which better fits your structure.

VB how do I call a 'Public Sub' from a Class in the main form? (OOP)

I need to know how to call a Public Sub into the main form when I click a button. I need to show the calculations which are done in the class in the main form within a listbox.
You simply type the name of your sub. Here is a simple example :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Here you "call" the sub.
' If you have parameters you put them in the brackets.
YourSub()
End Sub
Public Sub YourSub() ' You can add parameters.
' Some code.
End Sub

One button to control another button on many user controls

Hey and sorry for another strange question...
I have 25 UserControls with a Start_Button on each of them - this Start_Button can either be Visible or not depending on whether the UserControl is active. On my form1 I have a Start_All button.
I would like to simulate a click of all the UserControl's Start_Buttons which are visible only.
Instead of simulating click-events expose a method for the start-functionality and call this method from the Start_Button.Click-event. Then you can use this method from wherever you want. On this way your code remains readable and reusable.
You should also provide an Active property in your UserControl which you can simply link to your start-button's Visible-property.
Presuming that the user-controls are in a container-control like Panel:
Public Sub StartAll()
Dim allActiveUserControls =
From uc In controlPanel.Controls.OfType(Of MyUserControlType)()
Where uc.Active
For Each uc In allActiveUserControls
uc.Start()
Next
End Sub
Here is an example for the Active property:
Public Property Active As Boolean
Get
Return StartButton.Visible
End Get
Set(value As Boolean)
StartButton.Visible = value
End Set
End Property
and here are the Start method and the event-handlers:
Public Sub Start()
' Do Something ... '
End Sub
Private Sub StartButton_Click(sender As System.Object, e As System.EventArgs) Handles StartButton.Click
Start()
End Sub
Private Sub Start_All_Click(sender As System.Object, e As System.EventArgs) Handles Start_All.Click
StartAll()
End Sub

Initialize not properly make with classes vb.net

So, I need to do an program for a client and he wants a search bar in it. So I made it and everything worked perfectly but I put it in my main form. Now, I want to put it in a class but when I initialize the program, it gives me the following error
An error occurred while creating the form. For more information,
see Exception.InnerException. The error is: The form is self-reference during
construction from a default instance, which led to infinite recursion. In the
constructor of the form, refer to the form using 'Me'.
I tried to put Me.Rbtn_X... but it doesn't recognize it.
Initialization
' Main form
Public Sub New()
InitializeComponent()
Initialize_search()
End Sub
Initialize_search()
' Main form
' search is initialize like this :
' Dim search as New Research
Private Sub Initialize_search()
search.generate_autocomplete()
End Sub
generate_autocomplete()
' Research class
Sub generate_autocomplete()
' Main_form = Main form
Dim field = ""
' This is the place where the program fail
If Main_form.RbtnR_avancee_contact.Checked Then
field = "personneressource"
Else
field = "beneficiaire"
End if
' ....
End Sub
Is there something I didn't understand or It's not possible to do it that way?
Edit: added Form_shown event
Public Sub New()
InitializeComponent()
' Initialize_search()
End Sub
Private Sub Form_personne_Shown(sender As Object, e As EventArgs) Handles Me.Shown
MessageBox.Show("You are in the Form.Shown event.")
End Sub
The form is not created (fully) until New completes. By adding your Initialize_search to it, it eventually leads to the statement `Main_form.RbtnR_avancee_contact.Checked'. This is wrong on two counts:
1) the form doesnt exist yet, so you cant refer to it. (this is what the error meant with 'form is self-reference during construction')
2) the ref should be Me.RbtnR (which is what it meant by 'refer to the form using 'Me'')
Move your Initialize_search to the Form_shown event. Your code should look like this (including Lar's suggestion)
' Main form
Public Sub New()
' REQUIRED
InitializeComponent()
End Sub
If there is really something that needs to be setup for this, add it to the form_shown event:
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Shown
' NOTE: even .NET refers to ME not MainForm etc
InitializePanel
InitializeSeach
End Sub
Then:
Private Sub Initialize_search()
search.generate_autocomplete(Me.RbtnR_avancee_contact.Checked)
End Sub
Then:
Sub generate_autocomplete(AdvContact as Boolean)
Dim field AS STRING = ""
If AdvContact Then
field = "personneressource"
Else
field = "beneficiaire"
End if
' ....
End Sub
Your search class doesn't have a reference to the instance of the form's controls.
Try passing the value instead:
Sub generate_autocomplete(advancedChecked As Boolean)
Dim field As String = ""
If advancedChecked Then
field = "personneressource"
Else
field = "beneficiaire"
End if
End Sub
Then when you call it:
search.generate_autocomplete(Me.RbtnR_avancee_contact.Checked)
Even if did work like you want it to, according to your code, it would always result in field containing the same value (whichever was set in designer).
Instead, try putting this code inside RbtnR_avancee_contact.Checked event. Or even TextChanged for the autocomplete box (and initialize it for the first time user enters anything), it would examine the checked state and populate autocomplete items.
With this approach, if your user never uses the search box, you don't need to initialize it.