How to get returnvalue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • soulfly73
    New Member
    • Sep 2007
    • 7

    How to get returnvalue

    Hello all,

    I'm very new to ASP.net, i have created an function
    Code:
    Public Function Margin(ByVal Retail As String, ByVal Dealer As String) As Long
            
            If Retail = "" Then
                Exit Function
            Else
                Dim RetailAmount As Long = CLng(Retail)
                Dim DealerAmount As Double = CLng(Dealer)
                Dim percentageSum As Double = RetailAmount - DealerAmount
                Dim Inbetween As Double = percentageSum / Retail
                Dim marginpercentage As Long = Mid(CStr(Inbetween), 3, 2)
            
                Dim marginresult = CStr(marginpercentage)
            End If
        End Function
    I call the function like
    Code:
     lblMarge.Text = Margin(dtrSelectArticles("RetailPrice"), dtrSelectArticles("DealerPrice"))
    But i dont get any result back, off course I'm forgetting something,but I don't see what.. Can anyone help me?
  • anijos
    New Member
    • Nov 2008
    • 52

    #2
    Hi,


    Try this.

    Code:
    Public Function Margin(ByVal Retail As String, ByVal Dealer As String) As Long
            
            If Retail = "" Then
                Exit Function
            Else
                Dim RetailAmount As Long = CLng(Retail)
                Dim DealerAmount As Double = CLng(Dealer)
                Dim percentageSum As Double = RetailAmount - DealerAmount
                Dim Inbetween As Double = percentageSum / Retail
                Dim marginpercentage As Long = Mid(CStr(Inbetween), 3, 2)
            
                Margin = marginpercentage
            End If
        End Function

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      I am looking and I see almost no .NET code in this, only old vb6 style behavior.
      Also, when Retail is "", you return no value? Wouldn't that be a problem? I really wish VBNET would not let you get away with silly mistakes like that, it should be a compiler error.

      Comment

      • soulfly73
        New Member
        • Sep 2007
        • 7

        #4
        Originally posted by Plater
        I am looking and I see almost no .NET code in this, only old vb6 style behavior.
        Also, when Retail is "", you return no value? Wouldn't that be a problem? I really wish VBNET would not let you get away with silly mistakes like that, it should be a compiler error.
        Hello Plater,

        Your so right, I have very little expirience with .NET, but learning.
        I changed it to When Retail = Nothing ;) ...
        No serious, I'm very new to .NET So I fall back on some old (more familiar) coding.

        For now I have changed the function much more to .NET simply cause it doesnt work on old style.

        But thanks for the reply.

        @ anijos. Thanks for the reply.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          What were you trying to do with this line:
          Dim marginpercentag e As Long = Mid(CStr(Inbetw een), 3, 2)

          It looks like you are converting a double to a string, taking a substring section of it, and trying to save it to a Long. There seems like there would be a lot wrong with that.
          If the value was 0.324
          Your substring value would be "32" right?
          Wouldn't you be better off multiplying 0.32 by 10 to get 32.4, and then casting it as a long, so as to only get the integer part?

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Originally posted by Plater
            What were you trying to do with this line:
            Dim marginpercentag e As Long = Mid(CStr(Inbetw een), 3, 2)

            It looks like you are converting a double to a string, taking a substring section of it, and trying to save it to a Long. There seems like there would be a lot wrong with that.
            If the value was 0.324
            Your substring value would be "32" right?
            Wouldn't you be better off multiplying 0.32 by 10 to get 32.4, and then casting it as a long, so as to only get the integer part?
            Dude, the poor guy doesn't understand .NET yet - I read your comment and laughed because if I was a new .NET programmer I'd have been left scratching my head...

            In .NET syntax you no longer assign the value to the function name, that is: Before, where we would specify something like:

            Code:
            Function MyFunction(ByVal Input As String) As String
              MyFunction = "Hello World"
            End Function
            and call it something like:

            Code:
            Dim MyString As String
            MyString = MyFunction
            And we'd see "Hello World"

            We now do:

            Code:
            Function MyFunction(ByVal Input As String) As String
              Return "Hello World"
            End Function
            
            Dim MyString As String = MyFunction
            Not a world different, but different enough that someone new to .NET might miss it...

            Comment

            • soulfly73
              New Member
              • Sep 2007
              • 7

              #7
              Originally posted by balabaster
              Dude, the poor guy doesn't understand .NET yet - I read your comment and laughed because if I was a new .NET programmer I'd have been left scratching my head...

              In .NET syntax you no longer assign the value to the function name, that is: Before, where we would specify something like:

              Code:
              Function MyFunction(ByVal Input As String) As String
                MyFunction = "Hello World"
              End Function
              and call it something like:

              Code:
              Dim MyString As String
              MyString = MyFunction
              And we'd see "Hello World"

              We now do:

              Code:
              Function MyFunction(ByVal Input As String) As String
                Return "Hello World"
              End Function
              
              Dim MyString As String = MyFunction
              Not a world different, but different enough that someone new to .NET might miss it...
              Hi balabaster, thanks for the explanation. The Return was indeed not in my knowledgebase ;) ...

              Lucky for me there are a lot of you experts outthere pointing me in the right direction. For now I'm still playing around with .NET. But I'm having fun doing it, so I really want to know the in's and out's. So the internet and some books are great sources.. Thanks!!

              Peter

              Comment

              Working...