+ Reply to Thread
Results 1 to 6 of 6

Counting textboxes

  1. #1
    franzklammer
    Guest

    Counting textboxes

    Hello! I got this piece of code from someone who helped me with a function
    that counts the number of textboxes in a user form. However I do not not what
    what 'oUF' means and how to use the function. I have never used functions
    before so I do not know how to call it. I tried useing 'Call countTextboxes'
    in another Sub but I suppose that you need something else...

    Public Function countTextboxes(oUF As UserForm) As Long
    Dim iCtrl As Long
    For iCtrl = 0 To oUF.Controls.Count - 1
    If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    countTextboxes = countTextboxes + 1
    End If
    Next iCtrl
    End Function

  2. #2
    Norman Jones
    Guest

    Re: Counting textboxes

    Hi Franz,

    oUF is simply an object variable for a userform.

    To demonstrate the use of your function, try:

    '=============>>
    Public Sub TestIt()
    Dim iCtr As Long

    iCtr = countTextboxes(UserForm1)

    MsgBox iCtr
    End Sub
    '<<=============

    ---
    Regards,
    Norman



    "franzklammer" <[email protected]> wrote in message
    news:[email protected]...
    > Hello! I got this piece of code from someone who helped me with a function
    > that counts the number of textboxes in a user form. However I do not not
    > what
    > what 'oUF' means and how to use the function. I have never used functions
    > before so I do not know how to call it. I tried useing 'Call
    > countTextboxes'
    > in another Sub but I suppose that you need something else...
    >
    > Public Function countTextboxes(oUF As UserForm) As Long
    > Dim iCtrl As Long
    > For iCtrl = 0 To oUF.Controls.Count - 1
    > If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    > countTextboxes = countTextboxes + 1
    > End If
    > Next iCtrl
    > End Function




  3. #3
    mooncrawler
    Guest

    Re: Counting textboxes


    The difference between a function and a subroutine is that a function always
    returns a value.
    Your function does not. I would do it a little different:

    Public Function countTextboxes( oUF As UserForm ) as Long
    Dim iCtrl As Long
    Dim i as integer
    For iCtrl = 0 To oUF.Controls.Count -1
    If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    i = i + 1
    End If
    Next iCtrl
    countTextboxes = i
    End Function


    From your form-macro, you call i.e.

    Dim x As Long
    x = countTextBoxes( Me )






    "franzklammer" <[email protected]> schreef in bericht
    news:[email protected]...
    > Hello! I got this piece of code from someone who helped me with a function
    > that counts the number of textboxes in a user form. However I do not not
    > what
    > what 'oUF' means and how to use the function. I have never used functions
    > before so I do not know how to call it. I tried useing 'Call
    > countTextboxes'
    > in another Sub but I suppose that you need something else...
    >
    > Public Function countTextboxes(oUF As UserForm) As Long
    > Dim iCtrl As Long
    > For iCtrl = 0 To oUF.Controls.Count - 1
    > If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    > countTextboxes = countTextboxes + 1
    > End If
    > Next iCtrl
    > End Function




  4. #4
    Bob Phillips
    Guest

    Re: Counting textboxes

    oUF is the userform that it is being called from. If that code is in the
    userform, it is not necessary, but if not, you can pass the Me object which
    refers to the container object (the userform)

    numCBs = countTextboxes(Me)

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "franzklammer" <[email protected]> wrote in message
    news:[email protected]...
    > Hello! I got this piece of code from someone who helped me with a function
    > that counts the number of textboxes in a user form. However I do not not

    what
    > what 'oUF' means and how to use the function. I have never used functions
    > before so I do not know how to call it. I tried useing 'Call

    countTextboxes'
    > in another Sub but I suppose that you need something else...
    >
    > Public Function countTextboxes(oUF As UserForm) As Long
    > Dim iCtrl As Long
    > For iCtrl = 0 To oUF.Controls.Count - 1
    > If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    > countTextboxes = countTextboxes + 1
    > End If
    > Next iCtrl
    > End Function




  5. #5
    Bob Phillips
    Guest

    Re: Counting textboxes

    You must be reading different code to me as the code I see increments
    countTextboxes which is the name of the function.

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "mooncrawler" <coffeecop[NOSPAM]@planet.nl> wrote in message
    news:[email protected]...
    >
    > The difference between a function and a subroutine is that a function

    always
    > returns a value.
    > Your function does not. I would do it a little different:
    >
    > Public Function countTextboxes( oUF As UserForm ) as Long
    > Dim iCtrl As Long
    > Dim i as integer
    > For iCtrl = 0 To oUF.Controls.Count -1
    > If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    > i = i + 1
    > End If
    > Next iCtrl
    > countTextboxes = i
    > End Function
    >
    >
    > From your form-macro, you call i.e.
    >
    > Dim x As Long
    > x = countTextBoxes( Me )
    >
    >
    >
    >
    >
    >
    > "franzklammer" <[email protected]> schreef in bericht
    > news:[email protected]...
    > > Hello! I got this piece of code from someone who helped me with a

    function
    > > that counts the number of textboxes in a user form. However I do not not
    > > what
    > > what 'oUF' means and how to use the function. I have never used

    functions
    > > before so I do not know how to call it. I tried useing 'Call
    > > countTextboxes'
    > > in another Sub but I suppose that you need something else...
    > >
    > > Public Function countTextboxes(oUF As UserForm) As Long
    > > Dim iCtrl As Long
    > > For iCtrl = 0 To oUF.Controls.Count - 1
    > > If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    > > countTextboxes = countTextboxes + 1
    > > End If
    > > Next iCtrl
    > > End Function

    >
    >




  6. #6
    Norman Jones
    Guest

    Re: Counting textboxes

    Hi Mooncrawler,

    > a function always returns a value.
    > Your function does not


    What then is the purpose of the function's code line:

    >> countTextboxes = countTextboxes + 1


    In any event, the funtion worked for me.

    ---
    Regards,
    Norman



    "mooncrawler" <coffeecop[NOSPAM]@planet.nl> wrote in message
    news:[email protected]...
    >
    > The difference between a function and a subroutine is that a function
    > always returns a value.
    > Your function does not. I would do it a little different:
    >
    > Public Function countTextboxes( oUF As UserForm ) as Long
    > Dim iCtrl As Long
    > Dim i as integer
    > For iCtrl = 0 To oUF.Controls.Count -1
    > If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    > i = i + 1
    > End If
    > Next iCtrl
    > countTextboxes = i
    > End Function
    >
    >
    > From your form-macro, you call i.e.
    >
    > Dim x As Long
    > x = countTextBoxes( Me )
    >
    >
    >
    >
    >
    >
    > "franzklammer" <[email protected]> schreef in bericht
    > news:[email protected]...
    >> Hello! I got this piece of code from someone who helped me with a
    >> function
    >> that counts the number of textboxes in a user form. However I do not not
    >> what
    >> what 'oUF' means and how to use the function. I have never used functions
    >> before so I do not know how to call it. I tried useing 'Call
    >> countTextboxes'
    >> in another Sub but I suppose that you need something else...
    >>
    >> Public Function countTextboxes(oUF As UserForm) As Long
    >> Dim iCtrl As Long
    >> For iCtrl = 0 To oUF.Controls.Count - 1
    >> If TypeName(oUF.Controls(iCtrl)) = "TextBox" Then
    >> countTextboxes = countTextboxes + 1
    >> End If
    >> Next iCtrl
    >> End Function

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1