PC Review


Reply
Thread Tools Rate Thread

Call Statement Difficulty???

 
 
Radith Silva
Guest
Posts: n/a
 
      14th May 2004
Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalculate.Click
If txtName.Text <> "" Then
If txtUnits.Text <> "" Then
If optOne.Checked Or optTwo.Checked Or optThree.Checked
Or optFour.Checked Then
'Data fine
Else
MessageBox.Show("Please choos an option button")
End If
Else
MessageBox.Show("txtUnits")
txtUnits.Focus()
End If
Else
MessageBox.Show("txtName")
txtName.Focus()
End If
End Sub

Private Sub cmdO_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdO.Click
Call cmdCalculate_Click()
End Sub

I have the two functions as stated above; now the call statement returns
the error:
C:\vbNet\beginning\nested_if\Form1.vb(141): Argument not specified for
parameter 'e' of 'Private Sub cmdCalculate_Click(sender As Object, e As
System.EventArgs)'.

PLS HELP

THANX



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Konrad L. M. Rudolph
Guest
Posts: n/a
 
      14th May 2004
Radith Silva wrote:
> Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdCalculate.Click
>
> Call cmdCalculate_Click()
>
> I have the two functions as stated above; now the call statement returns
> the error:
> C:\vbNet\beginning\nested_if\Form1.vb(141): Argument not specified for
> parameter 'e' of 'Private Sub cmdCalculate_Click(sender As Object, e As
> System.EventArgs)'.


yea well, you omitted both parameters for cmdCalculate_Click. Obviosuly,
that is wrong.
Try

\\\
cmdCalculate_Click(Nothing, Nothing)
///

btw: why do you write "Call"?

--
Konrad -
http://madrat.net/
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      14th May 2004
"Radith Silva" <(E-Mail Removed)> schrieb
> Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdCalculate.Click
> If txtName.Text <> "" Then
> If txtUnits.Text <> "" Then
> If optOne.Checked Or optTwo.Checked Or
> optThree.Checked
> Or optFour.Checked Then
> 'Data fine
> Else
> MessageBox.Show("Please choos an option
> button")
> End If
> Else
> MessageBox.Show("txtUnits")
> txtUnits.Focus()
> End If
> Else
> MessageBox.Show("txtName")
> txtName.Focus()
> End If
> End Sub
>
> Private Sub cmdO_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles cmdO.Click
> Call cmdCalculate_Click()
> End Sub
>
> I have the two functions as stated above; now the call statement
> returns the error:
> C:\vbNet\beginning\nested_if\Form1.vb(141): Argument not specified
> for parameter 'e' of 'Private Sub cmdCalculate_Click(sender As
> Object, e As System.EventArgs)'.



Better approach (IMO):

private sub Calculate()
If txtName.Text <> "" Then
If txtUnits.Text <> "" Then
If optOne.Checked Or optTwo.Checked Or optThree.Checked Or
optFour.Checked Then
'Data fine
Else
MessageBox.Show("Please choos an option button")
End If
Else
MessageBox.Show("txtUnits")
txtUnits.Focus()
End If
Else
MessageBox.Show("txtName")
txtName.Focus()
End If
end sub

Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalculate.Click
Calculate()
end sub

Private Sub cmdO_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles cmdO.Click
Calculate
End Sub


- OR -

Delete Sub cmdO_Click and have Sub cmdCalculate_Click handle the click of
both controls:

Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalculate.Click, cmdO.Click

Notice the 2nd event after "Handles".


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      14th May 2004
"Radith Silva" <(E-Mail Removed)> schrieb
> Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdCalculate.Click
> If txtName.Text <> "" Then
> If txtUnits.Text <> "" Then
> If optOne.Checked Or optTwo.Checked Or
> optThree.Checked
> Or optFour.Checked Then
> 'Data fine
> Else
> MessageBox.Show("Please choos an option
> button")
> End If
> Else
> MessageBox.Show("txtUnits")
> txtUnits.Focus()
> End If
> Else
> MessageBox.Show("txtName")
> txtName.Focus()
> End If
> End Sub
>
> Private Sub cmdO_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles cmdO.Click
> Call cmdCalculate_Click()
> End Sub
>
> I have the two functions as stated above; now the call statement
> returns the error:
> C:\vbNet\beginning\nested_if\Form1.vb(141): Argument not specified
> for parameter 'e' of 'Private Sub cmdCalculate_Click(sender As
> Object, e As System.EventArgs)'.



Better approach (IMO):

