Results 1 to 5 of 5

Thread: share same procedure or function on multiple forms in vb6

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2015
    Posts
    2

    share same procedure or function on multiple forms in vb6

    Hi everyone,
    I have a problem. I am attaching here a rar file. please unrar and check the vb6 code.
    You saw in windows copy paste function. We copy and paste one file, then again copy another file and paste in folder and again and again, then windows shows multiple windows for this operation. I am trying to make function in visual basic 6 but unable to develop this application. I attached my code here. In this code there is a one main form, sub form and a class module. When run this application the main form opens. Now press Command 1 button, it creates the instance for both sub form and class module and open the sub form and after 3 seconds the counting starts. When you press Command 2 button it creates another instance for the same sub form and class module and open the sub form and after 3 seconds the counting starts. When second sub form opens then the counting of first form stops. I want the script that share the same function (Class module function/procedure) and both counting should run. I think you understand my problem. Please help me.

    Amir
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: share same procedure or function on multiple forms in vb6

    Rather than attaching the entire project you should show us just the little bit of code that is of interest.
    Are you using a timer on the form that is created?
    Are you using a local variable for the counter or a global?

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2015
    Posts
    2

    Re: share same procedure or function on multiple forms in vb6

    Hi DataMiser,
    When the sub form is loaded, the timer control runs the code in class module after 3 seconds. Then counter runs from 1 to 1000000. When the second button pressed, the new counter starts from 1 to 1000000 but also the counter of first form should run. I mean both counters of both forms should run simultaneously.

    Thanks
    Amir

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: share same procedure or function on multiple forms in vb6

    Is it a class or a module?

    Why not have the code in the timer event on the form, that way when you create a new instance of the form you are creating a new instance of the timer code as well. Just need to make sure that you are not using a global variable for trackign the counter else they will step on each other. Use a form level variable or a local static variable in the timer routine.

  5. #5
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,730

    Re: share same procedure or function on multiple forms in vb6

    the problem with your code is that you are looping and you think doevents is enough to allow the other form to run.
    the other is "waiting" until the loop is done. to fix this you need to circle between the forms to allow both to run the loops simultaneously.

Posting Permissions

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



Click Here to Expand Forum to Full Width