Passing parameters in VB 2005!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nab

    #1

    Passing parameters in VB 2005!!

    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.Te xt)
    Dim objConverter As New localhost.Servi ce

    lblDollar.Text = CStr(objConvert er.Convert2Doll ar(myEuro))

    Does anyone know why this should work..?


    --
    UK
  • Mitchell S. Honnert

    #2
    Re: Passing parameters in VB 2005!!

    "Nab" <Nab@discussion s.microsoft.com wrote in message
    news:EC7020BC-8239-4D6C-9040-1F3920FC726E@mi crosoft.com...
    >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.Te xt)
    Dim objConverter As New localhost.Servi ce
    >
    lblDollar.Text = CStr(objConvert er.Convert2Doll ar(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

    >
    >
    --
    UK

    Comment

    • Nab

      #3
      Re: Passing parameters in VB 2005!!

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


      "Mitchell S. Honnert" wrote:
      "Nab" <Nab@discussion s.microsoft.com wrote in message
      news:EC7020BC-8239-4D6C-9040-1F3920FC726E@mi crosoft.com...
      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.Te xt)
      Dim objConverter As New localhost.Servi ce

      lblDollar.Text = CStr(objConvert er.Convert2Doll ar(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
      >
      >


      --
      UK
      >
      >
      >

      Comment

      Working...