Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old November 3rd, 2004, 10:08 PM
dimez dimez is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Orlando
Posts: 6 dimez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help with incrementing variable

I am not sure what I am doing wrong...
I am trying to increment a variable but each time it will only increment once and then resets to 0

I have declared a variable in the class section of my codebehind.vb of my aspx page

public class webform1
...
dim i as integer
...

I have to buttons that trigger subs (fwd and back) which should increment the variable by 1 each time

sub goFwd()
....
i = i + 1
....
end sud

sub goBack()
...
i = i - 1
...

But no matter how many times I click the button to trigger goFwd, i always = 1, it doesnt seem to increment the value each time.

If any can understand what I mean here and can help me, it would be greatly appreciated.

Reply With Quote
  #2  
Old November 3rd, 2004, 11:24 PM
SoberButCrazy SoberButCrazy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 15 SoberButCrazy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If the coding is done properly it will work fine. Make sure the variable is declared globally and isnt being interfered with by another command.

Public I as integer

I += 1 or I -= 1

This could be your problem

Reply With Quote
  #3  
Old November 4th, 2004, 07:04 AM
dimez dimez is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Orlando
Posts: 6 dimez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I believe it is coded properly...here is what I've got, it still doesnt work

Public Class WebForm2

Inherits System.Web.UI.Page
Public i as integer

.....


Private sub Page_Load(.....) handles MyBase.load

response.write(i)

end sub


sub goFwd(......)

i += 1

response.write(i)

end sub

end class


everytime I click the button to trigger goFwd, I got a 01, the 0 from Page_Load and 1 from goFwd, it wont go to 2 or 3 or anything else, any ideas what I might be doing wrong? I know this is simple and everything looks fine to me but still wont work for some reason, Im sure im gonna kick myself when I find the solution....

Reply With Quote
  #4  
Old November 4th, 2004, 07:43 PM
SoberButCrazy SoberButCrazy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 15 SoberButCrazy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try putting Public Shared I as integer instead. Also double check and make sure you are not using (i) anywhere else. From what I can see, it should work fine. You could also create a function an pass the integer back and forth. Not recommended though.

Reply With Quote
  #5  
Old November 4th, 2004, 09:43 PM
dimez dimez is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Orlando
Posts: 6 dimez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I found what I was doing wrong..

Class member variables are not stored in the ViewState by default so each time the page loads or postbacks, a new instance of the class is created which kept intializing my i variable back to zero. So I had to use this in my Page Load event

if not IsNothing(Viewstate("i")) Then


i = Viewstate("i")


else


i = 0


Viewstate.Add("i", i)


End If


and then also call ViewState("i") = i after each time I changed the value.


Thank you much for taking the time to try to help me, happy programming!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Help with incrementing variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway