473,396 Members | 1,816 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,396 software developers and data experts.

Passing Values to Subroutines - Empty Returns

Hi All,

I'm having a bit of trouble with a subroutine I am calling when it is
invoked for the first time. When the subroutine runs, I expect it to return
a value for every time it is called. However, it seems as though the first
time it is run, I don't get any returned values. However, subsequent
returns will get me something back.

Here is how I am calling the code and the first line it is supposed to
populate with a return value:

<% GetBGColour(rsMATRIX("pad12a")) %>

<td bgcolor="<%response.write(caseclr)%>" align="center"
height="75" class="hugeboldwhitetext"><% Response.Write(rsMATRIX("pad12a"))
%><br>
<table width="100%" align="center">
<tr>
<td bgcolor="<%response.write(caseclr)%>" align="center"
class="regtext"><% Response.Write(rsMATRIX("pad12acom")) %></td>
</tr>
</table>
</td>

And here is the subroutine:

<% Sub GetBGColour(padnumber)
response.write("Pad: " & padnumber & " ")
'This code will check to see if the case is in the current dash. If not,
grey out the box.
If isarray(ICArray) = true Then
chgcolor=0
For kdcase = 0 to UBound(ICArray, 2)
If chgcolor <> 1 Then
If InStr(1,Replace(padnumber,"-",nullchar),ICArray(0,kdcase),1) = 0
Then
caseclr = "#999999"
Else
caseclr = "green"
chgcolor=1
End If
End If
Next
End If

' This code checks the case - if it's been scanned, change the bgcolor
from red to green
If IsArray(CSArray) = true Then
For kdcase = 0 to UBound(CSArray, 2)
If InStr(1,Replace(padnumber,"-",nullchar),CSArray(0,kdcase),1) = 1 Then
caseclr = "red"
End If
Next
End If
response.write("Colour: " & caseclr & "<BR>")
End Sub
%>

Any idea why the first time it is fired it will not return any values, but
it will work with subsequent calls? I know there is a value for CASECLR -
when I use the response.write statements, I see that for the first time it
is called, it does return a value, but the value does not get back to my
"<%response.write(caseclr)%>" statement.

Any ideas?

Thanks!
Apr 25 '06 #1
2 1353

"Brian Piotrowski" <bp*********@nospam---simcoeparts.com> wrote in message
news:uI**************@TK2MSFTNGP04.phx.gbl...
Hi All,

I'm having a bit of trouble with a subroutine I am calling when it is
invoked for the first time. When the subroutine runs, I expect it to return a value for every time it is called. However, it seems as though the first time it is run, I don't get any returned values. However, subsequent
returns will get me something back.

Here is how I am calling the code and the first line it is supposed to
populate with a return value:

<% GetBGColour(rsMATRIX("pad12a")) %>

<td bgcolor="<%response.write(caseclr)%>" align="center"
height="75" class="hugeboldwhitetext"><% Response.Write(rsMATRIX("pad12a")) %><br>
<table width="100%" align="center">
<tr>
<td bgcolor="<%response.write(caseclr)%>" align="center"
class="regtext"><% Response.Write(rsMATRIX("pad12acom")) %></td>
</tr>
</table>
</td>

And here is the subroutine:

<% Sub GetBGColour(padnumber)
response.write("Pad: " & padnumber & " ")
'This code will check to see if the case is in the current dash. If not, grey out the box.
If isarray(ICArray) = true Then
chgcolor=0
For kdcase = 0 to UBound(ICArray, 2)
If chgcolor <> 1 Then
If InStr(1,Replace(padnumber,"-",nullchar),ICArray(0,kdcase),1) = 0
Then
caseclr = "#999999"
Else
caseclr = "green"
chgcolor=1
End If
End If
Next
End If

' This code checks the case - if it's been scanned, change the bgcolor
from red to green
If IsArray(CSArray) = true Then
For kdcase = 0 to UBound(CSArray, 2)
If InStr(1,Replace(padnumber,"-",nullchar),CSArray(0,kdcase),1) = 1 Then caseclr = "red"
End If
Next
End If
response.write("Colour: " & caseclr & "<BR>")
End Sub
%>

Any idea why the first time it is fired it will not return any values, but
it will work with subsequent calls? I know there is a value for CASECLR -
when I use the response.write statements, I see that for the first time it
is called, it does return a value, but the value does not get back to my
"<%response.write(caseclr)%>" statement.

Any ideas?

Thanks!


I'm not even going to attempt to pick through that code. However I will off
you this advice.

