473,587 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some variables at the Class level not accessible in Subs

Following what I think are relevant portions of my code:

---------------Begin Code---------------------
Public Class LOLoadingBoard
Inherits System.Web.UI.P age
Dim MaxNum As Integer
Dim LNToEd As Integer
Dim CStatClr As Integer
Dim lBox() As Integer, lStatusColor() As Integer, lTrimWt() As Integer
Dim lPanelWt() As Integer, lPurlinWt() As Integer, lOtherWt() As Integer
Dim lWt() As Integer, lRoute() As String, lStatus() As String
Dim lTrimTime() As String, lPanelTime() As String, lPurlinTime() As
String
Dim lWalked() As String, lCompleted() As String, lBOL() As String
Dim lTrailerNum() As String, lDriver() As String, lNotes() As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LNToEd = 3
CStatClr = 1
MaxNum = 13
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " & CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
LNToEd = 7
CStatClr = 7
MaxNum = 7
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2Click
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " & CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub
End Class
---------------End Code---------------------
You can see I have declared these vars at the Class level of this ASPX page.

Most of theses vars are available to be updated or to return their values in
ALL other subroutines under this class.

MaxNum and all of the arrayed variables are working this way.

My problem is that LNToEd and CStatClr are NOT available.

Here is an example of what I am seeing
When I run the Code it displays:

LNToEd = 3
CStatClr = 1
MaxNum = 13

If I then immediately click Button2 I get:

LNToEd = 0
CStatClr = 0
MaxNum = 13

If I then click Button1 I get:

LNToEd = 7
CStatClr = 7
MaxNum = 7

If I then click Button2 again I get:

LNToEd = 0
CStatClr = 0
MaxNum = 7
This is of coure not my entire application but this is representative of
what is happening. I don't get it. The MaxNum and array vars (once they
are Redim'ed when needed) seem to be responding the way I would expect for a
var declared with a class level scope. But just these two are giving me
troubles. I have hunted through the entire code and there are no other
places placing a 0 value in these var that I can see.

Any ideas are appreciated.

thanx
Fred
Nov 20 '05 #1
5 1170
You realize you have 2 sub routines handling the same event??
"Fred" <fb******@centr alstatesmfg.com > wrote in message
news:OR******** ******@TK2MSFTN GP10.phx.gbl...
Following what I think are relevant portions of my code:

---------------Begin Code---------------------
Public Class LOLoadingBoard
Inherits System.Web.UI.P age
Dim MaxNum As Integer
Dim LNToEd As Integer
Dim CStatClr As Integer
Dim lBox() As Integer, lStatusColor() As Integer, lTrimWt() As Integer
Dim lPanelWt() As Integer, lPurlinWt() As Integer, lOtherWt() As Integer Dim lWt() As Integer, lRoute() As String, lStatus() As String
Dim lTrimTime() As String, lPanelTime() As String, lPurlinTime() As
String
Dim lWalked() As String, lCompleted() As String, lBOL() As String
Dim lTrailerNum() As String, lDriver() As String, lNotes() As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LNToEd = 3
CStatClr = 1
MaxNum = 13
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " & CStatClr & "<BR>MaxNum = " & MaxNum )
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
LNToEd = 7
CStatClr = 7
MaxNum = 7
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2Click
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " & CStatClr & "<BR>MaxNum = " & MaxNum )
End Sub
End Class
---------------End Code---------------------
You can see I have declared these vars at the Class level of this ASPX page.
Most of theses vars are available to be updated or to return their values in ALL other subroutines under this class.

MaxNum and all of the arrayed variables are working this way.

My problem is that LNToEd and CStatClr are NOT available.

Here is an example of what I am seeing
When I run the Code it displays:

LNToEd = 3
CStatClr = 1
MaxNum = 13

If I then immediately click Button2 I get:

LNToEd = 0
CStatClr = 0
MaxNum = 13

If I then click Button1 I get:

LNToEd = 7
CStatClr = 7
MaxNum = 7

If I then click Button2 again I get:

LNToEd = 0
CStatClr = 0
MaxNum = 7
This is of coure not my entire application but this is representative of
what is happening. I don't get it. The MaxNum and array vars (once they
are Redim'ed when needed) seem to be responding the way I would expect for a var declared with a class level scope. But just these two are giving me
troubles. I have hunted through the entire code and there are no other
places placing a 0 value in these var that I can see.

Any ideas are appreciated.

thanx
Fred

Nov 20 '05 #2
That was a Typo, didn't just copy and paste out of the app.

It should be :

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2Click
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " & CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
You realize you have 2 sub routines handling the same event??
"Fred" <fb******@centr alstatesmfg.com > wrote in message
news:OR******** ******@TK2MSFTN GP10.phx.gbl...
Following what I think are relevant portions of my code:

