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
Solved

Using the ByRef param in a function - MAX POINTS

Posted on 2006-11-13
9
209 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
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 85

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

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.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

840 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