Variable as field name troubles


#1

I am trying to set the value of a field that has it’s name in a variable, without any success as of yet. I can’t seem to figure out how to do this. The name of my field is HP1R1Score. Here is what I have:
local HScorebox
HScorebox = “HP1R1Score”
field (HScorebox+"")
cell 0

It doesn’t put the 0 into that field and I can’t figure out why


#2

You can’t assign a value to a field that way.

I don’t understand the +"" but it doesn’t seem to have an effect, and assuming your field is numeric, this should work. «» means the active field.

local HScorebox
HScorebox = “HP1R1Score”
field (HScorebox)
«» = 0

#3

That had no effect on the field at all.

I’m still stumped…


#4

I don’t see why what Jim gave doesn’t work for you. Here is a short animation showing your basic code with the removal of the +"" putting the 0 value in the proper field.


#5

Jim’s procedure works for me as well, but I thought I would mention another way to do this.

local HScorebox
HScorebox = “HP1R1Score”
set HScorebox, 0

This sets the value of the field, but doesn’t make it the active field. You would still need the field command if you wanted to make it the active field.

Your version also works for me.


#6

It works if I make a new file with one field (HP1R1Score) and that short script.
I do need to figure out why my database won’t change the field in a script…


#7

That works but I would really like to know why my original code is faulty.


#8

How are you triggering it? If it runs it should work. At least it did for me.


#9

I just have that small snippet of code in a procedure window. I am proceeding with using the “set” procedure and that seems to work very well.


#10

Do you by chance also have a variable you created by that same name?
Is the field set as a numeric field?


#11

The field is "Number (Integer). I don’t think I have a variable by that name unless it was accidentally created along the way. I keep my variable names substantially different than my field names so as to avoid confusion and errors.


#12

check value assigned.


#13

It’s always best to try to come up with the simplest code possible for debugging. The original code could be replaced with

HP1R1Score = 0

Does that work? Even if you ultimately really need the field name to be in a variable, trying this simple code verifies the basics before moving on to more complex applications.


#14

I agree with the simple aspect. I do need to have the field name in a variable, and between “set” and “datavalue(” I think I have it now. I am slowly making sense of it all. I hate asking for help with simple/trivial issues but I only do that after an hour or so of looking for answers on my own. DNS outages don’t help, but I understand that s/>t happens. My personal knowledge base is rapidly expanding, in no small part due to this forum. Thank you all.


#15

No question is too trivial or simple. Just keep asking.