---------------Begin Code---------------------
Public Class LOLoadingBoard
Inherits System.Web.UI.P age
Dim MaxNum As Integer
Dim LNToEd As Integer
Dim CStatClr As Integer
Dim lBox() As Integer, lStatusColor() As Integer, lTrimWt() As Integer Dim lPanelWt() As Integer, lPurlinWt() As Integer, lOtherWt() As Integer
Dim lWt() As Integer, lRoute() As String, lStatus() As String
Dim lTrimTime() As String, lPanelTime() As String, lPurlinTime() As
String
Dim lWalked() As String, lCompleted() As String, lBOL() As String
Dim lTrailerNum() As String, lDriver() As String, lNotes() As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LNToEd = 3
CStatClr = 1
MaxNum = 13
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " &

CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
LNToEd = 7
CStatClr = 7
MaxNum = 7
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2Click
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " &

CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub
End Class
---------------End Code---------------------
You can see I have declared these vars at the Class level of this ASPX

page.

Most of theses vars are available to be updated or to return their values in
ALL other subroutines under this class.

MaxNum and all of the arrayed variables are working this way.

My problem is that LNToEd and CStatClr are NOT available.

Here is an example of what I am seeing
When I run the Code it displays:

LNToEd = 3
CStatClr = 1
MaxNum = 13

If I then immediately click Button2 I get:

LNToEd = 0
CStatClr = 0
MaxNum = 13

If I then click Button1 I get:

LNToEd = 7
CStatClr = 7
MaxNum = 7

If I then click Button2 again I get:

LNToEd = 0
CStatClr = 0
MaxNum = 7
This is of coure not my entire application but this is representative of
what is happening. I don't get it. The MaxNum and array vars (once
they are Redim'ed when needed) seem to be responding the way I would expect

for a
var declared with a class level scope. But just these two are giving me
troubles. I have hunted through the entire code and there are no other
places placing a 0 value in these var that I can see.

Any ideas are appreciated.

thanx
Fred


Nov 20 '05 #3
Hi Fred,

I runned your code (after removing some typos more than CJ told) and it
works as it would I
expect. (I also added a dot in your last corrections)

Load gives
3
1
13
Button 1 gives
3
1
13
Button 2 gives
3
1
13
3
1
13

Strange that you get with this sample other results.
What did you expect?

Cor

....
That was a Typo, didn't just copy and paste out of the app.

It should be :

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2Click
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " & CStatClr & "<BR>MaxNum = " & MaxNum )
End Sub

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl...
You realize you have 2 sub routines handling the same event??
"Fred" <fb******@centr alstatesmfg.com > wrote in message
news:OR******** ******@TK2MSFTN GP10.phx.gbl...
Following what I think are relevant portions of my code:

---------------Begin Code---------------------
Public Class LOLoadingBoard
Inherits System.Web.UI.P age
Dim MaxNum As Integer
Dim LNToEd As Integer
Dim CStatClr As Integer
Dim lBox() As Integer, lStatusColor() As Integer, lTrimWt() As Integer Dim lPanelWt() As Integer, lPurlinWt() As Integer, lOtherWt() As

Integer
Dim lWt() As Integer, lRoute() As String, lStatus() As String
Dim lTrimTime() As String, lPanelTime() As String, lPurlinTime() As String
Dim lWalked() As String, lCompleted() As String, lBOL() As String
Dim lTrailerNum() As String, lDriver() As String, lNotes() As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
LNToEd = 3
CStatClr = 1
MaxNum = 13
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " &

CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
LNToEd = 7
CStatClr = 7
MaxNum = 7
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2Click
Response.Write (" LNToEd = " & LNToEd & "<BR>CStatC lr = " &

CStatClr
& "<BR>MaxNum = " & MaxNum )
End Sub
End Class
---------------End Code---------------------
You can see I have declared these vars at the Class level of this ASPX

page.

Most of theses vars are available to be updated or to return their values
in
ALL other subroutines under this class.

MaxNum and all of the arrayed variables are working this way.

My problem is that LNToEd and CStatClr are NOT available.

Here is an example of what I am seeing
When I run the Code it displays:

LNToEd = 3
CStatClr = 1
MaxNum = 13

If I then immediately click Button2 I get:

LNToEd = 0
CStatClr = 0
MaxNum = 13

If I then click Button1 I get:

LNToEd = 7
CStatClr = 7
MaxNum = 7

If I then click Button2 again I get:

LNToEd = 0
CStatClr = 0
MaxNum = 7
This is of coure not my entire application but this is representative of what is happening. I don't get it. The MaxNum and array vars (once

they are Redim'ed when needed) seem to be responding the way I would expect

for
a
var declared with a class level scope. But just these two are giving me troubles. I have hunted through the entire code and there are no other places placing a 0 value in these var that I can see.

Any ideas are appreciated.

thanx
Fred



Nov 20 '05 #4
Let's try this one and I'll include what I expected:
WebApplication
VB.Net 2003

Take Web Form and add two buttons to it.

