Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Code execution ordering


Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2004, 04:24 AM
cabbageman cabbageman is offline
Newcomer
 
Join Date: May 2004
Posts: 2
Question Code execution ordering


Hi all

Quick question about code execution (VB6), here's my scenario...

Form1 calls Form2 which displays a list of records, the user selects one and Form3 opens to show related records, the user once again selects one of these. Form3 sends the relevant record number to a global variable.

Both Form2 and Form3 now close and the user is back to where they began, and in a field on the form, should appear the contents of the global variable set by Form3.


The problem I am having is, after calling Form2, the piece of code which reads the global variable into the field on Form1 executes as soon as Form2 opens, which is, of course way too soon (it should execute after Form3 is closed).

How do I get VB to execute the loading of the two forms, and then move on to the statement following the Load Form1 line once forms 2/3 have closed?

I realise I could put something on Form3 to put the appropriate value directly onto Form1 by going
Code:
Form1.textbox1 = blaablaablaa
, but I want to use this form2/form3 combo in other places in the program too, where the final value will be output to forms other than Form1.

I hope this makes sense to someone, thanks in advance for any help.
Reply With Quote
  #2  
Old 05-03-2004, 05:08 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Show forms 2 and 3 as modal, so all other code execution stops until those forms are closed.
Code:
'form 1: Private Sub Command1_Click() Form2.Show vbModal 'the following will only run after Form2 has been closed: Me.Text1.Text = GlobalStringVariable End Sub 'form 2: Private Sub Command1_Click() GlobalStringVariable = Me.Text1.Text Unload Me End Sub
Reply With Quote
  #3  
Old 05-04-2004, 01:53 AM
cabbageman cabbageman is offline
Newcomer
 
Join Date: May 2004
Posts: 2
Default

Oops, I forgot to mention it's an MDI application and the forms are MDI children.

Quote:
Originally Posted by herilane
Show forms 2 and 3 as modal, so all other code execution stops until those forms are closed.
Code:
'form 1: Private Sub Command1_Click() Form2.Show vbModal 'the following will only run after Form2 has been closed: Me.Text1.Text = GlobalStringVariable End Sub 'form 2: Private Sub Command1_Click() GlobalStringVariable = Me.Text1.Text Unload Me End Sub
Reply With Quote
  #4  
Old 05-04-2004, 02:45 AM
HunterVF01's Avatar
HunterVF01 HunterVF01 is offline
Contributor
 
Join Date: Apr 2003
Location: Home Planet... Earth
Posts: 441
Default

How about removing the piece of code which reads the global variable into the field on Form1 from where it is and transfer it inside Form3's Unload event procedure?

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help understanding the Code dinesh General 7 09-21-2005 03:53 AM
Problem with code execution speed shevagol General 2 12-30-2003 10:56 PM
Need a hand with TinyJacks Search Code ..... Gunslinger Excel 7 12-17-2003 09:50 AM
Delay code execution? MagiX General 16 05-04-2003 04:30 PM
Excel VBA, stopping code execution on Error (Exit Sub doesn't work) EACutter Excel 3 03-18-2003 12:14 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->