Passing Values to Subroutines - Empty Returns

B

Brian Piotrowski

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!
 
A

Anthony Jones

Brian Piotrowski said:
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.
 
B

Brian Piotrowski

Yup, that was the problem. After I declared everything, the program worked
as expected.

Thanks for the advice, Anthony.

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top