Shop OBEX P1 Docs P2 Docs Learn Events
Dynamic variables with LONGMOVE? — Parallax Forums

Dynamic variables with LONGMOVE?

eagletalontimeagletalontim Posts: 1,399
edited 2014-04-08 19:32 in Propeller 1
Is there a way to use LONGMOVE to copy data from one variable to another where the receiving variable name changes?

Example :
DAT
  Start_User_Settings
  User_Setting1  LONG  1
  User_Setting2  LONG  456
  User_Setting3  LONG  15040
  End_User_Settings

OBJ
  eeprom : "Propeller_Eeprom"

PUB main | current_value
  current_value := 555
  copy_me(current_value, 2)

PUB copy_me(the_value, setting_number)
  size := strsize(the_value)
  LONGMOVE(@User_Setting + "0" + setting_number, @the_value, size)

I have not tested the code above. Doing this off the top of my head....

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2014-04-08 19:23
    Guess I have to create a function with "CASE" to do what I am trying to do. I was hoping to make this simpler, but dynamic variables are not as easy or not able to be done on the Prop :(
  • kuronekokuroneko Posts: 3,623
    edited 2014-04-08 19:28
    With User_Setting3 being the same as UserSetting1[2] this becomes:
    PUB copy_me(the_value, setting_number)
      User_Setting1[setting_number] := the_value
    
    Unless you want 1-based-indexes in which case you need an adjustment. That said, a method may be overkill for this.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-08 19:32
    You're using "strsize" on long? strsize is intended to be used with character strings. I'm not really sure what size you're trying to measure.

    The "0" seems out of the blue. You'd normally only use the '+ "0"' trick on a single character to change it from its numeric value to an ASCII value/character.

    What do you mean by "host" variable name change? Oh, I see (sort of what you're trying to do. No, You can't manipulate variable names. You can treat other variables as an element of an array named by an earlier (or even later variable).

    For example. "User_Setting2" is the same as "User_Setting1[1]".

    The variable names are not compiled as names. Your compiled code shown by F8 will be the same no mater what you call your variables.
Sign In or Register to comment.