Solved

Using the ByRef param in a function - MAX POINTS

Posted on 2006-11-13
9
198 Views
Last Modified: 2010-04-30
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
Comment
Question by:amandalynn
  • 5
  • 3
9 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
Comment Utility
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
 

Author Comment

by:amandalynn
Comment Utility
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
 
LVL 23

Expert Comment

by:gecko_au2003
Comment Utility
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
 
LVL 23

Expert Comment

by:gecko_au2003
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:amandalynn
Comment Utility
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
 
LVL 23

Expert Comment

by:gecko_au2003
Comment Utility
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
 

Author Comment

by:amandalynn
Comment Utility
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
 
LVL 23

Expert Comment

by:gecko_au2003
Comment Utility
no problem :) just glad you got it sorted out and was just trying to help
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now