473,467 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to update variables in SUB

Variable ta, tb, tc, td and te are not updated in the SUB WriteTableDetail.
As a result, Response write of the ta, tb, tc td and te displays 0.

Sub Page_load(Src AS Object, e AS EventArgs)
IF Request.QueryString("lnk_a") = "1" OR Request.QueryString("lnk_a") =
"3" OR Request.QueryString("lnk_a") = "4" THEN
Main_Program
END IF
END SUB

Sub Main_Program
Dim a AS Integer = 0
Dim b AS Integer = 0
Dim c AS Integer = 0
Dim d AS Integer = 0
Dim e AS Integer = 0
Dim ta AS Integer = 0
Dim tb AS Integer = 0
Dim tc AS Integer = 0
Dim td AS Integer = 0
Dim te AS Integer = 0
Dim I1 AS Integer = 0
Response.Write("<TABLE WIDTH=1300 BORDER=1 CELLSPACING=0 CELLPADDING=0
style=font-family: Arial; font-size: 8pt>")
DO While I1 <= DS1.Tables(0).Rows.Count - 1
IF DS1.Tables(0).Rows(I1).item(4) = "CN" THEN
a = a + 1
ELSE
IF DS1.Tables(0).Rows(I1).item(4) = "IF" THEN
b = b + 1
ELSE
c = c + 1
END IF
END IF
IF DS1.Tables(0).Rows(I1).item(5) = "Y" THEN
d = d + 1
ELSE
e = e + 1
END IF
IF Request.QueryString("lnk_a") = "1" THEN
IF a < 1 AND b > 0 THEN
WriteTableDetail(a, b, c, d, e, ta, tb, tc, td, te)
END IF
ELSE
IF Request.QueryString("lnk_a") = "2" THEN
IF a - b> 1 THEN
WriteTableDetail(a, b, c, d, e, ta, tb, tc, td, te)
END IF
END IF
END IF
I1 = I1 + 1
Loop
Response.Write("<TR >")
Response.Write("<td ALIGN=RIGHT>" & ta & "</td>")
Response.Write("<td ALIGN=RIGHT>" & tb & "</td>")
Response.Write("<td ALIGN=RIGHT>" & tc & "</td>")
Response.Write("<td ALIGN=RIGHT>" & td & "</td>")
Response.Write("<td ALIGN=RIGHT>" & te & "</td>")
Response.Write("</TR >")
Response.Write("</TABLE>")
END SUB

SUB WriteTableDetail
ta = ta + a
tb = tb + b
tc = tc + c
td = td + d
te = te + e
Response.Write("<TR >")
Response.Write("<td ALIGN=RIGHT>" & a & "</td>")
Response.Write("<td ALIGN=RIGHT>" & b & "</td>")
Response.Write("<td ALIGN=RIGHT>" & c & "</td>")
Response.Write("<td ALIGN=RIGHT>" & d & "</td>")
Response.Write("<td ALIGN=RIGHT>" & e & "</td>")
Response.Write("</TR >")
END SUB
Nov 19 '05 #1
1 1123
Hi!

First of all, always use Option Explicit in your work. It makes the compiler
tell you when you do mistakes like this one. ;) For information about how to
do this, see these pages:
http://msdn.microsoft.com/library/en...asp?frame=true
http://msdn.microsoft.com/library/en...asp?frame=true

Your a-e and ta-td variables is local to the Main_Program method. The
variables you reference in the WriteTableDetail method are created each time
you call it. If you'd used Option Explicit, the application wouldn't compile
at all.

Anyway, to solve the problem, move the variables out of Main_Program and
make them member variables in the page. I'm not 100% sure of the VB syntax,
but it should look something like this:

public class YourPage
implements....

' Declare your variables outside the methods
public a As Integer = 0
public b As Integer = 0
... ' the rest
public td As Integer = 0

Sub Page_load(Src As Object, e As EventArgs)
' don't dim the variables here
Response.Write...

HTH,
Lars-Erik

"Bill Patel" <bp****@golden-isles.com> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
Variable ta, tb, tc, td and te are not updated in the SUB
WriteTableDetail.
As a result, Response write of the ta, tb, tc td and te displays 0.

Sub Page_load(Src AS Object, e AS EventArgs)
IF Request.QueryString("lnk_a") = "1" OR Request.QueryString("lnk_a") =
"3" OR Request.QueryString("lnk_a") = "4" THEN
Main_Program
END IF
END SUB

