dcsimg
Results 1 to 12 of 12

Thread: Passing many controls parameter to procedure

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    697

    Passing many controls parameter to procedure

    Hi

    I Would like to pass one or more controls to a procedure , How can I Do, I tried to use ParamArray , but no work



    I would like something as:
    Code:
       My_procedure (myWhere As String, myBindVals As String, txttetbox1 as textbox, txttexbox2 as textbox....)
    
      'or  only textbox (or combobox....etc)
        My_procedure (myWhere As String, myBindVals As String, txttetbox1 as textbox)

  2. #2
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,339

    Re: Passing many controls parameter to procedure

    And what's the problem?
    The code that you wrote should work...

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: Passing many controls parameter to procedure

    How did a ParamArray not work? Other options can be to add the controls to a collection, then pass the collection. In either case, you would iterate through the passed parameter (whether a pararmarray or collection), i.e.,
    Code:
    For x = 1 To passedCollection.Count
    
    or 
    
    For x = 0 To Ubound(paramArrayVariable)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    697

    Re: Passing many controls parameter to procedure

    Quote Originally Posted by Eduardo- View Post
    And what's the problem?
    The code that you wrote should work...
    my problem is populate control, but when return to form the control is empty

    Code:
            ' Populate the control with the obtained value.
          For i = 0 To UBound(parametervalues)
            parametervalues(i) = ldLOVRetVal(intLOVId, i + 1)
           ' txtCfop_code = ldLOVRetVal(intLOVId, 1)
          ' txtCfopdescri = ldLOVRetVal(intLOVId, 2)
            
         Next
        '------------------
       '  How can I put setfocus in firstcontrol  
        ' txtCfop_code.SetFocus

  5. #5
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,339

    Re: Passing many controls parameter to procedure

    I don't know. If you can post a sample project to see the problem that could help.

  6. #6

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    697

    Re: Passing many controls parameter to procedure

    Quote Originally Posted by Eduardo- View Post
    I don't know. If you can post a sample project to see the problem that could help.
    Example
    Attached Files Attached Files

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: Passing many controls parameter to procedure

    You don't return a control. You pass a control, the routine does whatever it needs to with the control. Simple example

    Code:
    Private Sub Command1_Click()
        PopulateControls txtCfop_code, Command1
    End Sub
    
    
    Public Sub PopulateControls(ParamArray Ctrls())
    
        Dim c As Long
        
        For c = 0 To UBound(Ctrls)
            If TypeName(Ctrls(c)) = "TextBox" Then
            
                Select Case Ctrls(c).Name
                
                Case "txtCfop_code"
                    ' do whatever is needed
                    Ctrls(c).Text = "Hello World"
                    
                ' other Cases for other textbox controls
                
                End Select
                
            ElseIf TypeName(Ctrls(c)) = "CommandButton" Then
                ' setup your case statements
            Else
                ' other ElseIf statements as needed
            End If
            
            If c = 0 Then
                Ctrls(c).SetFocus  ' set focus to 1st control passed in paramarray?
            End If
        Next
    
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,014

    Re: Passing many controls parameter to procedure

    Hmmm, yeah, I looked at it too.

    I'm pretty sure you can't actually return the values passed in a ParamArray. It'd be very tricky and very non-standard to do that.

    However, you can certainly return some set of controls in an Object array, or a Collection, or even a Variant array. And you could pass in this array (or Collection), fill it, and then it'd be passed back filled.

    But it also seems that we're confusing actual controls with the properties of those controls. We can certainly pass in a reference to some control (or even set of controls, possibly with ParamArray), and then change whatever properties we like ... and they'd still be changed when we returned.

    Mutley, if you could outline a bit more about what you're trying to do, I think we could probably come up with better solutions.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  9. #9
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,339

    Re: Passing many controls parameter to procedure

    Quote Originally Posted by mutley View Post
    Example
    Code:
    Private Sub CMDFILL_Click()
       example_fill TXTCODE, TXTDECRI
    End Sub
    
    Private Sub example_fill(ParamArray parametervalues() As Variant)
       Dim txt_examples(4) As String
    
        txt_examples(0) = "MYCODE"
        txt_examples(1) = "MYDESSCRIPTION"
        txt_examples(2) = "LONDON"
        txt_examples(3) = "PARIS"
        txt_examples(4) = "NEW YORK"
        
        
    
         For I = 0 To UBound(parametervalues)
               parametervalues(I).Text = txt_examples(I)
         Next
        'I would like the controls with  MYCODE  and  MYDESSCRIPTION
    
    End Sub
    Or:

    Code:
    Private Sub CMDFILL_Click()
       example_fill TXTCODE, TXTDECRI
    End Sub
    
    Private Sub example_fill(ParamArray parametervalues() As Variant)
       Dim txt_examples(4) As String
        Dim iCtl As Control
        
        txt_examples(0) = "MYCODE"
        txt_examples(1) = "MYDESSCRIPTION"
        txt_examples(2) = "LONDON"
        txt_examples(3) = "PARIS"
        txt_examples(4) = "NEW YORK"
        
        
    
         For I = 0 To UBound(parametervalues)
               Set iCtl = parametervalues(I)
               iCtl = txt_examples(I)
         Next
        'I would like the controls with  MYCODE  and  MYDESSCRIPTION
    
    End Sub
    Last edited by Eduardo-; Jan 14th, 2019 at 02:04 PM.

  10. #10

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    697

    Re: Passing many controls parameter to procedure

    Quote Originally Posted by Eduardo- View Post
    Code:
    Private Sub CMDFILL_Click()
       example_fill TXTCODE, TXTDECRI
    End Sub
    
    Private Sub example_fill(ParamArray parametervalues() As Variant)
       Dim txt_examples(4) As String
    
        txt_examples(0) = "MYCODE"
        txt_examples(1) = "MYDESSCRIPTION"
        txt_examples(2) = "LONDON"
        txt_examples(3) = "PARIS"
        txt_examples(4) = "NEW YORK"
        
        
    
         For I = 0 To UBound(parametervalues)
               parametervalues(I).Text = txt_examples(I)
         Next
        'I would like the controls with  MYCODE  and  MYDESSCRIPTION
    
    End Sub
    Or:

    Code:
    Private Sub CMDFILL_Click()
       example_fill TXTCODE, TXTDECRI
    End Sub
    
    Private Sub example_fill(ParamArray parametervalues() As Variant)
       Dim txt_examples(4) As String
        Dim iCtl As Control
        
        txt_examples(0) = "MYCODE"
        txt_examples(1) = "MYDESSCRIPTION"
        txt_examples(2) = "LONDON"
        txt_examples(3) = "PARIS"
        txt_examples(4) = "NEW YORK"
        
        
    
         For I = 0 To UBound(parametervalues)
               Set iCtl = parametervalues(I)
               iCtl = txt_examples(I)
         Next
        'I would like the controls with  MYCODE  and  MYDESSCRIPTION
    
    End Sub
    Very very good
    Is possible call an event ?

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: Passing many controls parameter to procedure

    Quote Originally Posted by mutley View Post
    Very very good
    Is possible call an event ?
    iCtl.SetFocus
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,339

    Re: Passing many controls parameter to procedure

    What do you mean to call an event?
    What would you like to do, specifically?

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width