declaring a variable in CF
4 Message(s) by 3 Author(s) originally posted in cfml getting started
| From: mega_L |
Date: Monday, October 22, 2007
|
I thought when a
variable is needed,
ColdFusion developer can just set it on the fly,
<CFSET var MyVar="assign a value here">
I'm writing a simple UDFs, and didn't declare a variable. The
error I got was
Variable is undefined. Should I declared the variable when it is used within a
function ?
<CFFUNCTION name="InUser">
<CFARGUMENT name="EmpID" required="true" type="numeric">
<CFARGUMENT name="DeptArray" required="true" type="array">
<CFSET NewUserID = 0> ----????????? If Omitted this, I
got error saying NewUserID is Undefined.
.
.
.
<CFSET NewUserID = GetNewUser(UserName)>
.
.
Then I use the value of NewUserID for something else
down
here.
.
.
</CFFUNCTION>
<CFFUNCTION name="GetNewUser">
select statement to get userID based on userName
<CFRETURN #GetID.UserID#>
</CFFUNCTION>
| From: Dan Bracuk |
Date: Monday, October 22, 2007
|
Yes, and you should use the
keyword "var" to keep it local to the function.
| From: cf_dev2 |
Date: Monday, October 22, 2007
|
[b]mega_L[/b]
> I thought when a variable is needed, ColdFusion developer can just set it on the fly
You can [b]mega_L[/b]
> Should I declared the variable when it is used within a function?
Technically you can use variables without declaring them. But with functions
its best to declare local variables using the keyword
VAR to prevent potential
conflicts with other threads.
<CFSET VAR NewUserID = 0>
...
<CFSET NewUserID = GetNewUser(UserName)> [b]mega_L[/b]
> I'm writing a simple UDFs, and didn't declare a variable. The error I got
was Variable is undefined.
>
<CFSET NewUserID = 0> ----????????? If Omitted this, I got error saying
NewUserID is Undefined.
>
<CFSET NewUserID = GetNewUser(UserName)>
...
That suggests a problem in your code. Perhaps the GetNewUser() function does
not return a value, or you have used the variable out of scope or before it was
initialized.
| From: mega_L |
Date: Monday, October 22, 2007
|
Thank you so much for the inpu!
Next Message: Connecting to a remotly hosted database
Blogs related to declaring a variable in CF
php define class
php
declare variable php apache windows config photosmart 707 review php check for null photoshop tutorial digital painting php 4.3.0 photoshop tutorial worn paint photosynthesis middle school activities php download page
...
RE: table union
... September 21, 2007 11:10 AM To:
CF-Talk Subject: RE: table union Depending on your DBMS, I would suggest
declaring a temp table or table
variable (depending on how many records you are expecting). Do two separate inserts into the
...
udf var
Will - the form scope is available to your function already, that's why it says can't
declare variable twice. Try using "frm" or something similar for the name of your argument to avoid confusion. You still pass in the form
...
RE: Shocked!
On 5/21/07, Robertson-Ravo, Neil (RX) wrote: > It would defeat the purpose and wonder of
ColdFusion being typeless etc. No it wouldn't. You still wouldn't have to
declare a
variable as a type of
variable. Just the context to which it
...
1139Chapter 42 .Global Functions and Statements } document ...
Before using any
variable, you should
declare it (and optionally initialize it with a value) via the varstatement. If you omit the varkeyword, the
variable is automatically assigned as a global
variable within the current document.
...
Regular timeout
Do you
declare you application
variable with this amount of time? Travis Haley Haley Computer Solutions 2749 E. Nichols Cir Centennial, CO 80122 P: (303) 694-8050 F: (303) 779-0335 -----Original Message-----
...