What is AmbientMode and Ambient.UserMode and when are they True and when are they False? What's the purpose?
What is AmbientMode and Ambient.UserMode and when are they True and when are they False? What's the purpose?
Last edited by jmsrickland; Sep 8th, 2012 at 08:44 PM.
The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
It is allow the control to determine whether it's executing at design time (UserMode = False) or at run time.
Read this topic for more details.
If I run the project from the IDE is it considered design time or run time? I ask because when I am in the VB IDE and I run the project UserControl.Ambient.UserMode is always True. Is that the way it is supposed to be?
Another question: What is the difference between the keywords UserControl and Me when used in a UserControl?
The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
From MSDN article:
So it is always True at run time, False at design time. To well understand this property, create new project, add UserControl and paste this codeThe most important property of the AmbientProperties object is UserMode, which allows an instance of your control to determine whether it's executing at design time (UserMode = False) or at run time. Use of this property is discussed in "Creating Design-Time-Only or Run-Time-Only Properties," later in this chapter.
Tip To remember the meaning of UserMode, recall that at design time the person working with your control is a developer, rather than an end user. Thus the control is not in "user" mode, so UserMode = False.
The Me keyword does not work in a UserControl.Code:Private Sub UserControl_Resize() If UserControl.Ambient.UserMode = True Then Label1.Caption = "UserControl.Ambient.UserMode = True " & Format(Now, "hh:MM:ss") ' just to know that part continuously invoked. Else Label1.Caption = "UserControl.Ambient.UserMode = False " & Format(Now, "hh:MM:ss") End If End Sub
OK, I see the difference now.
Oh, but it does work in a UserControl. I further checked into this and it appears the difference is this:
UserControl has all the properties of a UserControl similar to what a Form has, whereas, Me has all the Public variables, Functions, and Subs that appear in the UserControl but not the Private ones.
The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
What i said is still true "The Me keyword does not work in a UserControl.", that is you cannot use Me in usercontrol like you do in a form.
Last edited by jmsrickland; Sep 10th, 2012 at 12:52 PM.
The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day