Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2008, 05:05 PM
Registered User
 
Join Date: Feb 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ATM beginning program

I have tried two ways to get this program to do what i want.
I am going to post both codes along with errors and if anyone could help that would be great. Thanks

Code:
<script language="vb" runat="server">
Sub Page_Load()
DIM balance as decimal
balance = 250.00
End Sub

  Sub Add(sender as object, e As EventArgs , balance)
    lblAnswer.Text = CDbl(tbxInput1.text) + balance
  End Sub

  Sub Subtract(sender as object, e As EventArgs , balance)
    lblAnswer.Text = balance - CDbl(tbxInput2.text)
  End Sub

 
</script>
<html>
  <form runat="server">
    <asp:textbox id="tbxInput1" runat="server" />
    <asp:button id="btnAdd" runat="server" text=" + " Onclick="Add" />
    <asp:button id="btnSubtract" runat="server" text=" – " 
                                                         Onclick="Subtract" />
    <br/>

    <br/>
    <b>Answer = <asp:Label id="lblAnswer" runat="server" /></b>
  </form>
</html>
resulting error:
Quote:
quote:
Line 5: End Sub
Line 6:
Line 7: Sub Add(sender as object, e As EventArgs , balance)
Line 8: lblAnswer.Text = CDbl(tbxInput1.text) + balance
Line 9: End Sub
second try is this

Code:
<script language="vb" runat="server">

Sub page_Load()
if Page.IsPostBack then
Dim intnewbal As Double
 End if
 End sub

Sub Add(sender as object, e As EventArgs)
    DIM newbal as decimal
    DIM lblAnswer as decimal
    newbal = newbal + CDbl(tbxInput1.text)
 lblAnswer.Text = newbal
Session ("newbal") = 0
End Sub

Sub Subtract(sender as object, e As EventArgs)
    DIM newbal as decimal
    newbal = newbal - CDbl(tbxInput1.text)
 lblAnswer.Text = newbal
Session ("newbal") = 0
End if
End Sub


</script>

<html>
<head>
<title>Your ATM Machine</title>
</head>
<body>
  <h1>Welcome to the ATM</h1><br/><br/>
<form id="BalanceForm" method ="post" action="bank.aspx runat="server">
  Current Balance: $
 <span id="bal">0</span>


<asp:textbox id="tbxInput1" runat="server" /><br/>
<asp:Button id="Add2" OnClick="Add" runat="server" Text="Deposit Money"/><br>
<asp:Button id="Subtract2" OnClick="Subtract" runat="server" Text="Withdraw Money"/><br>
New Balance : <%Session ("BalanceCount") %>
 

<input type="Submit">
  </form>

</body>
</html>
resulting error:
Quote:
quote:
Line 11: DIM lblAnswer as decimal
Line 12: newbal = newbal + CDbl(tbxInput1.text)
Line 13: lblAnswer.Text = newbal
Line 14: Session ("newbal") = 0
Line 15: End Sub
Again any help is appreciated.
Thanks
jrb47

 
Old February 28th, 2008, 05:25 PM
Registered User
 
Join Date: Feb 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


I have changed some of the code and am now getting this;

Code:
<script language="vb" runat="server">

Sub page_Load()
if Page.IsPostBack then
Dim intnewbal As Double
Dim lblAnswer as decimal
 End if
 End sub

Sub Add(sender as object, e As EventArgs)
    DIM newbal as decimal
    DIM lblAnswer as decimal
    newbal = newbal + CDbl(tbxInput1.text)
 Session ("newbal") = 0
End Sub

Sub Subtract(sender as object, e As EventArgs)
    DIM newbal as decimal
    newbal = newbal - CDbl(tbxInput1.text)
    DIM lblAnswer as decimal
Session ("newbal") = 0
End Sub


</script>

<html>
<head>
<title>Your ATM Machine</title>
</head>
<body>
  <h1>Welcome to the ATM</h1><br/><br/>
<form id="BalanceForm" method ="post" action="bank.aspx runat="server">
  Current Balance: $
 <span id="bal">0</span>


<asp:textbox id="tbxInput1" runat="server" /><br/>
<asp:Button id="Add2" OnClick="Add" runat="server" Text="Deposit Money"/><br>
<asp:Button id="Subtract2" OnClick="Subtract" runat="server" Text="Withdraw Money"/><br>
New Balance : <%Session ("newbal") %>
 

<input type="Submit">
  </form>

</body>
</html>
resulting error:
Quote:
quote:

Line 39: <asp:Button id="Add2" OnClick="Add" runat="server" Text="Deposit Money"/><br>
Line 40: <asp:Button id="Subtract2" OnClick="Subtract" runat="server" Text="Withdraw Money"/><br>
Line 41: New Balance : <%Session ("newbal") %>
Line 42:
Line 43
any insight helpful
thanks

 
Old February 28th, 2008, 06:21 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think it would help if you posted the actual error message....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old February 28th, 2008, 06:36 PM
Registered User
 
Join Date: Feb 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Actually you might be right:
I have been working on the code and have made some progress. I will post the full error message and the new code

[quote]
 Compiler Error Message: BC30545: Property access must assign to the property or use its value.

Source Error:

Line 39: <asp:Button id="Add2" OnClick="Add" runat="server" Text="Deposit Money"/><br>
Line 40: <asp:Button id="Subtract2" OnClick="Subtract" runat="server" Text="Withdraw Money"/><br>
Line 41: New Balance : <% Session ("CurrentBalance") %> = newbal
Line 42:
Line 43: <input type="Submit">


Source File: \\argofiler.argo.uwf.edu\students\web\jrb47\aspnet \assignment6\test4.aspx Line: 41
[/code]

and the new code
Code:
<script language="vb" runat="server">

Sub page_Load()
if Page.IsPostBack then
Dim intnewbal As Double
Dim lblAnswer as decimal
 End if
 End sub

Sub Add(sender as object, e As EventArgs)
    DIM newbal as decimal
    DIM lblAnswer as decimal
    newbal = newbal + CDbl(tbxInput1.text)
 Session ("newbal") = 0
End Sub

Sub Subtract(sender as object, e As EventArgs)
    DIM newbal as decimal
    newbal = newbal - CDbl(tbxInput1.text)
    DIM lblAnswer as decimal
Session ("newbal") = 0
End Sub


</script>

<html>
<head>
<title>Your ATM Machine</title>
</head>
<body>
  <h1>Welcome to the ATM</h1><br/><br/>
<form id="BalanceForm" method ="post" action="bank.aspx runat="server">
  Current Balance: $
 <span id="bal">0</span>


<asp:textbox id="tbxInput1" runat="server" /><br/>
<asp:Button id="Add2" OnClick="Add" runat="server" Text="Deposit Money"/><br>
<asp:Button id="Subtract2" OnClick="Subtract" runat="server" Text="Withdraw Money"/><br>
<input type="Submit">
  </form>

New Balance : <% Session ("CurrentBalance") %>
</body>
</html>
Any help appreciated.










 
Old February 28th, 2008, 06:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I see. Are you trying to display the value of Session ("CurrentBalance")?

In that case, add an equals sign:

<%= Session ("CurrentBalance") %>

Or are you assigning to it? In that case you need something like:

Session ("CurrentBalance") = Session ("CurrentBalance") + newbal

BTW, it would probably better to use a Label and set its Text from the code as well (like you do with lblAnswer), rather than embedding a Response.Write statement (which is what <%= %> comes down to) in your markup directly.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
C programming ATM Machine mikie1112 C++ Programming 2 May 22nd, 2007 08:25 AM
ATM Machine RaCheer ASP.NET 1.0 and 1.1 Basics 1 February 10th, 2006 07:44 PM
Problem in <Beginning Linux Program > balajirrao Linux 0 October 3rd, 2005 06:06 AM
Setup Project: Program not added in Start>Program arif_1947 VS.NET 2002/2003 2 March 31st, 2005 06:40 AM
Atm program Pa_square C# 0 November 3rd, 2004 06:23 AM





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