dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Should I Creat a BAS Module or Function or...

  1. #1
    Join Date
    Sep 2004
    Posts
    45

    Should I Creat a BAS Module or Function or...

    I have the same four option buttons on each of four forms. To clear the option selections;
    Opt1 = false
    Opt2 = false
    Opt3 = false
    Opt3 = false
    I'd like to write and call a function or bas module instead of inserting the above in each form. Have searched my books and can't figure out what or how. I suspect a module is appropriate but don't know how to write it for this. Every example I find creates types, declarations, enum, etc. and solves complex events. Is it possible to create a function or module to do the job?
    Last edited by wisgro; 10-02-2010 at 03:46 PM. Reason: typed the wrong word

  2. #2
    Join Date
    Mar 2009
    Location
    Italy - Breganze (VI)
    Posts
    120
    make a global Sub routine like this below (put it into a module BAS):

    Code:
    Public Sub ClearOptionButtons (ByRef oForm As Form)
    
        On Error Resume Next
        objForm.Opt1.Value = False
        objForm.Opt2.Value = False
        objForm.Opt3.Value = False
        objForm.Opt3.Value = False
    
    End Sub
    
    'To call this routine :
    
    Call ClearOptionButtons(Me)


  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Quote Originally Posted by wisgro
    Is it possible to create a function or module to do the job?
    What you want is a Sub routine within a module. It isn't an either or proposition.
    Code:
    Public Sub ClearOptionButtons(pForm As Form)
    Dim ctrl As Control
        For Each ctrl In pForm
            If TypeOf ctrl Is OptionButton Then
               ctrl.Value = False
            End If
        Next
    End Sub
    
    'and on all the forms
    Private Sub Command1_Click()
    ClearOptionButtons Me
    End Sub

  4. #4
    Join Date
    Sep 2004
    Posts
    45

    Should I Creat a BAS Module or Function or...

    Thanks Folks.

  5. #5
    Join Date
    Sep 2004
    Posts
    45

    Clear Option Buttons

    Hack, I pasted your code to clear option buttons into the form and inserted ClearOptionButtons Me in the form's "Clear" button Sub. The Clear button works however it disables my Reset button and Exit Button. Clicking the Exit button causes no action. Clicking Reset the first time caused an error message that I didn't write down. So I ran the program again, clicked Reset and the program froze.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Ok, so that means you have more than just those options buttons on a form. In that case, we need to segregate them from the other options buttons.

    To do that, we are going to use their "Tag" property.

    For the buttons whose value you want to clear with the sub routine place the word "Clear" (without the quote marks) in the tag property for each button.

    Once that is done, go back to your sub routine and use this for the code:
    Code:
    Public Sub ClearOptionButtons(pForm As Form)
    Dim ctrl As Control
        For Each ctrl In pForm
            If TypeOf ctrl Is OptionButton Then
               If ctrl.Tag = "Clear" Then
                  ctrl.Value = False
               End If
            End If
        Next
    End Sub
    Now the sub routine will look for all option buttons on a form, as it did before, but only reset those buttons that have the word "Clear" in its Tag property.

Similar Threads

  1. String Array in C++
    By saruman in forum C++
    Replies: 13
    Last Post: 11-19-2007, 04:51 PM
  2. string array in c++
    By emeric in forum C++
    Replies: 11
    Last Post: 07-16-2007, 09:36 PM
  3. Replies: 8
    Last Post: 03-08-2003, 07:25 PM
  4. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 03:45 PM
  5. I am helpless - Edit Info form
    By Dan in forum VB Classic
    Replies: 0
    Last Post: 03-17-2000, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center