• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Using the ByRef param in a function - MAX POINTS

I am performing maintence on an application. I would like to avoid having to write another function that is performing a similar task, and really change as little code as possible (this is one of those "held together in it's own chaos" type of applications).

What i need to do it use the paygrade parameter after calling the function.
How can i do this?

When the function is being called an empty string is being passing as the paygrade, and you can see where paygrade is getting set at the forth line from the bottom of the function.
I think this should be a quick/easy answer. I just can't think of the syntax to use that parameter.
I need to do analysis on the paygrade after calling the function without changing the return value that is being set (0, 965, 964, etc)

Public Function getGradeRate(ByVal grade As String, ByRef paygrade As String) As Long
', ByVal isOfficer As Boolean

   If Not doInitializeDB2 Then
        'error in Class_Initialize
        getGradeRate = 99
        Exit Function
    End If

    Dim rate As String
    rate = grade
    'create parameters
    Dim cmdParams(1) As Parameter
    Set cmdParams(0) = createInputParameter("gradeRate", adChar, 5)
    cmdParams(0) = UCase(rate)
    'retrieve data
    Dim oRsGradeRate As ADODB.Recordset
    Set oRsGradeRate = oDatabase.getData("sGradeRate", cmdParams) 'select_grade_rate
    If oRsGradeRate Is Nothing Then
        'failed to retrieve the RS
        sErrorMessage = "Failed to retrieve grade rate." & vbCrLf & oDatabase.dbError.Description
        getGradeRate = 964
        Exit Function
    End If
    If oRsGradeRate.EOF Then
        'failed to find grade rate
        sErrorMessage = "Unable to find grade rate in the TRDB."
        getGradeRate = 965
        Exit Function
    End If
    'destroy command parameter objects created
    Dim i As Integer
    For i = UBound(cmdParams) To LBound(cmdParams) Step -1
       Set cmdParams(i) = Nothing
    Next i
    paygrade = oRsGradeRate("grade_description")
    Set oRsGradeRate = Nothing
    getGradeRate = 0

End Function 'getGradeRate
  • 5
  • 3
1 Solution
at the end of the function on the last line before End Function couldnt you do this :

getGradeRate = paygrade, but then that would always assign or return the value of paygrade to the getGradeRate function , is that what you mean ?
amandalynnAuthor Commented:
no, not necessarily...
Because there is a lot of already existing code that is looking for 0 as the value of getGradeRate to know that the function ran successfully.  So the function could run successfully, and not have the value set to zero if it's set to the paygrade.

so i'm hoping to get and use that paygrade value without having to set getGradeRate to the paygrade value.

is that possible?
Make a public variable outside of the function and set that variable to paygrade ?

and then use that variable when you need to which will be equal to the paygrade
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Dim strGrade

you function here (your parameters here)

all your code

strGrade = paygrade

end function

msgbox strGrade

or however you want to use paygrade which will be strGrade because you are assigning the value of paygrade to the variable strGrade

If that makes sense ?
amandalynnAuthor Commented:
That is a possiblity,
but i'd rather not if there is a possible way to use that byRef param straight from the function.
such as

Dim paygrade as string
paygrade = getGradeRate(strValue, strEmpty).paygrade
(or whatever the syntax is.. that obviously isn't it)
how would you access it out side of the function since the byref paramname is to do with just that function ?

maybe im missing something ....
Mike TomlinsonMiddle School Assistant TeacherCommented:
You just ~use~ it after the function...

For example:

    Dim grade As String
    Dim paygrade As String
    Dim gradeRate As Long
    gradeRate = getGradeRate(grade, paygrade)
    Debug.Print paygrade

Since you have passed "paygrage" ByRef, any changes in the sub are reflected in the original variable.

All you need to do is use that variable like you normally would and it will reflect the changes made in the getGradeRate() function.

I think you are interested in getting that value without using the return from the function?

If so, then just use:

    Dim paygrade As String
    getGradeRate "", paygrade
    Debug.Print paygrade
amandalynnAuthor Commented:
Thanks for your promt reply and help gecko.

However it's Idle_mind's answer that was what i was looking for.

It was almost too easy.. :-) lol..

thanks for your help!
no problem :) just glad you got it sorted out and was just trying to help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now