Make sure the very first thing that happens in your page is:-

<%
Option Explicit

Now you must Dim all variable before using them.

A variable declared inside a Sub or Function is only available to code
inside that procedure. This is often refered to as 'Local scope'.

A variable declared outside any Sub or Function is available to all code in
any procedure or outside the procedure (this is sometimes refered to a
'Module level scope').
A good coding practice will use a naming standard to differentiate the two
types usually a prefix of 'm_' to any variables declared at the module
level.

I suggest you go through your code and make it conform to these guidelines.
It's likely that you will find the problem in the process and will find
similar issues easier to spot in future.

Anthony.
Apr 25 '06 #2
Yup, that was the problem. After I declared everything, the program worked
as expected.

Thanks for the advice, Anthony.

Brian.
"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:uJ**************@TK2MSFTNGP05.phx.gbl...

"Brian Piotrowski" <bp*********@nospam---simcoeparts.com> wrote in message
news:uI**************@TK2MSFTNGP04.phx.gbl...
Hi All,

I'm having a bit of trouble with a subroutine I am calling when it is
invoked for the first time. When the subroutine runs, I expect it to

return
a value for every time it is called. However, it seems as though the

first
time it is run, I don't get any returned values. However, subsequent
returns will get me something back.

Here is how I am calling the code and the first line it is supposed to
populate with a return value:

<% GetBGColour(rsMATRIX("pad12a")) %>

<td bgcolor="<%response.write(caseclr)%>" align="center"
height="75" class="hugeboldwhitetext"><%

Response.Write(rsMATRIX("pad12a"))
%><br>
<table width="100%" align="center">
<tr>
<td bgcolor="<%response.write(caseclr)%>" align="center"
class="regtext"><% Response.Write(rsMATRIX("pad12acom")) %></td>
</tr>
</table>
</td>

And here is the subroutine:

<% Sub GetBGColour(padnumber)
response.write("Pad: " & padnumber & " ")
'This code will check to see if the case is in the current dash. If

not,
grey out the box.
If isarray(ICArray) = true Then
chgcolor=0
For kdcase = 0 to UBound(ICArray, 2)
If chgcolor <> 1 Then
If InStr(1,Replace(padnumber,"-",nullchar),ICArray(0,kdcase),1) = 0
Then
caseclr = "#999999"
Else
caseclr = "green"
chgcolor=1
End If
End If
Next
End If

' This code checks the case - if it's been scanned, change the bgcolor
from red to green
If IsArray(CSArray) = true Then
For kdcase = 0 to UBound(CSArray, 2)
If InStr(1,Replace(padnumber,"-",nullchar),CSArray(0,kdcase),1) = 1

Then
caseclr = "red"
End If
Next
End If
response.write("Colour: " & caseclr & "<BR>")
End Sub
%>

Any idea why the first time it is fired it will not return any values,
but
it will work with subsequent calls? I know there is a value for
CASECLR -
when I use the response.write statements, I see that for the first time
it
is called, it does return a value, but the value does not get back to my
"<%response.write(caseclr)%>" statement.

Any ideas?

Thanks!


I'm not even going to attempt to pick through that code. However I will
off
you this advice.

Make sure the very first thing that happens in your page is:-

<%
Option Explicit

Now you must Dim all variable before using them.

A variable declared inside a Sub or Function is only available to code
inside that procedure. This is often refered to as 'Local scope'.

A variable declared outside any Sub or Function is available to all code
in
any procedure or outside the procedure (this is sometimes refered to a
'Module level scope').
A good coding practice will use a naming standard to differentiate the two
types usually a prefix of 'm_' to any variables declared at the module
level.

I suggest you go through your code and make it conform to these
guidelines.
It's likely that you will find the problem in the process and will find
similar issues easier to spot in future.

Anthony.

Apr 25 '06 #3

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

Similar topics

1
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
2
by: o1j2m3 | last post by:
I created 2 forms, A and B using VB.NET 2003 in A, the codes are : ========================== public AsName as string public AsPrice as double public sub setValue(ByVal sname as string,...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
1
davydany
by: davydany | last post by:
Hey guys...a n00b Here for this site. I'm making a sequence class for my C++ class. And The thing is in the array that I have, lets say i put in {13,17,38,18}, when i see the current values for the...
5
by: Ludwig | last post by:
I have a user control news.ascx that lists news items, and it has add/edit/delete linkbuttons. This user control is on the default.aspx page together with other user controls. When the edit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.