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

  • SEARCH
  • Home
  • 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 8452921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:37:48+00:00 2026-06-10T11:37:48+00:00

I am trying to declare a variable in a VB6 module as follows: Public

  • 0

I am trying to declare a variable in a VB6 module as follows:

Public WithEvents MyObject As MyClass

The help files say that WithEvents can only be used in class modules. Why can’t it be used in .bas modules?

The legacy code I am working has an object declared globally in a module. I want to add WithEvents to this declaration but I need to keep the object global because many other forms etc refer to the object. How can I achieve this with minimal disruption to the code?

  • 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-06-10T11:37:50+00:00Added an answer on June 10, 2026 at 11:37 am

    Write a class that accepts your global object as a parameter and sinks its events.

    ' Class MySink
    Private WithEvents m_oSink As MyClass
    
    Friend Sub frInit(oSink As MyClass)
        Set m_oSink = oSink
    End Sub
    
    Private Sub m_oSink_MyEvent()
        '--- implement event
    End Sub
    

    Create an instance of this class in your .bas module.

    Public g_oMyObject AS MyClass
    Private m_oMySink As MySink
    
    Sub Main()
        Set g_oMyObject = New MyClass
        Set m_oMySink = New MySink
        m_oMySink.frInit g_oMyObject
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to declare a UInt32 variable that can be accessed by any
I am trying to declare a variable for matrix multiplication as follows: __shared__ float
I'm trying to declare a variable in an if-else block as follows: int main(int
I am trying to declare a variable that has a default value or if
I'm trying to declare a C++ variable that takes up zero bytes. Its in
I'm trying to declare a variable whose value is another variable that isn't set
I was wondering if there was a way that I can declare a variable
I'm trying to declare a global variable from within a class like so: class
I am trying to declare some integer values (used for controlling checkboxes that I
I'm trying to declare a variable depending on what the number is. I'm trying

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.