Results 1 to 5 of 5

Thread: Function Always Returns Null or Zero

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Muscatine, Iowa, USA
    Posts
    18

    Unhappy

    Hi Everyone,
    I 've created a funcion and I cannot get it to return a value other than Null or Zero. I've tried changing the type returned.... Text, Long, Integer etc. I orginally had it in a class, then I moved it to a module and finally to the form it is used in....with no results. I get no errors but also no data. I'm at my wits end!!!! The code follows.

    Dim WrkStrikePrc As Currency
    Dim WrkOutNbrOfOSO As Long
    Dim GrantPrice As Currency
    Dim NetOSOWorth As Currency
    Dim AdjExerPrc As Currency
    Dim OutPerfPrecent As Double
    Dim SucMult As Double
    Dim PreMultGain As Currency
    Dim PostMultGain As Currency
    Dim AwardTotVal As String


    '
    AwardTotVal = CalcOSOValue _
    (WrkStrikePrc, AnSPGrw, AnLVLTGrw, _
    AvgStockPrc, WrkOutNbrOfOSO)

    ' Use Debug to check the value of AwardTotVal will = Null here

    Public Function CalcOSOValue _
    (IntStrPrc As Currency, _
    AnSPGrw As Double, AnLVLGrw As Double, _
    AvgStockPrc As Currency, WrkOSOAwd As Long) _
    As String
    AwardTotVal = "Anything"

    ' Use Debug to Check value of AwardtotVal will = Something Here

    End Function

    Thanks Again!

  2. #2
    Guest
    Hello,

    In order for a function to retun a value you must assign the value to return:

    Code:
    Public Function DemoTest(sDataIn as String) as String
    
      Dim SDataOut As String
    
      sDataOut = SDataIn & "It's Out now"
    
      DemoTest = sDataOut
    
    End Function
    Try something like that

    Best

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Muscatine, Iowa, USA
    Posts
    18

    Wink Many Thanks!!1

    Hi Roger,
    I got it to work. I still don't understand what was wrong with my original code but this works.
    Thanks Again,
    Jim

    ' Everything in call is Dimmed before here
    ' I understood that the return value would be assigned to MyTotVal But it is still Null or Zero

    ' This is the Call
    MyTotVal = CalcOSOValue _
    (WrkStrikePrc, AnSPGrw, AnLVLTGrw, _
    AvgStockPrc, WrkOutNbrOfOSO, AwardTotVal)

    ' This is the Function
    Public Function CalcOSOValue _
    (WrkStrikePrc As Currency, _
    AnSPGrw As Double, AnLVLTGrw As Double, _
    AvgStockPrc As Currency, WrkOutNbrOfOSO As Long, AwardTotVal As Currency) _
    As String

    AwardTotVal = "1000"
    End Function

    I owe you one!!!

  4. #4
    Guest
    Hello Jim,

    ok here is the Function that you made:
    Code:
    Public Function CalcOSOValue _ 
    (WrkStrikePrc As Currency, _ 
    AnSPGrw As Double, AnLVLTGrw As Double, _ 
    AvgStockPrc As Currency, WrkOutNbrOfOSO As Long, AwardTotVal As Currency) _ 
    As String 
    
    AwardTotVal = "1000" 
    End Function
    Now the reason it's not returning the value is because your not telling VB to return anything.

    Try This:

    Code:
    Public Function CalcOSOValue _ 
    (WrkStrikePrc As Currency, _ 
    AnSPGrw As Double, AnLVLTGrw As Double, _ 
    AvgStockPrc As Currency, WrkOutNbrOfOSO As Long, AwardTotVal As Currency) _ 
    As String 
     
     ' Convert it to a string and return the value
     CalcOSOValue = Cstr(WrkStrikePrc * AnSPGrw * WrkOutNbrOfOSO * AwardTotVal)
    
    End Function
    That will return the value of all that multiplication. The part of the code that I use the Function Name = Value is how VB knows to return that value.

    Hope this helps

    Best

    [Edited by RvA on 05-06-2000 at 04:04 PM]

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Location
    Muscatine, Iowa, USA
    Posts
    18

    Dah!

    Hi Randy,
    I must of missed that chapter. It works like a charm
    Bye,
    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width