• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Problem with saving state variables in VB.NET

mAdD INDIAN

Diamond Member
Here's the scenario:

I have a page that gets data continously. There is a client software that sends it data every 2sec or so. The code to get the data from the query string is in the page_load function of the page. Now I want to add that data to an object everytime it gets new data. But if I create an instance of that object in the page, everytime the page is loaded, a new instance of the object will be created....hence not allowing data to be stored in that object since it will be gone the next time the page is loaded.

Also, I want to access that object in another page in the same project (and directory on the webserver).

How do I do these two things? I heard about using the Application object but I couldnt' figure it out.

Thanks.
 
Anyone can use it.

Hear's the deal...this is system of webpages and a client software that ultimately updates the webpages with GPS coordinates in real-time. So the client software is connected to a GPS reciever, gets the positional data, and then uploads it to the webserver. Now it uploads it to a page called write.aspx.

And in write.aspx the gps coord is serialized to a xml text file, which read.aspx uses to display it on another webpage for anyone to view.

Currently, it works by taking in one GPS coord at a time. But now I'm adding additional funcationality where I want to find instanteous speed between two GPS coord recieved in sequence.

So I made an object that takes two GPS coord and finds the distnace/speed between them. However, that object gets reinstantiated everytime the page loads, so only one Coord gets stored.

I thought about using session or application object, but I can't figure out the proper syntax for it.

Thanks.
 
Ok, whn you say client software, is it done by one client? So people who view this website should only be able to view the data that the client software uploaded?
Why don't you store both the co-ordinates in one XML file and then read from that XML file in one page load?

Anyway, Here is how to use session objects:
Session["objectName"]=Value; ->C#
Session("objectName")=Value -> VB
 
Only done by one client. this entire thing is mainly for research purposes to collect data for traffic anaylsis...so only one client will input data...but anyone can view the data that has been uploaded.

I was thinking about saving both to an XML file..but it would be difficult to implement that...since I would have to make it only save it twice...

So for
Session("objectName") = value

what does value equal?? And object name would be the object itself right? so I only need that one line? Don't I need something else to use that object when the page is reloaded?

Thanks a lot for your help.
 
value is whatever you want to store in the session variable. Probably the coordinates. I'm kind of rusty with ASP.NET session variables, but IIRC, ObjectName is the name of the particular session variable you want to use. I assume it works a lot like classic ASP. If you google for "ASP.NET session variable", you'll probably find a ton of indepth tutorials on usage.
 
Originally posted by: mAdD INDIAN
Only done by one client. this entire thing is mainly for research purposes to collect data for traffic anaylsis...so only one client will input data...but anyone can view the data that has been uploaded.

I was thinking about saving both to an XML file..but it would be difficult to implement that...since I would have to make it only save it twice...

So for
Session("objectName") = value

what does value equal?? And object name would be the object itself right? so I only need that one line? Don't I need something else to use that object when the page is reloaded?

Thanks a lot for your help.


