CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2007
    Posts
    60

    Smile 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!

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    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
    -

  3. #3
    Join Date
    Dec 2007
    Posts
    60

    Re: passing control names

    Can you give a more specific detail? It is something I am not used to at all.

  4. #4
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792

    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...

  5. #5
    Join Date
    Dec 2006
    Location
    Pune, India.
    Posts
    579

    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!

  6. #6
    Join Date
    Dec 2007
    Posts
    60

    Re: passing control names

    Thnaks, but none of these hints seem to work..any thoughts? The last one use "ME" is this correct?

  7. #7
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    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
    -

  8. #8
    Join Date
    Dec 2006
    Location
    Pune, India.
    Posts
    579

    Re: passing control names

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured