Home All Groups Group Topic Archive Search About

Passing Values to Subroutines - Empty Returns



Author
25 Apr 2006 3:22 PM
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!

Author
25 Apr 2006 3:44 PM
Anthony Jones
Show quote
"Brian Piotrowski" <bpiotrowski@nospam---simcoeparts.com> wrote in message
news:uIhgDwHaGHA.3736@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"))
Show quote
> %><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.
Author
25 Apr 2006 4:20 PM
Brian Piotrowski
Yup, that was the problem.  After I declared everything, the program worked
as expected.

Thanks for the advice, Anthony.

Brian.


Show quote
"Anthony Jones" <A**@yadayadayada.com> wrote in message
news:uJiAm8HaGHA.3896@TK2MSFTNGP05.phx.gbl...
>
> "Brian Piotrowski" <bpiotrowski@nospam---simcoeparts.com> wrote in message
> news:uIhgDwHaGHA.3736@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.
>
>

AddThis Social Bookmark Button