It seems to me that a cookie would be a more viable option and meaningful option.
Anyway, Here is the example of how to use session variables:
Coord1=35.25
Coord2=36.32
Session("FirstCoord")=Coord1;
Session("SecondCoord")=Coord2;
Whenever you need to access the session variables just call Session("Firstcoord) or Session("Secondcoord") ... if either is null, it means that they haven't been assigned anything yet.
The session variables will remain in the server's memory until the sessin is closed... usually until the person who started the session closes the browser. A person starts a session whenever he visits your website.

Just so you know, Session/Application variables use server memory and blind use of them can have a significant impact on your application. Since this seems like something that isn't going to be used by a lot of people and you are using only two session variables, it shouldn't make a huge difference though.
 
I quickly read what you want to do, not sure i understand but...
you could use application level variables maybe
 
Originally posted by: WannaFly
I quickly read what you want to do, not sure i understand but...
you could use application level variables maybe

I was thinking of that too.

First I'm gonna spend more time reading up on Session and Application variables in ASP.NET.

This is what happens when you try programming in a language for the first time without proper books. I've been going thru it by pretty much Googling and asking folks for help. But I'm enjoying it...ASP.NET is a really nice setup.
 
You want to be able to access this data on a different page, so it seems to me that the best solution is to use a database to store the data. I think you're getting too complicated with the session variables and trying to pass an object off to a different page.

Lots of DB's out there to consider, many are free: Oracle, SQLServer, MSDE (free ver of SQLServer), MySQL, PostGreSQL, Access.
 
Originally posted by: tkdkid
You want to be able to access this data on a different page, so it seems to me that the best solution is to use a database to store the data. I think you're getting too complicated with the session variables and trying to pass an object off to a different page.

Lots of DB's out there to consider, many are free: Oracle, SQLServer, MSDE (free ver of SQLServer), MySQL, PostGreSQL, Access.

I was thinking of going the Access route.

But the problem is this: how can I make it so it only stores two Coords. As in, it Coord 1 goes in Location A first. Then coordinate 2 comes along which pushes Coord1 into Loc B..and Coord2 takes LocA. Then when Coord3 is entered, Coord1 is disposed off, Coord 2 takes Coord1's place...and Coord 3 goes into LocA.

Does that make sense? I would need session objects to implement that right? So the page knows which location to use...

Eventually I won't need to do that, but for now...I can only deal with two Coords...once I figure out a proper algorithm/formula to find distnaces given many coordinates (ie: find out what kind of avg to take..etc..)
 
Are the co-ords to be calculated only for the person who is accessing the page or should they be constant throughout
This is what I think you need to do (and is by far the easiest)... when the person updates the data use the following code:
If Application("Coord1")=NULL then
Application("Coord1")=31.42 //or whatever it is supposed to be
elseif Application("Coord2")=NULL then
Application("Coord2")=45.32
else //both are filled, so just pop the second one out
Application("Coord1")=Application("Coord2")
Application("Coord2")=53.32 // your new value
end if
*I may have made some minor syntax mistakes (I'm a C# programmer)*
To get the values in your application all you have to do is Application("Coord1")... again just so you know in case you extend this app to support thousands of coords... excessive use of application and session variables can have an impact on performance; you then have to consider alternatives (files,dbs etc etc)
 
Originally posted by: mAdMaLuDaWg
Are the co-ords to be calculated only for the person who is accessing the page or should they be constant throughout
This is what I think you need to do (and is by far the easiest)... when the person updates the data use the following code:
If Application("Coord1")=NULL then
Application("Coord1")=31.42 //or whatever it is supposed to be
elseif Application("Coord2")=NULL then
Application("Coord2")=45.32
else //both are filled, so just pop the second one out
Application("Coord1")=Application("Coord2")
Application("Coord2")=53.32 // your new value
end if
*I may have made some minor syntax mistakes (I'm a C# programmer)*
To get the values in your application all you have to do is Application("Coord1")... again just so you know in case you extend this app to support thousands of coords... excessive use of application and session variables can have an impact on performance; you then have to consider alternatives (files,dbs etc etc)

Thanks. And yes, they should be constant throughout.
 
Originally posted by: mAdD INDIAN
Originally posted by: mAdMaLuDaWg
Are the co-ords to be calculated only for the person who is accessing the page or should they be constant throughout
This is what I think you need to do (and is by far the easiest)... when the person updates the data use the following code:
If Application("Coord1")=NULL then
Application("Coord1")=31.42 //or whatever it is supposed to be
elseif Application("Coord2")=NULL then
Application("Coord2")=45.32
else //both are filled, so just pop the second one out
Application("Coord1")=Application("Coord2")
Application("Coord2")=53.32 // your new value
end if
*I may have made some minor syntax mistakes (I'm a C# programmer)*
To get the values in your application all you have to do is Application("Coord1")... again just so you know in case you extend this app to support thousands of coords... excessive use of application and session variables can have an impact on performance; you then have to consider alternatives (files,dbs etc etc)

Thanks. And yes, they should be constant throughout.
Yeah, then the code will be fine for this purpose. Application variables are shared throughout the entire web application so they could be accessed throughout. Storing them in a file is not really necessary then, unless you want to keep a log of all the co-ords.
 
Back
Top