Sub Main_Program
Dim a AS Integer = 0
Dim b AS Integer = 0
Dim c AS Integer = 0
Dim d AS Integer = 0
Dim e AS Integer = 0
Dim ta AS Integer = 0
Dim tb AS Integer = 0
Dim tc AS Integer = 0
Dim td AS Integer = 0
Dim te AS Integer = 0
Dim I1 AS Integer = 0
Response.Write("<TABLE WIDTH=1300 BORDER=1 CELLSPACING=0 CELLPADDING=0
style=font-family: Arial; font-size: 8pt>")
DO While I1 <= DS1.Tables(0).Rows.Count - 1
IF DS1.Tables(0).Rows(I1).item(4) = "CN" THEN
a = a + 1
ELSE
IF DS1.Tables(0).Rows(I1).item(4) = "IF" THEN
b = b + 1
ELSE
c = c + 1
END IF
END IF
IF DS1.Tables(0).Rows(I1).item(5) = "Y" THEN
d = d + 1
ELSE
e = e + 1
END IF
IF Request.QueryString("lnk_a") = "1" THEN
IF a < 1 AND b > 0 THEN
WriteTableDetail(a, b, c, d, e, ta, tb, tc, td, te)
END IF
ELSE
IF Request.QueryString("lnk_a") = "2" THEN
IF a - b> 1 THEN
WriteTableDetail(a, b, c, d, e, ta, tb, tc, td, te)
END IF
END IF
END IF
I1 = I1 + 1
Loop
Response.Write("<TR >")
Response.Write("<td ALIGN=RIGHT>" & ta & "</td>")
Response.Write("<td ALIGN=RIGHT>" & tb & "</td>")
Response.Write("<td ALIGN=RIGHT>" & tc & "</td>")
Response.Write("<td ALIGN=RIGHT>" & td & "</td>")
Response.Write("<td ALIGN=RIGHT>" & te & "</td>")
Response.Write("</TR >")
Response.Write("</TABLE>")
END SUB

SUB WriteTableDetail
ta = ta + a
tb = tb + b
tc = tc + c
td = td + d
te = te + e
Response.Write("<TR >")
Response.Write("<td ALIGN=RIGHT>" & a & "</td>")
Response.Write("<td ALIGN=RIGHT>" & b & "</td>")
Response.Write("<td ALIGN=RIGHT>" & c & "</td>")
Response.Write("<td ALIGN=RIGHT>" & d & "</td>")
Response.Write("<td ALIGN=RIGHT>" & e & "</td>")
Response.Write("</TR >")
END SUB

Nov 19 '05 #2

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

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
2
by: KathyB | last post by:
Hi, figured out where I was going wrong in my post just prior, but is there ANY way I can assign several variables to then use them in an Update statement, for example (this does not work): ...
1
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
4
by: gooday | last post by:
Table test2 has multiple amounts for each account, I would like to sum the amounts for the same account and use the result to update the variable 'tot_amount' in table test1. But SQL does not allow...
5
by: Alastair Anderson | last post by:
I have created a very simple form with which I would like to update a single value in a single row of a database as a proof of concept. The relevant parts of the form are a DBWebTextBox (which...
2
by: Elmo | last post by:
I've got a situation where I'm trying to fix an existing table - - The Fname Field has both First & Last Names... So - I've populated a Dataset with the ID, First and Last names - - - I'm...
3
by: Jerry | last post by:
Well, here is some weirdness. First, I noticed that I have 2 Set keywords (silly me). so I removed the 2nd "Set" but still got a syntax error. Then I removed the Where clause, and now it works...
1
tolkienarda
by: tolkienarda | last post by:
i need to update a database table using variables in unusual places here are the update statements mysql_query("UPDATE 'grades' SET '$class' = '$grade' WHERE student='$student'");...
0
by: Chris McCormick | last post by:
Hi, I'm looking for a solution to a concurrency problem I have. I would like to have multiple objects with an Update() method. This Update method might access the contents of other objects. I...
5
by: =?Utf-8?B?UlBhcmtlcg==?= | last post by:
I used the wizard to generate a typed dataset for my table and let it create my SPROCs. It created everything, and the GetData() method and the custom GetByUserName query works great, but when I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.