Is there a neater way to do this


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Location
    Kent, UK
    Posts
    52

    Default Is there a neater way to do this

    I am revising some old code and was wondering if there was an easier way to do this

    PARAM1 VAR WORD
    PARAM2 VAR WORD
    COMMAND VAR BYTE
    TX_BUFF VAR BYTE [20]
    LEN VAR BYTE

    Old code
    Code:
    IF PARAM1.15 THEN
       PARAM1 = ABS PARAM1
       SerOut2 TX,6, ["SU ", #COMMAND, " -", #PARAM1]
    ELSE
       SerOut2 TX,6, ["SU ", #COMMAND, " ", #PARAM1]
    ENDIF
    
    IF PARAM2.15 THEN
       PARAM2 = ABS PARAM2
       SerOut2 TX,6, [" -", #PARAM2]
    ELSE
       SerOut2 TX,6, [" ", #PARAM2]
    ENDIF
    Same code but into an array so I can then send by using
    HSEROUT [STR TX_BUFF\ LEN]

    Is there an easy way to build the array and keep track of the length (LEN)

    Thanks for looking,
    Tim.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Is there a neater way to do this

    arraywrite TX_BUFF,["SU ", #COMMAND, sdec PARAM1,0]



    if you look for the null termination chr then you may not need to know the length or write a subby to determine the length if you have to

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Is there a neater way to do this

    Hi,
    Yes, as Richard has shown the SDEC modifier is what you're looking for to get rid of the IF/ELSE/ENDIF stuff but I don't quite understand why you need to build the string, put into an Array and then send it with HSEROUT. Do you need it in the Array for some other purposes? If not, then simply
    Code:
    HSEROUT ["SU ", #COMMAND, " ", SDEC PARAM1]
    I'm sure the length of the array, after an arraywrite CAN be extracted from an internal system variable (if done directly after the Arraywrite) but I don't know which. Would need to do some investigation to find out. But again, I don't see the need.

    /Henrik.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts