|
 |
asp_web_howto thread: Why can't I call function from do while loop?
Message #1 by "Sebastiaan Janssen" <genuine2001@h...> on Mon, 28 Jan 2002 23:34:01
|
|
I made a Do While Loop, in which I'm trying to cal an earlier defined
function, why doesn't that work?
The function does not seem to return a value...
<%
Dim unique
Dim randomID
Function genRandomID(length)
Dim char_array(50)
Dim output, num
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
Randomize
Do While len(output) < length
num = char_array(Int((9 - 0 + 1) * Rnd + 0))
output = output + num
Loop
genRandomID = output
End Function
Do While uniek="false"
randomID = genRandomID(15)
Set rs = Server.CreateObject("ADODB.Recordset")
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="
& Server.MapPath("db/project.mdb")
strSQL = "SELECT ID FROM bestellingen WHERE ID = " &
randomID
rs.Open strSQL,cn,adOpenStatic,adLockOptimistic
If rs.EOF OR rs.BOF Then
unique="true"
Else unique = "false"
End If
Loop
%>
Message #2 by "Sebastiaan Janssen" <genuine2001@h...> on Mon, 28 Jan 2002 23:36:09
|
|
Do While uniek="false"
is supposed to be:
Do While unieue="false"
Sorry!
Message #3 by "Owen Mortensen" <ojm@a...> on Mon, 28 Jan 2002 16:36:11 -0700
|
|
Try this:
output = output & num
Your line
output = output + num
Will ADD instead of concatinate.
Cheers,
Owen
-----Original Message-----
From: Sebastiaan Janssen [mailto:genuine2001@h...]
Sent: Monday, January 28, 2002 11:34 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Why can't I call function from do while loop?
I made a Do While Loop, in which I'm trying to cal an earlier defined
function, why doesn't that work?
The function does not seem to return a value...
<%
Dim unique
Dim randomID
Function genRandomID(length)
Dim char_array(50)
Dim output, num
char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
Randomize
Do While len(output) < length
num = char_array(Int((9 - 0 + 1) * Rnd + 0))
output = output + num
Loop
genRandomID = output
End Function
Do While uniek="false"
randomID = genRandomID(15)
Set rs = Server.CreateObject("ADODB.Recordset")
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="
& Server.MapPath("db/project.mdb")
strSQL = "SELECT ID FROM bestellingen WHERE ID = " &
randomID
rs.Open strSQL,cn,adOpenStatic,adLockOptimistic
If rs.EOF OR rs.BOF Then
unique="true"
Else unique = "false"
End If
Loop
%>
$subst('Email.Unsub').
Message #4 by "Sebastiaan Janssen" <genuine2001@h...> on Mon, 28 Jan 2002 23:56:59
|
|
Thanks Owen,
The problem is that the function works perfectly when I don't call it
from the Do While loop..
So the function works fine, except that it doesn't allow to be called
from within the loop?
I can't put the whole function in the loop either...
It's driving me crazy! :)
> Try this:
>
> output = output & num
>
> Your line
>
> output = output + num
>
> Will ADD instead of concatinate.
>
> Cheers,
> Owen
Message #5 by "Owen Mortensen" <ojm@a...> on Mon, 28 Jan 2002 17:18:34 -0700
|
|
It's a good idea anyway to use "&" instead of "+" so it's obvious what
you're trying to do.
BY THE WAY, figured out what's wrong with the code snippet: you never
set unique equal to "false" so the loop is never entered....
Owen
-----Original Message-----
From: Sebastiaan Janssen [mailto:genuine2001@h...]
Sent: Monday, January 28, 2002 11:57 PM
To: ASP Web HowTo
Subject: [asp_web_howto] RE: Why can't I call function from do while
loop?
Thanks Owen,
The problem is that the function works perfectly when I don't call it
from the Do While loop..
So the function works fine, except that it doesn't allow to be called
from within the loop?
I can't put the whole function in the loop either...
It's driving me crazy! :)
> Try this:
>
> output = output & num
>
> Your line
>
> output = output + num
>
> Will ADD instead of concatinate.
>
> Cheers,
> Owen
$subst('Email.Unsub').
Message #6 by "Sebastiaan Janssen" <genuine2001@h...> on Tue, 29 Jan 2002 00:38:02
|
|
D'Oh!!
;-)
Thanks, that did the trick!
I'm so stupid! :)
Greets,
Sebastiaan
> It's a good idea anyway to use "&" instead of "+" so it's obvious what
> you're trying to do.
>
> BY THE WAY, figured out what's wrong with the code snippet: you never
> set unique equal to "false" so the loop is never entered....
>
> Owen
|
|
 |