Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 28th, 2012, 11:40 PM
Authorized User
Points: 350, Level: 6
Points: 350, Level: 6 Points: 350, Level: 6 Points: 350, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Location: Eastern Michigan-Near Canada
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default Trying to increment a counte

Okay, I give up, well not really. But I have four data fields that are to be filled and the data is put into a nice array, to have calculations done on the numbers when the array is done. I set up a counter field to start the program, so onece you enter 'number of capacitors' then what is displayed are four text fields to fill out for capacitor 1. Then a 'Next' button is clicked to clear the text fields and to show capacitor 2. But when I fill out the data fields and click 'Next' I get show capacitor 2 again. The simple counter which is Dim at 1 increments to 2 each time Next is clicked, but never gets past 2.

I have setup:

Quote:
<%@ Page Title="" Language="VB" MasterPageFile="~/CoilCalcsMaster.master" AutoEventWireup="false" CodeFile="capacitor-calculations.aspx.vb" Inherits="capacitor_calculations" EnableViewState="true" ViewStateMode="Disabled"%>
And then I have enabled ViewStateMode on individual controls where I thought I could get the counter to increment but never does!
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
Reply With Quote
  #2 (permalink)  
Old July 29th, 2012, 02:05 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

As a former member of this site used to say:

>> the error is online 11
> how do you know? I didn't post any code.
Exactly!

In other words, impossible to say without seeing your code.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old July 29th, 2012, 07:32 AM
Authorized User
Points: 350, Level: 6
Points: 350, Level: 6 Points: 350, Level: 6 Points: 350, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Location: Eastern Michigan-Near Canada
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

Hi Imar, glad to see you here, and thank you. Yes, I should have posted the code. So here is the code for the click event of the Next button I have. Variable C I have dimension as DIM C as Integer = 1. I first ask the user to tell me how many different capacitor groups he has. This number is stored in C and then I have a submit button that sets up the four text boxes shown below in the code. So if the user put 5 in the textbox to submit then the below routine should run and increment C each time. But C gets incremented to 2 and stays at 2. Each time I press the Next button C goes back to 1!

Code:
Protected Sub btnNextCap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNextCap.Click
    KR(C) = Val(txtKVAR.Text)
    VR(C) = Val(txtVoltage.Text)
    FR(C) = Val(txtFreq.Text)
    Q(C) = Val(txtHowManyThese.Text)

    'Clear the textbox values now.
    txtKVAR.Text = ""
    txtVoltage.Text = ""
    txtFreq.Text = ""
    txtHowManyThese.Text = ""



    If C = intNoCap Then
      btnNextCap.Enabled = False
      CapCalc()
    Else
    End If

    AR(C) = Q(C) * 1000 * KR(C) / VR(C)
    XC(C) = VR(C) / AR(C)
    MF(C) = 1000000.0! / (2 * 3.14159 * FR(C) * XC(C))

    If C = Val(txtNoCapacitors.Text) Then
      btnNextCap.Enabled = False
      'Run Calcs.
      CapCalc()

    Else

    End If

    C = C + 1
    lblCapNo.Text = "Capacitor number " & C.ToString


    

  End Sub
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
Reply With Quote
  #4 (permalink)  
Old July 29th, 2012, 07:46 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you post *all* relevant code? I don't see you declare C.

Also: a Page instance is created every time you request a page, also after a PostBack. So if C is a simple class based variable, it'll automatically be recreated (and thus set to its initial value) on each reqeust. Use ViewState, a hidden field or another state mechanism to maintain its value.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old July 29th, 2012, 08:15 AM
Authorized User
Points: 350, Level: 6
Points: 350, Level: 6 Points: 350, Level: 6 Points: 350, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Location: Eastern Michigan-Near Canada
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

I just noticed that I had this bit of code in twice.

Code:
If C = intNoCap Then
      btnNextCap.Enabled = False
      CapCalc()
    Else
    End If

    AR(C) = Q(C) * 1000 * KR(C) / VR(C)
    XC(C) = VR(C) / AR(C)
    MF(C) = 1000000.0! / (2 * 3.14159 * FR(C) * XC(C))

    If C = Val(txtNoCapacitors.Text) Then
      btnNextCap.Enabled = False
      'Run Calcs.
      CapCalc()
I changed this to but it didn't change anything with the C counter.

Code:
AR(C) = Q(C) * 1000 * KR(C) / VR(C)
    XC(C) = VR(C) / AR(C)
    MF(C) = 1000000.0! / (2 * 3.14159 * FR(C) * XC(C))

    If C = intNoCap Then
      btnNextCap.Enabled = False
      CapCalc()
    Else
    End If
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
Reply With Quote
  #6 (permalink)  
Old July 29th, 2012, 08:21 AM
Authorized User
Points: 350, Level: 6
Points: 350, Level: 6 Points: 350, Level: 6 Points: 350, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Location: Eastern Michigan-Near Canada
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

Here is all the code except for the CapCalc sub, which isn't finished anway!

Code:
Partial Class capacitor_calculations
  Inherits System.Web.UI.Page

  Dim C As Integer = 1

  Dim VR(25) As Decimal
  Dim FR(25) As Decimal
  Dim Q(25) As Decimal
  Dim AR(25) As Decimal
  Dim KR(25) As Decimal
  Dim MF(25) As Decimal
  Dim XC(25) As Decimal
  Dim TC As Decimal = 0

  Dim intNoCap As Integer
  

  Protected Sub btnNextCap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNextCap.Click
    KR(C) = Val(txtKVAR.Text)
    VR(C) = Val(txtVoltage.Text)
    FR(C) = Val(txtFreq.Text)
    Q(C) = Val(txtHowManyThese.Text)

    'Clear the textbox values now.
    txtKVAR.Text = ""
    txtVoltage.Text = ""
    txtFreq.Text = ""
    txtHowManyThese.Text = ""


    AR(C) = Q(C) * 1000 * KR(C) / VR(C)
    XC(C) = VR(C) / AR(C)
    MF(C) = 1000000.0! / (2 * 3.14159 * FR(C) * XC(C))

    If C = intNoCap Then
      btnNextCap.Enabled = False
      CapCalc()
    Else
    End If

    C = C + 1
    lblCapNo.Text = "Capacitor number " & C.ToString
 

  End Sub

  Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    intNoCap = Val(txtNoCapacitors.Text)
    btnSubmit.Enabled = False
    txtNoCapacitors.Enabled = False

    lblNoCapacitors.Text = "How many capacitors used?"
    txtNoCapacitors.Visible = True
    lblCapNo.Text = "Capacitor number " & C.ToString
    ' lblNoCapacitors.Enabled = False 'Once next is clicked, disable changing this value.
    lblKVAR.Text = "Rated KVAR"
    txtKVAR.Visible = True
    lblVoltage.Text = "Rated voltage"
    txtVoltage.Visible = True
    lblFreq.Text = "Rated Frequency"
    txtFreq.Visible = True
    lblHowManyThese.Text = "How many of this capacitor type?"
    txtHowManyThese.Visible = True

  End Sub
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
Reply With Quote
  #7 (permalink)  
Old July 29th, 2012, 08:31 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Code:
Partial Class capacitor_calculations   Inherits System.Web.UI.Page    Dim C As Integer = 1
See my previous reply; since you implemented C (great name!) as a class based variable, it'll be recreated and reset to 1 every time the page loads. You enabled View State on the controls, but since Integer is not a control, that doesn't help.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #8 (permalink)  
Old July 29th, 2012, 08:59 AM
Authorized User
Points: 350, Level: 6
Points: 350, Level: 6 Points: 350, Level: 6 Points: 350, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Location: Eastern Michigan-Near Canada
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by Imar View Post
[CODE]since you implemented C (great name!) as a class based variable,
Yes, C is a great name, I considered changing to counter & prob. should here. The formulas are old time tested, but written long ago. I have over a thousand of these to work with, sometimes it's less confusing to paste the formulas in, I do change the names often, but the time allotted for this doesn't allow it.

I will have to figure how to do 'hidden state' not really sure how that works. But I will Google it! Thanks Imar! Hope you are enjoying the Olympics. I am hoping the Michael Phelps can make a comeback Monday and beat the world record in medals. He really put his heart into this the first two Olympics and he had setbacks and done some stupid things, but I think his determination to excel is a good role model!
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
Reply With Quote
  #9 (permalink)  
Old July 29th, 2012, 10:21 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I have over a thousand of these to work with, sometimes it's less confusing to paste the formulas in
Ah, that explains it. Makes sense.

Quote:
I will have to figure how to do 'hidden state' not really sure how that works. But I will Google it!
To help you figure it out, and save you some time, I wrote you a quick article explaining the basic concept. You can find the article here: http://imar.spaanjaars.com/570/imple...ate-properties

Quote:
Hope you are enjoying the Olympics.
Haven't seen much yet, but hopefully I find some time to see some of it.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #10 (permalink)  
Old July 29th, 2012, 10:48 AM
Authorized User
Points: 350, Level: 6
Points: 350, Level: 6 Points: 350, Level: 6 Points: 350, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2010
Location: Eastern Michigan-Near Canada
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by Imar View Post
To help you figure it out, and save you some time, I wrote you a quick article explaining the basic concept. You can find the article here: http://imar.spaanjaars.com/570/imple...ate-properties
Thank you Imar, I have printed this and will study it. The original program goes back to DOS days, so I had to modify how the user interacted.
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Increment button Mark P. C# 4.0 aka C# 2010 General Discussion 3 May 1st, 2014 04:31 PM
Increment a tag stefan.yu XSLT 10 April 16th, 2007 05:45 AM
How to auto increment ? Shawn Mohan SQL Server 2000 2 June 22nd, 2006 03:00 AM
How to auto increment? Shawn Mohan ASP.NET 2.0 Basics 6 June 20th, 2006 10:36 PM
Is it possible to increment in crystal cmdolcet Crystal Reports 2 August 14th, 2005 06:55 PM



All times are GMT -4. The time now is 10:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.