Results 1 to 10 of 10

Thread: Calling a proceedure

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    71
    I have a database that contains info on what code to run in a particular instance. The code that I have looks to see what file is in a directory. Once it sees a file it trys to match it up against what is in the database. If it finds a file who's name exists in the database, it needs to call a proceedure who's name relates to the file name in the db.

    Ive got two fields in the table.
    FileName and Code

    I assign strFileName to = rs!FileName and strCode to = rs!Code.

    Then I want to do this:

    If Dir(strFileName, vbNormal) = "" Then
    GoTo CONT
    Else:
    Call strFileCode
    End If

    How should I dim strFileCode. I guess it shouldn't be a string as VB keeps telling me that it looks for a proceedure there. Any ideas?

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96
    Call is used to call a procedure - that's why VB is looking for one.

    If I understand you right you should want to pass the name of the file to the procedure...something like

    call PROC( strFileCode )

    and your procedure declaration will look something like

    private sub PROC ( filename as string )

    This tells the procedure that a string will be passed to it.

    Hope this helps.

    H.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    71

    I want to actually pass the name of the proceedure to call

    I want to actually pass the name of the proceedure to call. Unfortunately, when I try to pass the proceedure name as a string, VB says that its looking for a proceedure not a string here. I need to dim strCode as some kind of proceedure so that it will run. I am not trying to pass a variable to a proceedure, just actually trying to pass a proceedure name. Any ideas?

    It would look something like

    Dim strCode as procedure OR SOMETHING OF THE LIKE

    Call strCode

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    No, I don't think it is that. I think that strFileCode represents the name of a procedure.

    Perhaps you could make the procedures methods of an object and then use CallByName?

    Cheers,

    Paul.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    71
    Perhaps you could make the procedures methods of an object and then use CallByName?

    How could I do that?

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Code:
    CallByName Me, strFileCode, VbMethod
    The syntax:
    Code:
    CallByName Object As Object, ProcName As String, _
        CallType As vbCallType, Args() As Variant
    Hope this helps out. If you are using the VB IDE, just typing callbyname and when you hit space, the syntax appears in a tooltip (if you have this option enabled, highly recommended that you do .

    The Method/Property _MUST_ be a public one.
    -Excalibur

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    71

    Angry Still not working

    Excalibur,

    Thanks for your help. Unfortunately I am still struggling. I entered the "CallByName Me, strFileCode, VbMethod" line into my code. It says that it needs to be = to something. I tried saying x=CallByName Me, strFileCode, VbMethod
    but no dice. Object doesn't support this property or method. Any advice?

    Excelsior,
    WJM

  8. #8
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Firstly, you need to make sure you're referencing the correct Object (your form, a class module, etc.) secondly, that method (sub or function) _MUST_ be declared as public. If you are referencing a property, you need to use vbGet or vbLet and if that property is referencing an object, vbSet.

    Also, said procedure _MUST_ exist in the object you are referencing.

    the ARGS() list is just the standard arguements that the procedure would use for data.

    Here is an example:
    Code:
    Dim Temp As Variant
    
    If Dir(strFileName, vbNormal) = "" Then 
        GoTo CONT 
        Else
        Temp = CallByName Form1, strFileCode, vbMethod, strFileName
    End If 
    
    'If strFileCode contains, say CheckDir
    Public Function CheckDir(fName As String) As Boolean
        If Dir(App.Path & "\fName") <> "" Then
            CheckDir = True
            Else
            CheckDir = False
        End If
    End Function
    Hope this helps clear some things up.
    -Excalibur

  9. #9
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Maybe use the Eval() function. Not sure if it supports UDFs.

  10. #10
    ExplosiveNewt
    Guest
    Try This

    '------------------------Start Copy---------------------
    On Error Resume Next
    CallByName Me, strFileCode, VbMethod
    If Err.Number = 438 then
    'If You Are here you tried to call a Method that
    'doesn't Exist, Ingore it or Throw up a Msg box,
    'LogIt or something
    err.Clear
    ElseIf Err.Number > 0 then GoTo ErrorHand
    End If
    On Error GoTo ErrorHand
    '------------------------End Copy----------------------

    Then at the end of the same sub put

    '------------------------Start Copy---------------------
    Exit Sub
    ErrorHand:
    'If you are here you have some type of Error Handeler
    ' Such as a MSGBOX
    Err.Clear
    End Sub
    '------------------------End Copy-----------------------

    Indy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width