|
-
Nov 7th, 2000, 10:15 AM
#1
Thread Starter
Lively Member
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?
-
Nov 7th, 2000, 10:34 AM
#2
Lively Member
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.
-
Nov 7th, 2000, 10:49 AM
#3
Thread Starter
Lively Member
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
-
Nov 7th, 2000, 10:49 AM
#4
Fanatic Member
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...
-
Nov 7th, 2000, 10:52 AM
#5
Thread Starter
Lively Member
Perhaps you could make the procedures methods of an object and then use CallByName?
How could I do that?
-
Nov 7th, 2000, 11:01 AM
#6
Fanatic Member
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.
-
Nov 7th, 2000, 11:14 AM
#7
Thread Starter
Lively Member
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
-
Nov 7th, 2000, 12:01 PM
#8
Fanatic Member
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.
-
Nov 7th, 2000, 12:23 PM
#9
Hyperactive Member
Maybe use the Eval() function. Not sure if it supports UDFs.
-
Apr 8th, 2001, 09:32 PM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|