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

Using the ByRef param in a function - MAX POINTS

Hi,
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")
 
    oRsGradeRate.Close
    Set oRsGradeRate = Nothing
 
    getGradeRate = 0

End Function 'getGradeRate
0
amandalynn
Asked:
amandalynn
  • 5
  • 3
1 Solution
 
gecko_au2003Commented:
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 ?
0
 
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?
0
 
gecko_au2003Commented:
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
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
gecko_au2003Commented:
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 ?
0
 
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)
0
 
gecko_au2003Commented:
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 ....
0
 
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
0
 
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!
0
 
gecko_au2003Commented:
no problem :) just glad you got it sorted out and was just trying to help
0
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

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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