Following is code cut and pasted :
Public Class LOLoadingBoard
Inherits System.Web.UI.P age
Dim MaxNum As Integer
Dim LNToEd As Integer
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents Button2 As System.Web.UI.W ebControls.Butt on
Dim CStatClr As Integer

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
MaxNum = 1
LNToEd = 2
CStatClr = 3
Response.Write( "MaxNum = " & MaxNum & "<BR>")
Response.Write( "LNToEd = " & LNToEd & "<BR>")
Response.Write( "CStatClr = " & CStatClr & "<BR>")
Response.Write( "-----------------------------------")
Response.Write( " No Buttons<BR>")
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
MaxNum = 4
LNToEd = 5
CStatClr = 6
Response.Write( "MaxNum = " & MaxNum & "<BR>")
Response.Write( "LNToEd = " & LNToEd & "<BR>")
Response.Write( "CStatClr = " & CStatClr & "<BR>")
Response.Write( "-----------------------------------")
Response.Write( " Button 1<BR>")
End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Response.Write( "MaxNum = " & MaxNum & "<BR>")
Response.Write( "LNToEd = " & LNToEd & "<BR>")
Response.Write( "CStatClr = " & CStatClr & "<BR>")
Response.Write( "-----------------------------------")
Response.Write( " Button 2<BR>")
End Sub
End Class

What I expected was:

Form Load gives:
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- No Buttons

Button 1 Press gives:
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- No Buttons
MaxNum = 4
LNToEd = 5
CStatClr = 6
----------------------------------- Button 1

Button 2 Press gives:
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- No Buttons
MaxNum = 4
LNToEd = 5
CStatClr = 6
----------------------------------- Button 2
What I got was:

Form Load gives:
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- No Buttons

Button 1 Press gives:
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- No Buttons
MaxNum = 4
LNToEd = 5
CStatClr = 6
----------------------------------- Button 1

Button 2 Press gives:
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- No Buttons
MaxNum = 1
LNToEd = 2
CStatClr = 3
----------------------------------- Button 2
If I am expecting something that shouldn't be...let me know. Then let me
know how I can modify the values of these variables. I would expect that
vars declared at the class level would be able to be modified by member
subroutines. Their values are accessible so why not modifying the values?

Fred

Nov 20 '05 #5
Hi Fred,

If I am expecting something that shouldn't be...let me know. Then let me
know how I can modify the values of these variables. I would expect that
vars declared at the class level would be able to be modified by member
subroutines. Their values are accessible so why not modifying the values?

Yes you are probably expecting something wrong.

Form load will performed
the showing of 123
After button 1 is done
the form load showing 123
The reseting of the variables
the showing of 456
After button 2 is done
the form load is showing 123
the button 2 is showing 123 (because you do not reset anything)

A form load is always processed.
To prevent that it loads again is the the statement by the way
If not is postback then .........

Remember that you have to instance every time again, you can hold a variable
in a viewstate or in a session. (As well in a shared class and the cache
however those belongs not to the page or the session but to the application,
I would not use those 2 until you have not much expierience with the
behaviour).

I hope this helps?

Cor
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4593
by: Jonathan Perkins | last post by:
How do i create global variables that keep their values after the form is postback, (i.e. when a button is clicked, etc.) Thank you very much.
4
3528
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public myVar as string, etc. It seems to me that the scope and duration are the same, as they both are there while the application is running, and both go away...
5
9249
by: Fred Nelson | last post by:
Hi: I'm a relative newby so hopefully this is a simple question! I have found that I can create global variables easily on a web page by placing the dim statement before the first "private sub" in a program: dim mydata as (whatever) Public Sub Page_Load(etc..)
13
2209
by: Bijoy Naick | last post by:
My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions. Instead of copying each helper function into each aspx page, I am thinking of using a VB Class file to store these. Questions - - How would I "include" this class in each aspx page?
4
1095
by: Dennis D. | last post by:
Visual Studio Code Editor I get a '...not declared' syntax error after the initial variable declaration in any other subs or functions. Dim has module level scope so any subs or functions in the class should recognize iAnything. Why the syntax errors? For example: Class aclass... Private Sub blabla dim iAnything as Integer
5
3141
by: Brett | last post by:
In a class, I have several Private subs. I declare an instance of the class such as: Dim MySelf as new Class1 within a private sub. The motive is to provide access to other subs within the same class. Is this correct? It would be nice to declare the MySelf instance in the Class public space (just under Private Class Class1). That...
4
1499
by: JohnR | last post by:
My situation is that I have a custom user control that I have built into a DLL and put it on the "USER CONTROLS" part of the toolbox, so I can drag it into a form whenever I need it. The problem is that, for a variety of reasons, I need to "see" a variable in all the SUBs that exist in my user control class that is defined in my startup...
3
3345
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can cut/paste it into 2 files and run it to see what I mean. ###############menu.html############### <html> <body> <script type="text/javascript">
6
1540
by: D. Shane Fowlkes | last post by:
I posted this on another forum, and as I feared, the response(s) were too complex and sophisticated. I certainly don't mind learning new methods, in fact, that's why I asked, but I was hoping to emphasize that needed to take small steps. The responses I received talked about Public Classes and DLLs and such. =( I'm tinkering in ASP.NET 2...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.