private sub Calculate()
If txtName.Text <> "" Then
If txtUnits.Text <> "" Then
If optOne.Checked Or optTwo.Checked Or optThree.Checked Or
optFour.Checked Then
'Data fine
Else
MessageBox.Show("Please choos an option button")
End If
Else
MessageBox.Show("txtUnits")
txtUnits.Focus()
End If
Else
MessageBox.Show("txtName")
txtName.Focus()
End If
end sub

Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalculate.Click
Calculate()
end sub

Private Sub cmdO_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles cmdO.Click
Calculate
End Sub


- OR -

Delete Sub cmdO_Click and have Sub cmdCalculate_Click handle the click of
both controls:

Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalculate.Click, cmdO.Click

Notice the 2nd event after "Handles".


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      14th May 2004
Radith,
In addition to the other's comments, you can also use Button.PerformClick.

> Private Sub cmdO_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles cmdO.Click


cmdCalculate.PerformClick()

> End Sub


This way if you have multiple handlers for a given button, then all the
handlers will be invoked.

Although I prefer to use Armin's first example. I normally have a single
handler both handle the same event.

Remember VB.NET event model is not your VB6 event model! You can have
multiple handlers for a given event, plus a given event handler can handle
events from multiple objects.

Notice in the following "Button_Click" handles the click event for all three
buttons, while each button also has their own specific handler. This would
be handy if you have some common logic that needed to occur for every click,
plus some specific logic for every click. Or the buttons occur in the base
form and the base form wants to handle the events, plus the derived form
wants to handle the events...

Private WithEvents Button1 As Button
Private WithEvents Button2 As Button
Private WithEvents Button3 As Button

> Private Sub Button_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
> End Sub


> Private Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> End Sub


> Private Sub Button2_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> End Sub


> Private Sub Button3_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button3.Click
> End Sub


Hope this helps
Jay

"Radith Silva" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdCalculate.Click
> If txtName.Text <> "" Then
> If txtUnits.Text <> "" Then
> If optOne.Checked Or optTwo.Checked Or optThree.Checked
> Or optFour.Checked Then
> 'Data fine
> Else
> MessageBox.Show("Please choos an option button")
> End If
> Else
> MessageBox.Show("txtUnits")
> txtUnits.Focus()
> End If
> Else
> MessageBox.Show("txtName")
> txtName.Focus()
> End If
> End Sub
>
> Private Sub cmdO_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles cmdO.Click
> Call cmdCalculate_Click()
> End Sub
>
> I have the two functions as stated above; now the call statement returns
> the error:
> C:\vbNet\beginning\nested_if\Form1.vb(141): Argument not specified for
> parameter 'e' of 'Private Sub cmdCalculate_Click(sender As Object, e As
> System.EventArgs)'.
>
> PLS HELP
>
> THANX
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      14th May 2004
* "Konrad L. M. Rudolph" <(E-Mail Removed)> scripsit:
> yea well, you omitted both parameters for
> cmdCalculate_Click. Obviosuly, that is wrong.
>
> Try
>
> \\\
> cmdCalculate_Click(Nothing, Nothing)
> ///
>
> btw: why do you write "Call"?


I would call the button's 'PerformClick' method. Instead of passing
'Nothing', you should pass a reference to the button in the 1st
parameter and 'EventArgs.Empty' in the 2nd parameter.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      14th May 2004
Hi Radith,

A lot of answers mostly on click events, I give another approach however
more with the point to show you the purpose of the OrElse operator.

I also give another method for that click event (Keep in mind there is no
best and there are much more methods).

Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalculate.Click
If txtName.Text <> "" Then
If txtUnits.Text <> "" Then
If optOne.Checked OrElse optTwo.Checked OrElse
optThree.Checked

The OrElse stops evaluating when the condition is True.

OrElse optFour.Checked Then
'Data fine
Else
MessageBox.Show("Please choos an option button")
End If
Else
MessageBox.Show("txtUnits")
txtUnits.Focus()
End If
Else
MessageBox.Show("txtName")
txtName.Focus()
End If
End Sub

Private Sub cmdO_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdO.Click
cmdCalculate_Click(sender, e) 'Only when the signatures are equal
as in this case
End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Statement caldog Microsoft Excel Programming 4 11th Jan 2010 11:28 PM
Using the Call Statement caldog Microsoft Excel Programming 2 9th Jan 2010 02:59 PM
Difficulty with Arrays in Excel's DECLARE statement MichaelDavid Microsoft Excel Programming 0 3rd Mar 2009 07:41 AM
SQL Statement trying to call column not specified in statement Trepalium@gmail.com Microsoft Access Form Coding 2 15th May 2007 10:38 PM
Re: IF Statement difficulty susan hayes Microsoft Excel Worksheet Functions 3 2nd Nov 2004 09:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:08 PM.