|
-
Sep 29th, 2000, 06:59 AM
#1
Thread Starter
Lively Member
1) I made a program with more than one form, and I noticed that whenever I click on the close button in the upper right corner to close the program, the program doesn't really close but hides itself. Can someone explain why?
2) What is the best way to switch between forms?
3) How do I make my forms have scrollbars when I resize the form to a smaller size?
I greatly appreciate the help gurus! =)
-
Sep 29th, 2000, 07:08 AM
#2
Addicted Member
Hi,
1) Do you have functions that never exit like a "For ever" loop or a "While 1" loop in your form ? This may explain why the form never unloads but hides.
1) After the form closes do you refer to a control on it from another form ? This would cause the unloaded form to load again and give you the impression it never closed...
2) For the interface its frm.setfocus or frm.show. For the code its frm. but I'am quite sure you already knew this, did I understand your question right ?
3) Got me there, never had to do this...
-
Sep 29th, 2000, 07:26 AM
#3
Addicted Member
Hello1
The problem with exiting is that when you click the x in the upper right corner you unnload the form, but don't close the application.
Even if all forms are unloaded the applicaiton will still be running.
To exit the app you must use the command End.
You can for instance decide which of the forms that shall be unloaded last, and in the event Form_Unload() put the command End.
As for the second, I use:
frmSecond.Enabled = True
frmSecond.Show
to switch from frmFirst to frmSecond.
You just use the same code (but with different names) to switch back again.
If you want you can extend it to
frmFirst.Enabled = False
as well, so the user can't use the "wrong" form, depending on what app you're doing.
In that case, just remember to enable the other form when you unload one.
As for the scrollbars, I haven't got a clue.
I don't know if it's possible.
Good luck,
Pentax
Wilhelm Tunemyr,
Swede in London
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda vítezi!
(Truth prevails!)
-
Sep 29th, 2000, 10:39 AM
#4
Frenzied Member
Scrollbars: I have heard that SetWindowLong can add scrollbars, but I do not know.
Closing app: never use end. It is evil. Its only safe when you need to demolish the app regardless of whether or not it causes GPFs etc. When doing complicated things, End will screw your app, OS, machine, life, etc.
-
Sep 29th, 2000, 10:50 AM
#5
Addicted Member
I'am with you MLEWIS, I think the END statement can lead to errors and surely leads to "spagetti" code when you start putting those anywhere in the code. Your application should exit when there are no more forms loaded in the forms collection and obviously no more code running in backgroud (loop)...
-
Sep 29th, 2000, 02:35 PM
#6
Use the following to unload all Forms properly.
Code:
Sub DestroyForms()
Dim frm As Form
For Each frm In Forms
Unload frm
Set frm = Nothing
Next frm
End Sub
Private Sub Command1_Click()
'End the project
DestroyForms
End Sub
-
Sep 29th, 2000, 03:25 PM
#7
Addicted Member
Dear me...
Is it really so terrible to use the End command?
I've used it an a (rather) complicated app, and I haven't experienced any problems, but maybe I just haven't noticed them.
What exactly can happen (apart from the risk of being resented by every vb-programmer from here to Calcutta)?
Pentax
Wilhelm Tunemyr,
Swede in London
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda vítezi!
(Truth prevails!)
-
Sep 29th, 2000, 03:37 PM
#8
Addicted Member
Hi Pentax,
here from the VB help topics (poor references but...)
The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.
it always depends of the context of your application. The part that bothers me is that it CLEARS the variables not knowing if they have been saved right (database envir.) if in edit... just little things like that.
The thing is that when you decide you need to call an END statement I presume you know everything is fine in your application so you can do so...
Anyways... it the weekend so my brain is swiching OFF right about now !
-
Sep 29th, 2000, 06:18 PM
#9
Addicted Member
Okay, thanks for clearing it up.
But, as you wrote, I use End only when I'm sure that's what is needed. And before that, the user gets his/her chance to abort, save files etc.
So I think I can go on using it (I'll have to take the risk about being resented...)
Cheers, Pentax
Wilhelm Tunemyr,
Swede in London
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda vítezi!
(Truth prevails!)
-
Sep 29th, 2000, 10:40 PM
#10
Frenzied Member
End is only evil when you haven't destroyed class objects, cleaned up variables, etc. but if you have made everything tidy its a handy way to demolish an app.
-
Sep 29th, 2000, 11:54 PM
#11
Thread Starter
Lively Member
Wow!
Wow thanks guys I really learned alot form this thread! 
So let me see if I got this right, to close the app I should clear all variables and objects before I use the end statement right?
Is there a way to cancel the unload command when you click on the x on the upper right hand side of the form? I want to prompt the user if they really want to quit before I unload all the forms (Thanks Megatron!) and end the app gracefully.
Now my only problem is the scrollbars for the form. Whenenver I resize the form the objects in the form get clipped. So I figured if I put scrollbars similar to all other window applications I'm golden. Problem is I couldn't so I set my form's Border Style to fixed single. I still want to be able to minimize my program but make it a fixed size. Anyway I can work around this?
Thanx again guys!
-
Sep 30th, 2000, 03:36 AM
#12
For cancelling the Unload event try this code:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim res As VbMsgBoxResult
res = MsgBox("Are you sure you want to close?", vbYesNo + vbApplicationModal + vbQuestion, "Close program")
If res = vbNo Then
Cancel = True
else
' Unload all forms, collections etc...
end if
End Sub
As for re-sizing try this:
Code:
Private Sub Form_Resize()
Text1.Width = Me.Width / 2
Text1.Height = Me.Height / 2
End Sub
Ofcourse you'll have to do this with every object and you'll have to change the "formula" (the "/ 2" part) to anything to fit your needs, like
Code:
Text1.Width=Me.width-1000
etc...
Enjoy!
-
Oct 1st, 2000, 04:12 AM
#13
Thread Starter
Lively Member
Thanks!
Thanks RobIII!
A lot of work for the resize though but it's effective. Thanks again, I greatly appreciate the help
-
Oct 1st, 2000, 08:51 PM
#14
Hyperactive Member
Re: Thanks!
Originally posted by gin
Thanks RobIII!
A lot of work for the resize though but it's effective. Thanks again, I greatly appreciate the help
Couldn't you just enumerate your controls in the form and skip having to change them one by one?
-
Oct 2nd, 2000, 02:07 AM
#15
Thread Starter
Lively Member
Well since I'm just a newbie could you explain how I go about doing that? I'd really like to learn how. Thanks
-
Oct 2nd, 2000, 08:30 AM
#16
Frenzied Member
This will only work if all the controls need the exact same resizing performed on them; not easy. here's one idea:
Dim PrevW, PrevH
Private Sub Form_Resize()
On error resume next
Dim q as control
Dim deltaw as single
Dim deltah as single
deltaw = me.scalewidth / prevw
deltah = me.scaleheight / prevh
For Each q in Me.Controls
q.top = q.top * deltah
q.left = q.left * deltaw
q.height = q.height * deltah
q.width = q.width * deltaw
Next q
Prevh = me.scaleheight
Prevw = me.scalewidth
End Sub
This should work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|