Not Understanding "popupclick"

I would like to use popupclick on four fields in the same database. I entered this code into the code box of the field properties of field4:

return
click:
local choice
let choices=commatocr(“xx,yy,zz”)
popupclick choices,“”,choice
if choice<>“”
Type=choice
endif

It works perfectly for field4.

When I used similar but unique variables to field3, this does not work for field3.
It seems cross-wired. Insights? Thx

The code that doesn’t work would be more helpful than the code that does. Copy it from the code box, and paste it here, so that we can be sure that we are seeing what you did type, rather than what you intended to type.

Sure.

return

click:

local choice3
let choices3=commatocr(“Yellow,Black”)
popupclick choices3,“”,choice3
if choice3<>“”
Type=choice3
endif

Both procedures are working for me. They are both setting the value of a field named Type.

You mention field3 and field4, but your code does not reference any field with either of those names. But both of your programs assign a value into a field named Type. That’s why these two procedures are “cross-wired” - they are both wired to the Type field.

There’s no significance to using unique local variable names. It doesn’t hurt anything, but it doesn’t help anything either. Local variables in one procedure do not interact with local variables in another procedure, so it’s perfectly fine to use the same variable name in multiple procedures. In fact, that is the primary benefit of local variables - since they are local, you don’t have to worry about them getting mixed up between different procedures.

In your case, it sounds like you want the procedures to be exactly the same, except for:

  • the list of choices in the menu
  • the field that is assigned to if the choice is not blank.

Thanks Jim & Dave. Copy and paste ‘example code’ can produce confusion.

Happily, the forum educates.

I am now using identical code on four fields, works perfectly.

return
click:
local choice
let choices=commatocr(“data-aa,data-bb,data-cc,data-dd,data-ee”)
popupclick choices,“”,choice
if choice<>“”
«» = choice
endif