|
-
Nov 27th, 2000, 08:23 PM
#1
Thread Starter
Junior Member
Is there any way to suppress the Initialize and Load events?
I ask this because of a specific situation I have where a function in a code module is referencing a textbox on a Form. Whenever this function executes, however, it triggers the Initialize and Load events on the Form--thus re-initializing my Form and causing some pretty nasty fallout.
I've had to use some pretty ugly work arounds. I can't help but think that there is a better way.
Regards,
trapper
-
Nov 27th, 2000, 09:30 PM
#2
There are two ways (at least) to deal with the problem:
1) The good way: A form will be loaded any time any visible control is referenced. To avoid that, create properties (one or more) on the form and use the property Set to hold the values that you would normally send to the textbox or other controls. Then when you want to load the form, use the property Get to get the stored values.
2) The not so good way: Create a global boolean named for example bBypass and set it to True initially. In your form that you don't want to show, place If bBypass Then Exit Sub. When you want to show the form, set bBypass = False and show the form via MyForm.Show.
-
Nov 28th, 2000, 01:29 AM
#3
Thread Starter
Junior Member
Martin, wouldn't a Form also be loaded when referencing a Form's properties?
I'm thinking of defining a property within the Form and using it as a initialized flag. I have way too many text boxes to set up a property for each one.
-
Nov 28th, 2000, 03:22 AM
#4
transcendental analytic
Yep, the form will load as soon as you touch it. that goes for anything on it too. Put critical initialiation code in the module from which you load the form
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 28th, 2000, 11:25 AM
#5
trapper and kedaman I have to disagree. A form will not be loaded if all you do is refer to one of the properties you add. Try it yourself. Create a project with two forms. Put the following code in form2.
Code:
Option Explicit
Private mName As String
Public Property Get NickName() As String
NickName = mName
End Property
Public Property Let NickName(ByVal sNM As String)
mName = sNM
End Property
and put a command button on Form1 with the following code.
Code:
Private Sub Command1_Click()
Form2.NickName = "Marty"
MsgBox Form2.NickName
End Sub
When the button is clicked, Form2 is not loaded, but "Marty" will be displayed.
-
Nov 28th, 2000, 02:30 PM
#6
transcendental analytic
Very cool trick Martin, but i would never do something like that, well it's also somewhat odd, i think, and this is what i think, so i may be wrong, that it's actually accessing the form2 wrapper object which contains all the variables in the form but not the form itself.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 28th, 2000, 02:59 PM
#7
...this is what i think, so i may be wrong, that it's actually accessing the form2 wrapper object which contains all the variables in the form but not the form itself.
Who knows? But the point is that it works and it sure has made my life easier.
-
Nov 29th, 2000, 01:14 AM
#8
Thread Starter
Junior Member
Thanks Martin, kedaman, for your help.
Martin, I did try an experiment with the user-defined property. I referenced the form's new property from a code module. Next thing the trace showed was the Initialize event on the form being fired. I don't know if trying it from another form would make a difference. Is it significant whether the form is modal or not?
I had suspected that a form would be loaded when its properties were referenced because I had an "options" form reference the main form's Height, Width,...etc properties. This caused the main form to re-initialize & re-load.
I may try the user-defined property as an initialize flag. kedeman, do you know if the property is accessed and then the initialize event triggers, or is the property accessed after the initialize sub is done?
Regards,
trapper
-
Nov 29th, 2000, 03:47 AM
#9
transcendental analytic
The initialize event is triggered when you access the property(to the form or a control on the form but not to a property get method that doesn't access the form), that means before the value is retrieved.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 29th, 2000, 10:43 AM
#10
trapper, you are correct when you say that the Initialize event of Form2 is triggered when a property of Form2 is referenced. The reason I didn't know that was that while I've written VB programs for probably 10 years, I don't think I've ever put any code in the Initialize event of a form. What kind of code do you put there that couldn't be put instead in the Load or Activate events?
-
Nov 29th, 2000, 04:43 PM
#11
Thread Starter
Junior Member
Marty, I have a rather large treeview on the form that takes a few awkward moments to populate. The initialize event on the form fires when the form is instanced as well as when the form is shown. What I do is display my app's splash screen "Please wait--loading" and then instance my main form. When the treeview is done loading, I get rid of the splash screen and show the main form.
I had tried to build the treeview nodes separatly, but I had trouble.
Do you do all your initializing in your Load event?
If you have any suggestions I'd appreciate it.
Regards,
trapper
-
Nov 29th, 2000, 04:51 PM
#12
I use either the Load or Activate events. Couldn't you put your Initialize event code in the Load event, including loading the treeview, and unload your splash screen when yourmainform.Visible = True? That way you can use the Property method I suggested to supress the Load event and not have to worry about the Initialize event.
[Edited by MartinLiss on 11-29-2000 at 04:54 PM]
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
|