473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Help with "cannot assign string" error


I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

If I try

curHvals = "03" ; // (derived from index to provide leading zero)

( "this.fh" +curHvals + ".value" ) = fixFloat(Harms[ii],numPoints)
I get a [ Cannot assign string to 'string "this.fh03.value" ' error. ]

The right side of the equation works just fine elsewhere.
As does this.fh03.value elsewhere.

eval (...) does not work as it looks up the previous fh03 value rather
than replacing it with a new one.

What is the correct way to programatically loop calculated values with
fancy names?

Is there a command for string to named variable conversion?

--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #1
6 4071
Don Lancaster wrote:
>
I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.
Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);

--
Ian Collins.
Apr 29 '07 #2
Don Lancaster wrote:
>
I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

If I try

curHvals = "03" ; // (derived from index to provide leading zero)

( "this.fh" +curHvals + ".value" ) = fixFloat(Harms[ii],numPoints)
I get a [ Cannot assign string to 'string "this.fh03.value" ' error. ]
That seems a fairly clear and obvious error report.
The right side of the equation works just fine elsewhere.
No, there are no circumstances where you can assign a value to a string.
As does this.fh03.value elsewhere.
Your - this.fh03.value - is a property accessor and so can be the
destination for an assignment.
eval (...) does not work as it looks up the previous fh03
value rather than replacing it with a new one.
Eval would 'work' if you evaled the entire expression, but assigning to
the return value of a function call is not ever allowed (and not ever
meaningful).
What is the correct way to programatically loop calculated
values with fancy names?
Using bracket nation property accessors instead of dot notation property
accessors:-

<URL: http://jibbering.com/faq/#FAQ4_39 >
Is there a command for string to named variable conversion?
Variable names are strings, but - this.fh03.value - is a property
accessor not a variable name.

Richard.

Apr 29 '07 #3
Ian Collins wrote:
Don Lancaster wrote:
>>I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.


Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);
Looks like an interesting approach.

Except it returns "undefined" for [value].
--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #4
Don Lancaster wrote:
Ian Collins wrote:
>Don Lancaster wrote:
>>I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.


Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);

Looks like an interesting approach.

Except it returns "undefined" for [value].

But this works. Not sure why...

this [curHvals]["val" + "ue"] = fixFloat (Harms[ii], numPoints)

--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #5
Don Lancaster wrote:
Don Lancaster wrote:
>Ian Collins wrote:
>>Don Lancaster wrote:

I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

Have you tried:

this[fh03][value] = fixFloat (Harms[1], numPoints);

Looks like an interesting approach.

Except it returns "undefined" for [value].

But this works. Not sure why...

this [curHvals]["val" + "ue"] = fixFloat (Harms[ii], numPoints)
So does...

this [curHvals]["value"] = fixFloat (Harms[ii], numPoints)
Apparently quotes are required.
--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Apr 29 '07 #6
VK
On Apr 29, 7:07 am, Don Lancaster <d...@tinaja.comwrote:
I need to progrmatically do this inside a loop

this.fh03.value = fixFloat (Harms[1], numPoints) ;

with the numbers changing per an index.

If I try

curHvals = "03" ; // (derived from index to provide leading zero)

( "this.fh" +curHvals + ".value" ) = fixFloat(Harms[ii],numPoints)

I get a [ Cannot assign string to 'string "this.fh03.value" ' error. ]

The right side of the equation works just fine elsewhere.
As does this.fh03.value elsewhere.

eval (...) does not work as it looks up the previous fh03 value rather
than replacing it with a new one.

What is the correct way to programatically loop calculated values with
fancy names?
If I understood your problem properly then I would form the question
in some other way:

- How to access form controls using run-time generated control names
(so they cannot be hard coded as literals in my program).

- Use squared brackets notation with expression in it:
refFormElement.elements["fh"+curHvals].value =
fixFloat(Harms[ii],numPoints);

Apr 29 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
I built small C# Web and Web Service applications in a training class last week. The applications worked in the class, but when I tried to run them again over the weekend, they both bombed....
3
by: Karel Vandenhove | last post by:
Hi, I get an error "cannot apply indexing with to an expression of type object" when I try to compile the code below. SSLScannerManager is a COM component. (Used to access fingerprint...
2
by: Bruce Russell | last post by:
This may sound stupid but I can't rename the WebForm1.aspx in the solution explorer. The file is located in my local web server at C:\Inetpub\wwwroot\Lab3-VB-Starter\WebForm1.aspx Is there...
10
by: asnowfall | last post by:
I get following compilation error C3149: 'System::String' : cannot use this type here without a top-level '^'. Could someone explain why I get this error? here is the code... ImageFileData.h...
2
by: JRamirez | last post by:
Need help cannot figure out where I made the error. -------------------------------------------------------------------------------- Can someone view what I have, I need help I cannot figure out...
4
by: Don Lancaster | last post by:
I want to programically generate some JS variable names in a loop. The variables are NOT to be array values. The variable names might be eq0, eq1, eq2.... Inside an ii indexed loop, eval...
7
by: preeti13 | last post by:
i have a java script function with the pop up i want to update a database ow i am getting the erorr any one please help me with this. code is like this <script type="text/javascript"> ...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
5
by: mvmashraf | last post by:
Hi to all.... I have spent some time browsing for a solution to the following error but have unfortunatly not found any solution yet ,Please any help would be much appreciated.......
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.