WindowState on Form load - Unexpected Return Value 
Author Message
 WindowState on Form load - Unexpected Return Value

Hi Lisa,

It will return 0 until such time as the form is shown. This is as
documented.  You can probably check to see if it is Visible to see if the
return value has any meaning.


Quote:
> Why return 0 after just setting it to 1?

> Private Sub Form_Load()

>  Debug.Print Me.WindowState ' State returns 0 as expected

>  Me.WindowState = 1         ' Set State to 1 (minimized)
>  Debug.Print Me.WindowState ' State = 0?

>  DoEvents                   ' DoEvents to the rescue!
>  Debug.Print Me.WindowState ' State still = 0!

>  Me.Show                    ' Show
>  Debug.Print Me.WindowState ' Returns 1 now!

> End Sub

> ? Thanks,
> Lisa



Tue, 28 Jun 2011 17:43:05 GMT  
 WindowState on Form load - Unexpected Return Value

Quote:

> Why return 0 after just setting it to 1?

> Private Sub Form_Load()

>  Debug.Print Me.WindowState ' State returns 0 as expected

>  Me.WindowState = 1         ' Set State to 1 (minimized)
>  Debug.Print Me.WindowState ' State = 0?

>  DoEvents                   ' DoEvents to the rescue!
>  Debug.Print Me.WindowState ' State still = 0!

>  Me.Show                    ' Show
>  Debug.Print Me.WindowState ' Returns 1 now!

> End Sub

Well, your own code answers that.  The form has to be visible, which is why after the Me.Show, the WindowState is 1.

--
Mike



Tue, 28 Jun 2011 21:51:51 GMT  
 WindowState on Form load - Unexpected Return Value

Quote:
> Why return 0 after just setting it to 1?

> Private Sub Form_Load()

>  Debug.Print Me.WindowState ' State returns 0 as expected

>  Me.WindowState = 1         ' Set State to 1 (minimized)
>  Debug.Print Me.WindowState ' State = 0?

>  DoEvents                   ' DoEvents to the rescue!
>  Debug.Print Me.WindowState ' State still = 0!

>  Me.Show                    ' Show
>  Debug.Print Me.WindowState ' Returns 1 now!

> End Sub

There are several properties and methods that make no sense if the form
itself is not visible, and they're not even limited to VB6. Someone was
asking in a Windows Forms group why the EnsureVisible() method wasn't
working on a list view. Well, it's because nothing was visible at all, so
how is EnsureVisible() supposed to do its job?


Wed, 29 Jun 2011 05:54:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. SHGetFileInfo returning unexpected values...

2. SHGetFileInfo returning unexpected values...

3. Form as Dialog returning value - function style

4. Returning a field from a table as a default value in a form

5. Returning value from modal form.

6. Returning value from a search form

7. Returning a value from a VBA form

8. returning value from form

9. Can Forms return values?

10. Modal form returning a value

11. Returning Values from a Form.

12. Getting a form to return two read-only values

 

 
Powered by phpBB® Forum Software