-
February 18th, 2008, 11:26 AM
#1
passing control names
hello
I have to do the following logic in many places using different variables & control names, but essentially doing the same logical operations. I am trying to write a sub that can be called to do the work so I don't have to replicate this over & over
if cmdStart(0).value=CmdStop(4).value then
Call VscPot2_Change(0)
CmdStop(4).value =cmdStart(0).value+1
else
CmdStop(4).value =0
end if
I need a sub such as CHECKIT(Parm1,Parm2,Change1) where the parameters in this example are: cmdStart(0).value, CmdStop(4).value , Call VscPot2_Change(0)
I think this should be doable---but how do you pass & act on these "Names"? I'm not sure what these "Names" are called in Vb lingo, so its hard to do a search!
-
February 18th, 2008, 05:19 PM
#2
Re: passing control names
Just do something like
Code:
Sub CheckIt (Param1 as Control, Param2 As Control)
Marketing our skills - please participate in the survey and share your insights
-
-
February 18th, 2008, 07:56 PM
#3
Re: passing control names
Can you give a more specific detail? It is something I am not used to at all.
-
February 18th, 2008, 08:45 PM
#4
Re: passing control names
Using Aio's code above, you would probably do something like this (not sure if it will work though.) I've done something similar in the past, but it was quite a few years ago and I can't find the code.
Code:
Public Sub CheckIt (ByRef Param1 as Control, ByRef Param2 As Control, ByRef Param3 as Control)
dim ctlName as string
dim procName as string
ctlName = Param3.Name
procName = ctlName & "_Change(0)"
call procName
End Sub
Then you would just call CheckIt and pass in the control names.
Be nice to Harley riders...
-
February 19th, 2008, 01:39 AM
#5
Re: passing control names
Here is the working sample for you:
Code:
Private Sub Form_Load()
CheckIt Command1, Command2, "Text1_Change"
End Sub
Public Sub CheckIt(Param1 As Control, Param2 As Control, ProcToCall As String)
If Param1.Value = Param2.Value Then
CallByName Me, ProcToCall, VbMethod
Param2.Value = Param1.Value + 1
Else
Param2.Value = 0
End If
End Sub
Public Sub Text1_Change()
MsgBox "This block is called using CallByName"
End Sub
But I didn't understand what are you going to achieve with checking and incrementing values of command button!
-
February 20th, 2008, 09:50 AM
#6
Re: passing control names
Thnaks, but none of these hints seem to work..any thoughts? The last one use "ME" is this correct?
-
February 20th, 2008, 10:40 AM
#7
Re: passing control names
ok, please try to post that part of your codes and let's see. maybe me misunderstood the purpose of your codes.
Marketing our skills - please participate in the survey and share your insights
-
-
February 21st, 2008, 05:57 AM
#8
Re: passing control names
Originally Posted by normnov
Thnaks, but none of these hints seem to work..any thoughts? The last one use "ME" is this correct?
'Me' is used to refer to current form which contains the method.
CallByName requires the object name and its method to call. As I have written the sub as public, I have used it as member of 'Me'.
And I think this is what you are looking for!
Does this make any sense?
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
|