Dialog Box alongwith Form

Reply

Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Dialog Box alongwith Form

 
0
  #11
Jul 19th, 2004
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. '
  2. 'Form1 Code
  3. '
  4. Private Sub btnForm2Pop_Click()
  5. Form2.Show
  6. MsgBox "I just popped Form2"
  7. End Sub

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. '
  2. 'Form2 Code
  3. '
  4. Private Sub btnForm2Pop_Click()
  5. Form3.Show vbModal, Me
  6. MsgBox "I just popped Form3"
  7. 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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Dialog Box alongwith Form

 
0
  #12
Jul 19th, 2004
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:-
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Load Form1
  2. Form1.show
  3.  
  4. Unload Form2
Do I put the Load command first before Unload or vice-versa?
Or it really doesn't matter?
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Dialog Box alongwith Form

 
0
  #13
Jul 19th, 2004
You're going to have to ask a better question, again I don't really understand what you are asking.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Dialog Box alongwith Form

 
0
  #14
Jul 22nd, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Dialog Box alongwith Form

 
0
  #15
Jul 27th, 2004
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? :-|
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Dialog Box alongwith Form

 
0
  #16
Jul 28th, 2004
Try putting this code
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Form1.Refresh
  2. 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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Dialog Box alongwith Form

 
0
  #17
Jul 28th, 2004
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.
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Dialog Box alongwith Form

 
0
  #18
Jul 29th, 2004
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ' The original caption for this button is "Process".
  2. Private Sub Command1_Click()
  3. ' Static variables are shared by all instances
  4. ' of a procedure.
  5. Static blnProcessing As Boolean
  6. Dim lngCt As Long
  7. Dim intYieldCt As Integer
  8. Dim dblDummy As Double
  9. ' When the button is clicked, test whether it's
  10. 'already processing.
  11. If blnProcessing Then
  12. ' If processing is in progress, cancel it.
  13. blnProcessing = False
  14. Else
  15. Command1.Caption = "Cancel"
  16. blnProcessing = True
  17. lngCt = 0
  18. ' Perform a million floating-point
  19. ' multiplications. After every
  20. ' thousand, check for cancellation.
  21. Do While blnProcessing And (lngCt < 1000000)
  22. For intYieldCt = 1 To 1000
  23. lngCt = lngCt + 1
  24. dblDummy = lngCt * 3.14159
  25. Next intYieldCt
  26. ' The DoEvents statement allows other
  27. ' events to occur, including pressing this
  28. ' button a second time.
  29. DoEvents
  30. Loop
  31. blnProcessing = False
  32. Command1.Caption = "Process"
  33. MsgBox lngCt & " multiplications were performed"
  34. End If
  35. End Sub
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command2_Click()
  2. Static intClick As Integer
  3. Dim intClickNumber As Integer
  4. Dim dblEndTime As Double
  5. ' Each time the button is clicked,
  6. ' give it a unique number.
  7. intClick = intClick + 1
  8. intClickNumber = intClick
  9. ' Wait for ten seconds.
  10. dblEndTime = Timer + 10#
  11. Do While dblEndTime > Timer
  12. ' Do nothing but allow other
  13. ' applications to process
  14. ' their events.
  15. DoEvents
  16. Loop
  17. MsgBox "Click " & intClickNumber & " is finished"
  18. End Sub
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Function PrimeStatus (TestVal As Long) As Integer
  2. Dim Lim As Integer
  3. PrimeStatus = True
  4. Lim = Sqr(TestVal)
  5. For I = 2 To Lim
  6. If TestVal Mod I = 0 Then
  7. PrimeStatus = False
  8. Exit For
  9. End If
  10. If I Mod 200 = 0 Then DoEvents
  11. Next I
  12. End Function
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: Dialog Box alongwith Form

 
0
  #19
Jul 30th, 2004
Greetings.
Thanks a lot for your help all the way through.
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: Dialog Box alongwith Form

 
0
  #20
Jul 31st, 2004
Originally Posted by red_evolve
Greetings.
Thanks a lot for your help all the way through.
No worries, feel free to ask any time!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC