Forum  General Visual ...  Let's Chat Abou...  Global Variable question/Clarification
Previous Previous
 
Next Next
New Post 1/29/2009 1:05 AM
  gcsorensen
163 posts
5th Level Poster


Re: Global Variable question/Clarification 

Hi, Ori,

My colleague and I did some testing this morning to test the effect of global variables, and, naturally, saw the effect you described.

The user specific variables have now been moved into a class which is, as I understand it, instantiated for each user.

I will have to review the new code to confirm the exact mechanism, but I can say that the new code does allow for user specific "application wide" variables.

We will continue testing for ultimate confirmation, and I will get back to you if needed.

Thanks and regards,

Geoff

 
New Post 1/29/2009 3:46 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 

Hi Geoff,

Yes, you are right about that creating a class instance and store it in the correct scope, does allow for user-specific + application-wide variables, as well as user-specific + session-specific variables.

Good luck with your variables !

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/11/2009 3:39 PM
  derekmhart@yahoo.com
685 posts
1st Level Poster


Re: Global Variable question/Clarification 

OK, a little more clarification. I am clear that I want to use context variables, but I don't want them to be always used with the full syntax, such as VWGContext.Current("UserName")

 

So I am a little unclear if I should start a class, maybe like a singleton class, when the session starts, and store the variables there? Perhaps using somelike like MyClass.UserName is not much shorter than using VWGContext.Current("UserName") - perhaps using VWGContext.Current("UserName") would be very clear when it is in code, and adding another copy of this variable is not necessary. I am using vb.net. If it is best practices to use a class for a session, can you please show an example of how to use this class. For example, if I have my Logon form, and then a MainForm, how do I know the best place to instantiate the class, since my Logon form might not always execute (such as if the user simply pastes the URL into another tab in IE and goes directly to MainForm). Unclear on the scope of all this. Please send details. Thanx!

 
New Post 5/13/2009 3:16 PM
  palli
11189 posts
1st Level Poster




Re: Global Variable question/Clarification 

Hi,

Using a class to wrap access to those context variables is quite fine, if you use Properties to Get/Set the values, and within those Get/Set you Get/Set VWGContext.Current("UserName"). That way it really doesn't matter how many instances you are creating of that class, they are all using the same context variable.

If you on the other hand would not use properties, and use "fields" (in vb.net terms) within your class which you would init in the class's constructor, you would have to take some actions to set the values of the context variable when you assign a new value, which you would like to "stick".

A very, very simple example in vb.net could be something like this:

    Public Class WrapperClass
        Public Property Username() As String
            Get
                Return VWGContext.Current("UserName")
            End Get
            Set(ByVal value As String)
                VWGContext.Current("UserName") = value
            End Set
        End Property
    End Class

Using the class could be something of this kind:
        Dim WC As WrapperClass = New WrapperClass
        If WC.Username = "me" Then
            MessageBox.Show("It's me")
        End If
 

Hope this helps,

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 5/13/2009 5:51 PM
  derekmhart@yahoo.com
685 posts
1st Level Poster


Re: Global Variable question/Clarification 

Can you give a little more feedback on the best place to store code that starts at the beginning of an application, such as storing the connection string to a sql server into a variable. I know that a form is the first thing that loads, not a Sub Main(), but I am not always sure if the Logon Form is the first form to load, such as if the user pastes the URL into another tab in IE. However, if I load all the session variables in the Logon Form, and the user loads a copy into another tab, that tab will probably have all the variables available for use, right? So is the Logon Form the best place to load everything.

In reference to your previous response, I was looking to have a shorter way to get to my user, without having to first Dim WC as a class, because every time I write data to a database, I will be using the username to write data for the correct user. In winforms I would use a Public Shared Property, but I think this might become available to all users (all sessions), and that would be wrong. If I declare Public Shared Property Username() As String, will that be limited to one session, so a user on another machine would have their own copy of it?

 
Previous Previous
 
Next Next
  Forum  General Visual ...  Let's Chat Abou...  Global Variable question/Clarification
Azure banner
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS