Solved

Using the ByRef param in a function - MAX POINTS

Posted on 2006-11-13
9
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 17932012
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
ID: 17932051
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
ID: 17932124
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 23

Expert Comment

by:gecko_au2003
ID: 17932164
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
 

Author Comment

by:amandalynn
ID: 17932174
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
ID: 17932200
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 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17932440
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
ID: 17932506
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
ID: 17932551
no problem :) just glad you got it sorted out and was just trying to help
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

691 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