473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Stange effects?

One of our students wrote on a vb web form
Public intIndex As Integer = 0
Private Sub btSet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btSet.Click
intIndex = 2
lblOriginal.Text = "intIndex = : " & CType(intIndex, String)
End Sub
Private Sub btAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btAdd.Click
intIndex += intIndex
lblResult.Text = "intIndex = : " & CType(intIndex, String)
End Sub

Clicking on the button set wil seed the integer int Index with 2
Clicking on the Add button adss the index to it's self
Both times de value is displayed on the screen.
Strait forward no?
Cliking the btAdd displays a "0" Why?????
--
Voor mensen en machines die werken
http://ww.highpotech.nl
Nov 17 '05 #1
3 1173
I'm not sure I understand the question. You have 2 buttons on the page, both
of which display a calculated result from an integer field value that is
initialized to 0. The first button's Event Handler sets the value of the
integer to 2, and displays that value (2). The second button's Event Handler
doubles the value of the same integer and displays that. Therefore, as the
integer is initialized to 0, if you click the first button and then the
second, the second will display 4 (2 + 2). If you click the second button
first, the second will display 0 (0 + 0). Is there a problem with that?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"Alexander M. Polak" <am******@highpotech.nl> wrote in message
news:bi**********@news.hccnet.nl...
One of our students wrote on a vb web form
Public intIndex As Integer = 0
Private Sub btSet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btSet.Click
intIndex = 2
lblOriginal.Text = "intIndex = : " & CType(intIndex, String)
End Sub
Private Sub btAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btAdd.Click
intIndex += intIndex
lblResult.Text = "intIndex = : " & CType(intIndex, String)
End Sub

Clicking on the button set wil seed the integer int Index with 2
Clicking on the Add button adss the index to it's self
Both times de value is displayed on the screen.
Strait forward no?
Cliking the btAdd displays a "0" Why?????
--
Voor mensen en machines die werken
http://ww.highpotech.nl

Nov 17 '05 #2
Hello

The value int the integer value is not saved between trips to the server, so
every time it is initialized to zero.
To save the value, use the ViewState collection, then retrieve the value in
the Load event

Regards

"Alexander M. Polak" <am******@highpotech.nl> wrote in message
news:bi**********@news.hccnet.nl...
One of our students wrote on a vb web form
Public intIndex As Integer = 0
Private Sub btSet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btSet.Click
intIndex = 2
lblOriginal.Text = "intIndex = : " & CType(intIndex, String)
End Sub
Private Sub btAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btAdd.Click
intIndex += intIndex
lblResult.Text = "intIndex = : " & CType(intIndex, String)
End Sub

Clicking on the button set wil seed the integer int Index with 2
Clicking on the Add button adss the index to it's self
Both times de value is displayed on the screen.
Strait forward no?
Cliking the btAdd displays a "0" Why?????
--
Voor mensen en machines die werken
http://ww.highpotech.nl

Nov 17 '05 #3
Yes thanks
Found te same answer just a minute ago.
Even if public every trip around the integer is reset again to the old value

"Sherif ElMetainy" <el******@wayout.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello

The value int the integer value is not saved between trips to the server, so every time it is initialized to zero.
To save the value, use the ViewState collection, then retrieve the value in the Load event

Regards

"Alexander M. Polak" <am******@highpotech.nl> wrote in message
news:bi**********@news.hccnet.nl...
One of our students wrote on a vb web form
Public intIndex As Integer = 0
Private Sub btSet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btSet.Click
intIndex = 2
lblOriginal.Text = "intIndex = : " & CType(intIndex, String)
End Sub
Private Sub btAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btAdd.Click
intIndex += intIndex
lblResult.Text = "intIndex = : " & CType(intIndex, String)
End Sub

Clicking on the button set wil seed the integer int Index with 2
Clicking on the Add button adss the index to it's self
Both times de value is displayed on the screen.
Strait forward no?
Cliking the btAdd displays a "0" Why?????
--
Voor mensen en machines die werken
http://ww.highpotech.nl


Nov 17 '05 #4

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

Similar topics

1
by: Adam Teasdale Hartshorne | last post by:
Using the code below I get a very stange result. I assume that I must be doing something wrong, but I can't figure out what it is. getTriangleEdges(t,t1e) ; for (int i = 0 ; i <...
47
by: Lauren Quantrell | last post by:
I have constructed the following code that simulates the common rollover effect when moving the mouse over a label (this example makes the label bold.) I'm wondering if anyone has come up with...
23
by: Mantorok Redgormor | last post by:
Can emulation of the logical OR be done in standard C to obfuscate its use? So I don't have to use if(a||b) but instead make that even more obfuscated without its use but testing the same condition
9
by: Rouben Rostamian | last post by:
Consider the following illustrative program: #include <stdio.h> double f(double x) { return x*x; } double g(double x)
11
by: Sweety | last post by:
hello to all members, i have strange question in C. main() { printf("%d",main) ; } here o/p is same for all m/c in TC++ version 3.0 i.e 657. I think this is not garbage.
5
by: Niklaus | last post by:
This is one of the posts that i got. ------------------------------ A "side effect" of an operation is something that *happens*, not something that *is produced*. Examples: In the expression...
20
by: cwdjrxyz | last post by:
There have been fancy dhtml text effects since the early days of javascript. The rainbow text effect was one of the early ones. While some such effects may be fun on private pages, they can easily...
6
by: Senthil | last post by:
Hi, Whenever i read a C++ book or a newsgroup posting, i come across the terms like " before the side effects completes" , "destructor with side effects" etc. What is this side effect mean in C++...
0
MJMF
by: MJMF | last post by:
Streaming: how can i make an audio streaming to transmit the voice through a radio station to make the people listen by a web site. by C# please replay, help me MP3 audio effects: how can i...
4
by: Academia | last post by:
I get the following watch message: tsSource.Text.ToUpper() This expression causes side effects and will not be evaluated string The Text is &Edit
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.