What does this function do?

BJS

Registered User.
Local time
Today, 10:39
Joined
Aug 29, 2002
Messages
109
I have found a function in an inherited database I am working on. I don't understand what it does. Can someone explain:

This is the function:

Code:
Public Function GetArgs(strArgs As Variant, intNumber As Integer) As String

    'Arguments must be separated by a ^
    
    Dim intCount  As Integer
    Dim intOldPosition As Integer
    Dim intPosition As Integer
    
    intCount = 1
    intPosition = 1
    
    If IsNull(strArgs) Then
        GetArgs = ""
        Exit Function
    End If
    
    While intCount <= intNumber
        
        If intOldPosition > intPosition Then
            err.Raise vbObjectError + 1000, , "Argument " & intNumber & " Not Found in OpenArgs"
        Else
            intOldPosition = intPosition
        End If
        
        intPosition = InStr(intOldPosition, strArgs, "^") + 1
        intCount = intCount + 1
        
    Wend
    
    If intPosition < intOldPosition Then 'end of arguments
        intPosition = Len(strArgs) + 2
    End If
    
    If intPosition = 1 Then
        'One or no arguments
        GetArgs = Mid(strArgs, intOldPosition, Len(strArgs))
    Else
        GetArgs = Mid(strArgs, intOldPosition, (intPosition - intOldPosition) - 1)
    End If
End Function

This is how it is used:
Code:
Me.txtAmount.Value = modGetArgs.GetArgs(Me.OpenArgs, 2)

Thanks,
BJS
 
From the code you provided, it seems that this function is intended to parse individual elements of a form's OpenArgs property. Likewise, elsewhere in the database, there must be a function which opens the form and sets the OpenArgs property with a list of elements as a single string argument, with the ^ character as a delimiter.

Going with your example, let's say that the form was opened with the following OpenArgs text:
MyItem^100.37^US^0

The first element is MyItem, the second is 100.37, the third is US, and the fourth is 0.

Consequently, when the following line of code is executed:
Code:
Me.txtAmount.Value = modGetArgs.GetArgs(Me.OpenArgs, 2)
...the textbox txtAmount is set to the second element in the OpenArgs property, in this case, 100.37.

I hope I haven't thoroughly confused you.
 
Thank you for that explanation, ByteMyzer!
You are right...there is a function which opens the form and sets the openargs property. I have never seen this before.

You have given a very good explanation that will give me a good start to understanding how this database operates with respect to this code.

THANK YOU VERY MUCH! :)

I might be back with more questions after reviewing all the other code that is similar to this.

BJS
 

Users who are viewing this thread

Back
Top Bottom