Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 547209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:56:57+00:00 2026-05-13T10:56:57+00:00

Is it possible to convert your form to a self contained class module in

  • 0

Is it possible to convert your form to a self contained class module in vb6?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:56:57+00:00Added an answer on May 13, 2026 at 10:56 am

    One simple way to do this is to create a new ActiveX DLL project in the VB6 IDE, and then add a new Form to the project. You also need a class, but you can just rename the default “Class1” that gets added to the project.

    Create the form as you normally would, and then write a class that has a function to display the form, and optionally return information back to the caller (either via a return value, events, or public properties on the class). Once you compile the DLL, other projects can use your form by adding a reference to your DLL and instantiating the public class.

    Below is a very simple example that demonstrates how you might create a generic login dialog that you can then re-use in multiple projects. The login dialog simply displays a login screen with username and password fields, and OK and Cancel buttons. A public class, LoginDialog, can be used by other projects to actually display the login form and to retrieve data from it (the actual username and password entered by the user, and whether or not the user cancelled the dialog). The public class is a wrapper around the functionality provided by the form.

    Please note this is just a quick example to demonstrate the concept

    • Create a new Form and add it to the ActiveX DLL project. Rename it frmLogin and add the following controls to it:

      • A Textbox named txtUsername
      • A Textbox named txtPassword. Set the PasswordChar property to “*” (asterisk)
      • A CommandButton named cmdOK with the caption set to “OK”
      • A CommandButton named cmdCancel with the caption set to “Cancel”

    • Then add the following code to frmLogin.frm:

    'frmLogin.frm'
    
    Public Cancelled As Boolean 'Set if the user clicks Cancel or closes the form'
    
    Private Sub cmdCancel_Click()
       'User cancelled the dialog by clicking Cancel...'
       Me.Cancelled = True 
       Me.Hide
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer)
       'User cancelled the dialog by closing the window...'
       Me.Cancelled = True
       Me.Hide
    End Sub
    
    Private Sub cmdOK_Click()
       'Make sure the user filled in both fields.'
       If Trim(txtUsername.Text) = "" And _
          Trim(txtPassword.Text) = "" Then
    
          MsgBox "You must enter both a username and password."
          Exit Sub
    
       ElseIf Trim(txtUsername.Text) = "" Then
          MsgBox "You must enter a username."
          Exit Sub
       ElseIf Trim(txtPassword.Text) = "" Then
          MsgBox "You must enter a password."
          Exit Sub
       End If
    
       'User filled in the necessary data - we can hide the form now'
       Me.Cancelled = False
       Me.Hide
    
    End Sub
    

    • Rename “Class1” in the project to “LoginDialog” and add the following code. This is the class other projects will use to diplay the login form (frmLogin):

    'LoginDialog.cls'
    
    'A public class that allows other projects to display a login        '
    'dialog and retrieve the user`s login information and whether or not '
    'they cancelled the dialog.                                          '
    'This code assumes you have a form in the same project named frmLogin'
    'and that it contains 2 textboxes, txtUsername and txtPassword, and  '
    '2 command buttons, cmdOK and cmdCancel.                             '
    '                                                                    '
    
    Public Username As String          'The username entered by the user'
    Public Password As String          'The password entered by the user'
    Public CancelledByUser As Boolean  'True if the user cancels or closes the form'
    
    'Shows a new Login form with the specified defaults filled in, if provided.'
    '                                                                          '
    '                                                                          '
    Public Function Show()
    
       'Create the login form and fill in the defaults'
       Dim frm As frmLogin
       Set frm = New frmLogin
    
       frm.txtUsername = Me.Username
       frm.txtPassword = Me.Password
    
       'Shows the form until it is hidden or closed'
       frm.Show vbModal
    
       If frm.Cancelled Then
          Me.CancelledByUser = True
       Else
          'Get the username and password from the form'
          Me.Username = frm.txtUsername
          Me.Password = frm.txtPassword
          Me.CancelledByUser = False
       End If
    
       'Unload the form'
       Unload frm
    
    End Function
    
    • Compile the ActiveX project and give it a name (i.e. MyAppLoginUI) so you can easily identify it when you need to add it to other projects.

    • When you want to use the form in another project, go to Project -> References… in the menu, and add your ActiveX DLL to the project. You may have to click Browse... to find it. Below is an example of how other code might use the example login dialog we just created:

    'LoginExample.bas'
    
    ' A simple example of how another project might use     '
    ' the generic login form created in the previous steps. '
    ' This example displays the login screen, then tries    '
    ' to authenticate the user against a database.          '
    '                                                       '
    Public Sub PerformLogin()
    
        Dim login As New LoginDialog
    
        'Pre-fill the username with the username of the last user who logged in.'
        login.Username = GetSetting("MyApp", "Settings", "LastUser")
    
        'Show the login screen. It will stay up until the user clicks OK or Cancel'
        login.Show()
    
        'If the user cancelled the login form, exit now...'
        If login.CancelledByUser Then
            Exit Sub
        End If
    
        'Pretend DAL is a data access layer module...'
        If Not DAL.LoginUser(login.Username, login.Password)
            MsgBox "Invalid username or password.", vbCritical+vbOKOnly, "Login Failure"
        End If
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 405k
  • Answers 405k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd consider if you actually need the div - I… May 15, 2026 at 5:58 am
  • Editorial Team
    Editorial Team added an answer No, because "#" is a reserved character. It's used to… May 15, 2026 at 5:58 am
  • Editorial Team
    Editorial Team added an answer On Windows, I recommend PLT Scheme which includes the DrScheme… May 15, 2026 at 5:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.