Visual Basic 6 question

Discussion in 'NZ Computing' started by Stephen Williams, Jul 26, 2004.

  1. Hey i've got bunch of arrays of tick boxes, each array contains somewhere
    between 5 and 20.

    What I want to do is write a function that returns the captions of every
    ticked tick box in an array as a string.

    I want to be able to pass to the function the array name, and the lower and
    upper limits of the array. But I have no idea how to pass the control name
    (array name).

    I can do it by writing a prodecure for every single array, but there are
    hundreds of them! It must be possible using a single function or procedure.
    I came up with this, it needs finishing.

    Private Function ReturnString(ctrlName As ***WHAT?????**** , intLow As
    Integer, intHigh As Integer) As String
    intFlag = 0
    strField = ""
    For intCount = intLow To intHigh
    If ctrlName(intCount).Value = 1 Then
    If intFlag = 0 Then
    strField = ctrlName(intCount).Caption
    intFlag = 1
    Else
    strField = strField & ", " & ctrlName(intCount).Caption
    End If
    End If
    Next intCount
    ReturnString = strField
    End Function

    If anyone can help, or point me towards a good VB newsgroup I would be
    grateful :)

    Cheers,
    Steve
     
    Stephen Williams, Jul 26, 2004
    #1
    1. Advertising

  2. Stephen Williams

    Mark Guest

    You could try <just off the top of my head here> late binding....

    Private Function ReturnString(ctrlName As Variant, intLow As Integer,
    intHigh As Integer) As String

    --
    ----------------------------------------------------------------
    -**-
    www.byteboss.com : EZ website builder
    -**-
    Replace the Z with the e to reply
    ----------------------------------------------------------------

    "Stephen Williams" <> wrote in message
    news:ll0Nc.348$...
    > Hey i've got bunch of arrays of tick boxes, each array contains somewhere
    > between 5 and 20.
    >
    > What I want to do is write a function that returns the captions of every
    > ticked tick box in an array as a string.
    >
    > I want to be able to pass to the function the array name, and the lower

    and
    > upper limits of the array. But I have no idea how to pass the control name
    > (array name).
    >
    > I can do it by writing a prodecure for every single array, but there are
    > hundreds of them! It must be possible using a single function or

    procedure.
    > I came up with this, it needs finishing.
    >
    > Private Function ReturnString(ctrlName As ***WHAT?????**** , intLow As
    > Integer, intHigh As Integer) As String
    > intFlag = 0
    > strField = ""
    > For intCount = intLow To intHigh
    > If ctrlName(intCount).Value = 1 Then
    > If intFlag = 0 Then
    > strField = ctrlName(intCount).Caption
    > intFlag = 1
    > Else
    > strField = strField & ", " & ctrlName(intCount).Caption
    > End If
    > End If
    > Next intCount
    > ReturnString = strField
    > End Function
    >
    > If anyone can help, or point me towards a good VB newsgroup I would be
    > grateful :)
    >
    > Cheers,
    > Steve
    >
    >
     
    Mark, Jul 26, 2004
    #2
    1. Advertising

  3. "Mark" <> wrote in message
    news:ce24v9$d6j$...
    > You could try <just off the top of my head here> late binding....
    >
    > Private Function ReturnString(ctrlName As Variant, intLow As Integer,
    > intHigh As Integer) As String
    >


    Thanks, but that still gives the same problem (
     
    Stephen Williams, Jul 26, 2004
    #3
  4. Stephen Williams

    Armpit Guest

    On Mon, 26 Jul 2004 17:08:21 +1200, Stephen Williams wrote:

    > Hey i've got bunch of arrays of tick boxes, each array contains somewhere
    > between 5 and 20.
    >


    Pass in the form as a parameter to the function.
    You can then loop through the controls on the form.

    As part of the loop, you could either check by the control name, or make
    use of the TAG property to indicate what should happen.

    Reply if you need a better example, but its really straightforward.
     
    Armpit, Jul 26, 2004
    #4
  5. Stephen Williams

    Ray Greene Guest

    Do you have checkboxes on multiple forms? If you only have one form have a
    look at this code.

    Private Sub PrintNames()

    Dim objCtrl As Control

    For Each objCtrl In Me.Controls
    If TypeOf objCtrl Is CheckBox Then
    Debug.Print objCtrl.Name
    End If
    Next

    End Sub

    If more than one form then try this.

    Private Sub PrintNames()

    Dim objCtrl As Control
    Dim objFrm As Form

    For Each objFrm In Forms
    For Each objCtrl In objFrm.Controls
    If TypeOf objCtrl Is CheckBox Then
    Debug.Print objCtrl.Name
    End If
    Next
    Next

    End Sub


    Google Groups is good for finding relevant stuff on newsgroups.
    http://vbnet.mvps.org/index.html is an excellent site for VB code.

    Ray Greene.
     
    Ray Greene, Jul 26, 2004
    #5
  6. Thank you everyone who answered. Turns out I have to declare ctrlName as an
    Object.

    Probably should have learned that in VB101 lol :)

    Steve
     
    Stephen Williams, Jul 26, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jaime
    Replies:
    2
    Views:
    561
    Jaime
    Sep 20, 2003
  2. ¢harlie
    Replies:
    0
    Views:
    682
    ¢harlie
    Dec 26, 2003
  3. Jimmy Dean
    Replies:
    3
    Views:
    1,109
    Duane Arnold
    Jul 25, 2005
  4. TJ
    Replies:
    1
    Views:
    355
    =-Zero@HK-=ASP.Net / VB
    Sep 23, 2005
  5. Celf Destruk
    Replies:
    1
    Views:
    427
    =-Zero@HK-=ASP.Net / VB
    Sep 23, 2005
Loading...

Share This Page