| | |
Dialog Box alongwith Form
![]() |
You're going to have to restate your question here as it really doesn't make sense. Anyway here's something to think about when working with lots of forms like this. Let's say you have 3 forms, Form1,Form2,Form3. There is a button on Form1 that pops up Form2 and a button on Form2 that pops up Form3. Lets say the buttons are called btnForm2Pop and btnForm3Pop
When you click the button on Form1 the message box will be popped up as Form2 does not have exclusive control. So any code after showing the Form will be executed after the form load event of Form 2. However, when you click the button on Form2 execution of Form2 code is held up until Form3 is unloaded or hidden. So, the message box will not pop up until you close Form 3.
I don't know if this answers your question, but I hope it helps around the edges a bit.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' 'Form1 Code ' Private Sub btnForm2Pop_Click() Form2.Show MsgBox "I just popped Form2" End Sub
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' 'Form2 Code ' Private Sub btnForm2Pop_Click() Form3.Show vbModal, Me MsgBox "I just popped Form3" End Sub
When you click the button on Form1 the message box will be popped up as Form2 does not have exclusive control. So any code after showing the Form will be executed after the form load event of Form 2. However, when you click the button on Form2 execution of Form2 code is held up until Form3 is unloaded or hidden. So, the message box will not pop up until you close Form 3.
I don't know if this answers your question, but I hope it helps around the edges a bit.
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Greetings. Morning!
Thanks for your reply and sorry for making you confused.
I guess I got you.
So, vbModal is very important here.
What about the sequence of coding for:-
Do I put the Load command first before Unload or vice-versa?
Or it really doesn't matter?
Thanks for your reply and sorry for making you confused.
I guess I got you.
So, vbModal is very important here.
What about the sequence of coding for:-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Load Form1 Form1.show Unload Form2
Or it really doesn't matter?
"Study the past if you would define the future" - Confucius
You're going to have to ask a better question, again I don't really understand what you are asking.
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
For you to transfer information from form 3 to form 1 or what ever way you like declare an appropriate variable as global(outside all onclick events) and pass your local variable(inside your onclick events) to that global variable thus enabling any of the forms to get the information.
Form.Show (to show the form)
Yours Sincerely
Richard West
For you to transfer information from form 3 to form 1 or what ever way you like declare an appropriate variable as global(outside all onclick events) and pass your local variable(inside your onclick events) to that global variable thus enabling any of the forms to get the information.
Form.Show (to show the form)
Yours Sincerely
Richard West
Greetings.
Thanks a lot for all your replies.
Mnemtsas, I think I now truly understood the usage of vbModal and using it solved my problems.
However, one more small problem here.
I decided to upload a few screenshots to avoid confusions.
You see, in Form1, I only have 1 candidate in the list, initially.
http://redevolve.bravehost.com/Form1.jpg
When I click "Add Candidate", another form (Form2) would appear.
I then select a candidate to add from there.
In Form2, after selecting a candidate, I click "Add Candidate".
http://redevolve.bravehost.com/Form2.jpg
Form2 will be unloaded and the name of the selected candidate would then appear in Form1's list. The code is alright.
http://redevolve.bravehost.com/Form1-b.jpg
The problem is here:- Just before the lines where the new candidate is added to the list, I added a MsgBox "test" to see where goes wrong.
When I do that, after clicking the OK button in MsgBox, the candidate's name appeared in the list. When I remove the msgbox, the name won't appear.
What's wrong here? I suggest there should have some "return 0;" statements like in C for this? Hehe...I don't know. Can someone please advise me on this? :-|
Thanks a lot for all your replies.
Mnemtsas, I think I now truly understood the usage of vbModal and using it solved my problems.
However, one more small problem here.
I decided to upload a few screenshots to avoid confusions.
You see, in Form1, I only have 1 candidate in the list, initially.
http://redevolve.bravehost.com/Form1.jpg
When I click "Add Candidate", another form (Form2) would appear.
I then select a candidate to add from there.
In Form2, after selecting a candidate, I click "Add Candidate".
http://redevolve.bravehost.com/Form2.jpg
Form2 will be unloaded and the name of the selected candidate would then appear in Form1's list. The code is alright.
http://redevolve.bravehost.com/Form1-b.jpg
The problem is here:- Just before the lines where the new candidate is added to the list, I added a MsgBox "test" to see where goes wrong.
When I do that, after clicking the OK button in MsgBox, the candidate's name appeared in the list. When I remove the msgbox, the name won't appear.
What's wrong here? I suggest there should have some "return 0;" statements like in C for this? Hehe...I don't know. Can someone please advise me on this? :-|
"Study the past if you would define the future" - Confucius
Try putting this code
Just after the code where you add the item to the list.
If this doesn't work perhaps you could email me the code and I'll take a look offline.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Form1.Refresh DoEvents
Just after the code where you add the item to the list.
If this doesn't work perhaps you could email me the code and I'll take a look offline.
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Greetings.
Hey, thanks a lot for your advice.
Btw, just to let you know, I insert those 2 lines after the list.additem but there wasn't any signs.
I tried inserting them just before the list.additem and it worked.
Any idea whether the effect or whatever that's working in the background would be different? Could you please explain what does doevents do?
Thanks.
Hey, thanks a lot for your advice.
Btw, just to let you know, I insert those 2 lines after the list.additem but there wasn't any signs.
I tried inserting them just before the list.additem and it worked.
Any idea whether the effect or whatever that's working in the background would be different? Could you please explain what does doevents do?
Thanks.
"Study the past if you would define the future" - Confucius
Snipped from MSDN
Using DoEvents
Although Timer events are the best tool for background processing, particularly for very long tasks, the DoEvents function provides a convenient way to allow a task to be canceled. For example, the following code shows a "Process" button that changes to a "Cancel" button when it is clicked. Clicking it again interrupts the task it is performing.
DoEvents switches control to the operating-environment kernel. Control returns to your application as soon as all other applications in the environment have had a chance to respond to pending events. This doesn't cause the current application to give up the focus, but it does enable background events to be processed.
The results of this yielding may not always be what you expect. For example, the following Click-event code waits until ten seconds after the button was clicked and then displays a message. If the button is clicked while it is already waiting, the clicks will be finished in reverse order.
You may want to prevent an event procedure that gives up control with DoEvents from being called again before DoEvents returns. Otherwise, the procedure might end up being called endlessly, until system resources are exhausted. You can prevent this from happening either by temporarily disabling the control or by setting a static "flag" variable, as in the earlier example.
Avoiding DoEvents When Using Global Data
It may be perfectly safe for a function to be called again while it has yielded control with DoEvents. For example, this procedure tests for prime numbers and uses DoEvents to periodically enable other applications to process events:
This code calls the DoEvents statement once every 200 iterations. This allows the PrimeStatus procedure to continue calculations as long as needed while the rest of the environment responds to events.
Consider what happens during a DoEvents call. Execution of application code is suspended while other forms and applications process events. One of these events might be a button click that launches the PrimeStatus procedure again.
This causes PrimeStatus to be re-entered, but since each occurrence of the function has space on the stack for its parameters and local variables, there is no conflict. Of course, if PrimeStatus gets called too many times, an Out of Stack Space error could occur.
The situation would be very different if PrimeStatus used or changed module-level variables or global data. In that case, executing another instance of PrimeStatus before DoEvents could return might result in the values of the module data or global data being different than they were before DoEvents was called. The results of PrimeStatus would then be unpredictable.
Using DoEvents
Although Timer events are the best tool for background processing, particularly for very long tasks, the DoEvents function provides a convenient way to allow a task to be canceled. For example, the following code shows a "Process" button that changes to a "Cancel" button when it is clicked. Clicking it again interrupts the task it is performing.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
' The original caption for this button is "Process". Private Sub Command1_Click() ' Static variables are shared by all instances ' of a procedure. Static blnProcessing As Boolean Dim lngCt As Long Dim intYieldCt As Integer Dim dblDummy As Double ' When the button is clicked, test whether it's 'already processing. If blnProcessing Then ' If processing is in progress, cancel it. blnProcessing = False Else Command1.Caption = "Cancel" blnProcessing = True lngCt = 0 ' Perform a million floating-point ' multiplications. After every ' thousand, check for cancellation. Do While blnProcessing And (lngCt < 1000000) For intYieldCt = 1 To 1000 lngCt = lngCt + 1 dblDummy = lngCt * 3.14159 Next intYieldCt ' The DoEvents statement allows other ' events to occur, including pressing this ' button a second time. DoEvents Loop blnProcessing = False Command1.Caption = "Process" MsgBox lngCt & " multiplications were performed" End If End Sub
The results of this yielding may not always be what you expect. For example, the following Click-event code waits until ten seconds after the button was clicked and then displays a message. If the button is clicked while it is already waiting, the clicks will be finished in reverse order.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command2_Click() Static intClick As Integer Dim intClickNumber As Integer Dim dblEndTime As Double ' Each time the button is clicked, ' give it a unique number. intClick = intClick + 1 intClickNumber = intClick ' Wait for ten seconds. dblEndTime = Timer + 10# Do While dblEndTime > Timer ' Do nothing but allow other ' applications to process ' their events. DoEvents Loop MsgBox "Click " & intClickNumber & " is finished" End Sub
Avoiding DoEvents When Using Global Data
It may be perfectly safe for a function to be called again while it has yielded control with DoEvents. For example, this procedure tests for prime numbers and uses DoEvents to periodically enable other applications to process events:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Function PrimeStatus (TestVal As Long) As Integer Dim Lim As Integer PrimeStatus = True Lim = Sqr(TestVal) For I = 2 To Lim If TestVal Mod I = 0 Then PrimeStatus = False Exit For End If If I Mod 200 = 0 Then DoEvents Next I End Function
Consider what happens during a DoEvents call. Execution of application code is suspended while other forms and applications process events. One of these events might be a button click that launches the PrimeStatus procedure again.
This causes PrimeStatus to be re-entered, but since each occurrence of the function has space on the stack for its parameters and local variables, there is no conflict. Of course, if PrimeStatus gets called too many times, an Out of Stack Space error could occur.
The situation would be very different if PrimeStatus used or changed module-level variables or global data. In that case, executing another instance of PrimeStatus before DoEvents could return might result in the values of the module data or global data being different than they were before DoEvents was called. The results of PrimeStatus would then be unpredictable.
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
•
•
Originally Posted by red_evolve
Greetings.
Thanks a lot for your help all the way through.
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Is their a way to earn money from freelance VB coding on the net
- Next Thread: creating mail applications
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





