Search Tools Links Login

Is Form Loaded check without causing form to load (EASY!)


Visual Basic 6, or VB Classic

Check to see if a form is loaded without actually loading the form, or access public form variables without causing the form to load

Original Author: Dave Gallant

Code





Ever want to check to see if a form is loaded before you try to access it?

The only way I know of (other than this way) is to loop through the form collection...
a rather large pain in the rear.

The trick is to create a new form property.



Add the following code to any form:





  Option Explicit

  

  ' Create a new property variable

  Dim
m_bLoaded
  As Boolean

  ' get the value of the new property

  Public Property Get
Loaded()
  As Boolean



  

Loaded = m_bLoaded



End Property


' set the value of the new property

  Public Property Let
Loaded(ByVal
  bLoaded As Boolean)



  

m_bLoaded = bLoaded



End Property




  Private Sub
Form_Load()



  

' set the loaded property to true

   Me.Loaded = True



End Sub


Private Sub Form_Unload(Cancel
  As Integer)



  

' set the loaded property to false

   Me.Loaded = False



End Sub



 


Now, form any other form or module, you can do this (assume you are using the
default form name)


If Form1.Loaded = True Then



MsgBox "Form is loaded"



Else



MsgBox "Form is not loaded"



End If




Accessing this property will not cause the form to load in the event that loaded
is false.

However, if you make a single variable and make it public on the form, and try
to access it, the form will load.

You can actually use this property method to retain any data and access it without
reloading hte form.

I created a custom input box field in which the "Return String" is
a custom property, like the loaded property.

then I just do this:



Form1.show 1, me ' (show my new form
  modal)


  strInput = Form1.strInput '(this
  will not cause the form to reload provided your property is called strInput!)



give it a shot, let me know if you have any problems.

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 114 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.