Passing parameters in VB 2005!!

G

Guest

I have just tried to pass parameters to a procedure in VB 2005 and realised
that you only need to pass the input parameter. The output parameter's value
will be returned without the need to pass it as was the case in the previous
version of VB e.g. VB .Net 2003.

Here's the procedure in the web service:
Public Sub Convert2Dollar(ByVal euroAmount As Double, ByRef usDollarAmount
As Double)
Dim exchangeRate As Double
exchangeRate = 10 / 6

usDollarAmount = euroAmount * exchangeRate
End Sub

Here's how i passed an input parameter in a button's click procedure (and it
worked!!):

Dim myEuro As Double
myEuro = CDbl(txtEuro.Text)
Dim objConverter As New localhost.Service

lblDollar.Text = CStr(objConverter.Convert2Dollar(myEuro))

Does anyone know why this should work..?
 
M

Mitchell S. Honnert

Nab said:
I have just tried to pass parameters to a procedure in VB 2005 and realised
that you only need to pass the input parameter. The output parameter's
value
will be returned without the need to pass it as was the case in the
previous
version of VB e.g. VB .Net 2003.

Here's the procedure in the web service:
Public Sub Convert2Dollar(ByVal euroAmount As Double, ByRef usDollarAmount
As Double)
Dim exchangeRate As Double
exchangeRate = 10 / 6

usDollarAmount = euroAmount * exchangeRate
End Sub

Here's how i passed an input parameter in a button's click procedure (and
it
worked!!):

Dim myEuro As Double
myEuro = CDbl(txtEuro.Text)
Dim objConverter As New localhost.Service

lblDollar.Text = CStr(objConverter.Convert2Dollar(myEuro))

Does anyone know why this should work..?
It's not working for me. I copied your code into a test form and get the
following error on the reference to Convert2Dollar...
"Argument not specified for parameter 'usDollarAmount' of 'Public Sub
Convert2Dollar(ByVal euroAmount As Double, ByRef usDollarAmount As Double)'"

Are you sure you don't have an overload of Convert2Dollar that only has a
single parameter of type Double? That's the only thing that makes sense to
me given that you are not getting an error.

Also, some unsolicited advice. I would change your Sub to a Function. You
have a single input and a single output, a textbook use for a Function. So,
your code would look like this...

Public Function Convert2Dollar(ByVal euroAmount As Double) As Double

Dim ExchangeRate As Double = 10 / 6

Return euroAmount * ExchangeRate

End Function

If this is more than just a sample to demonstrate your problem, you might
also consider passing in the exchange rate.

Good luck.

- Mitchell S. Honnert
 
G

Guest

It's possible. Thanks for the thought and it's nice to know that Microsoft
has not changed the law of passing parameters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top