Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable problem

Status
Not open for further replies.

Benbunny

Programmer
Mar 19, 2001
18
0
0
HK
Dear all,

I would like to ask for help about the following coding in the action form which being called from the other form.


<cfoutput>
<cfset tDes = 'form.iDes'>
<cfset tSeqNo = 'form.iSeqNo'>

<cfquery name=&quot;updateItem&quot; datasource=&quot;DB&quot;>
update Item
set Des='#tDes#'
where ItemNo = '#form.iItemNo#'
and SeqNo = '#tSeqNo#'
</cfquery>
</cfoutput>

Thanks a lot.

 
If you do
Code:
<cfset tDes = 'form.iDes'>
and then output it:
Code:
#tDes#
you will find that you get

form.iDes

That is because you have quotes around it. Quotes will allow you to set tDes to the string &quot;form.iDes&quot; rather than the value of form.iDes. Try this instead (you don't need those extra variables or the cfoutput tags):
Code:
<cfquery name=&quot;updateItem&quot; datasource=&quot;DB&quot;>
update Item
set Des='#form.iDes#'  
where ItemNo = '#form.iItemNo#'
and SeqNo = '#form.iSeqNo#'
</cfquery>
If you need the variable names for some reason, just set them without the quotes (use of pound signs is optional, though not preferable). Try either:
Code:
<cfset tDes = form.iDes>    
<cfset tDes = #form.iDes#>
Sorry that was a little longwinded!
 
Thanks Glowball,

But really have my reason to do so...

And the varible value should be generated dynamically like as follows,

<cfset tDes = 'iDes' & ToString(LSNumberFormat(#tcounter#, 000))>

As I tried,
<cfset tDes = 'iDes' & ToString(LSNumberFormat(#tcounter#, 000))>
<cfset tDes1 = #tDes#>
<cfset tSeqNo = 'iSeqNo' & ToString(LSNumberFormat(#tcounter#, 000))>
<cfset tSeqNo1 = #tSeqNo#>

<cfquery name=&quot;updateItem&quot; datasource=&quot;DB&quot;>
update Item
set Des='#tDes1#'
where ItemNo = '#form.iItemNo#' and SeqNo = '#tSeqNo1#'
</cfquery>

But it is not work as well, can you help me??

Thanks!!
 
Well, ToString() is not a ColdFusion function so that won't work. Try this:
Code:
<cfset tDes = &quot;iDes&quot; & LSNumberFormat(tcounter, &quot;000&quot;)>
<cfset tDes1 = VARIABLES.tDes>
<cfset tSeqNo = &quot;iSeqNo&quot; & LSNumberFormat(tcounter, &quot;000&quot;)>
<cfset tSeqNo1 = VARIABLES.tSeqNo>
You might want to also put a scope on
Code:
tcounter
(I didn't know if it was a variable or coming from a form or whatever). Let me know if that doesn't work for you.
 
Actually the ToString() is works fine. It can really build up the variable name I want. But now the problem I facing is I can't get the value of the variable.

update Item set Des = '#tDes1#' where ItemNo = '#form.iItemNo#' and SeqNo = '#tSeqNo1#'

The result of the SQL I tried to display as follows,

update Item set Des = 'form.iDes001' where ItemNo = '000006' and SeqNo = 'form.iSeqNo001'

And also I have tried the command you provided 'VARIABLES', the result is also the same...Thanks!


 
Oh maybe you have CF 5 -- we aren't using that yet so we don't have user-defined functions. ToString() must be one of yours?

I think I don't know enough of what you're doing to help, maybe. When you first set tDes it would equal something like
Code:
iDes002
if I look at your example from before. Then you set tDes1 to the same string. Now in your example you have it equaling the string
Code:
form.iDes001
but that isn't what you want, right? I'm thinking that we're going about this the long way because we haven't looked at everything from start to finish, but if you want the &quot;form&quot; strings to actually be the form values, try this:
Code:
update Item set Des = '#Evaluate(tDes1)#' where ItemNo = '#form.iItemNo#' and SeqNo = '#Evaluate(tSeqNo1)#'
Though if you want we could go through it from the top to the bottom because it seems like you have a lot of variables all over the place. Let me know if you'd like to do this, no biggie.
 
Thanks Glowball, it works now.
Sorry for my unclarify question to make this simple problem for so long time.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top