Menu

setting strings

Help
2019-04-30
2019-05-01
  • Jim giordano

    Jim giordano - 2019-04-30

    This has probably been asked and answered, but after 3 hrs of searching I thought I'd just ask.

    What is the most efficient way to do the following? (not this specifically, but creating a string with multiple parts)

    dim line2 as string * 7
    line2=chr(27)+"[2H"+chr(27)+"[K" ' move to line 2 and erase line

    since you can only concatenate two strings into one, this obviously creates the error

    Error: Array SYSFNSTRING1 has not been declared

    a less than helpful catchall error for string problems.

    I've tried several things, but everything seems to waste twice as much memory as it should
    (eg. making two scratch variable and concatenating them together)

     

    Last edit: Jim giordano 2019-04-30
    • Anobium

      Anobium - 2019-04-30

      Yes, this can be annoying.

      So, treat you string as an array. See Array in the Help for this little trick.

      Dim line2(7)
      line2 =  27, "[", "2", "H", 27, "[","K"
      for sendchars = 1 to line2(0)
        hsersend line2(sendchars)
      next
      
       
  • Jim giordano

    Jim giordano - 2019-04-30

    is there some way to alias the byte array line2 to an actual string so I only have to call hsersend once?

     
  • Anobium

    Anobium - 2019-04-30

    You should write an array handler for arrays called hsersend.

     
  • Jim giordano

    Jim giordano - 2019-04-30

    Sorry, I read that at least 10 times and I don't quite understand what you are suggesting.
    My best guess is you mean write a subroutine and pass the array and do the same for-loop you did above, but it seems like only a marginal improvement unless I'm calling it in a dozen places. Yet, it is a possibility.

     
  • mmotte

    mmotte - 2019-05-01

    Jim,
    Strings and arrays are very similar.
    I don't know if you caught it but element line2(0) is the length of the string OR array when assigned as:

    line2 =  27, "[", "2", "H", 27, "[","K"
    

    so if you Dim an string and assign the elements like anobium, then it all works without the extra loop for printing.

    dim line2 as string
    line2 =  27, "[", "2", "H", 27, "[","K"
    
     HSerPrint line2
    

    From the terminal:
    

    So the overloading of HSerPrint with a string printed it as it should.

    This does not take care of the string concantenation limits of only 2 things and not assigned to itself.

    GL
    Mike

     
  • Jim giordano

    Jim giordano - 2019-05-01

    Excellent Mike, Thanks!
    That was exactly what I was looking for. I'll give it a try :)

     
  • Jim giordano

    Jim giordano - 2019-05-01

    Finally got a chance to try it out. That dropped the program memory usage by 37 bytes and the ram usage by 10 bytes. :)

     
  • Anobium

    Anobium - 2019-05-01

    Wow. I learn everyday.

    I will add to the Help today!!

     
    • Anobium

      Anobium - 2019-05-01

      To optimise... Use the ASCII values. Save memory usages...

      dim line2 as string * 7
      line2 =  27, 91, 50, 72, 27, 91,75
      
       
      • Chris Roper

        Chris Roper - 2019-05-01

        What would be the command to place that string into Program or Data Flash rather than RAM? can we put string Constants in Flash with the DATA ststements?

         
        • Anobium

          Anobium - 2019-05-01

          Not at the moment. But, soon. As this is on the list of changes.

           
      • Anobium

        Anobium - 2019-05-01
         
  • Jim giordano

    Jim giordano - 2019-05-01

    Evan-

    This is what I see at the link you posted-

    An example to show how to concate or join a string escape characters for an ASCII terminal. {empty} + {empty} + You can Dimension a string and then assign the elements like an array. Note.The first element of the string is the length, so, use this method to ensure you do not overwrite the string length. {empty} + {empty} +

    I don't think this is actually concatenation, it is declaration or assignment. I think it should be under the topic "Variables" or "Setting Variables".

    Also, I think you typed it too quickly and read back what you thought you typed. It happens to me all the time.

    Conncate is not a word (and again, it's not really concatenation as such).

    The "{empty} + {empty} +" means nothing to me. I assume this is some artifact of the editor you used?

    Where you said "Note.The" I would have said "Note: The" or "Note- The" but that's just me.

    I don't understand purpose of the comment about string length. In what context would you be overwriting the string length? It would be set to 7 however.

    Edit: After posting, the Dim of "Dimension" was shown in a box. When I looked at the link you posted, it showed as Dim between grave accents which was rather strange.

     

    Last edit: Jim giordano 2019-05-01
    • Anobium

      Anobium - 2019-05-01

      Thanks Jim. When I updated i was just awake!

      Have another look, but, can edit these documents if you have a Github account.

      Also, when we have done these edits. I will coopy to "Setting Variables".

       
  • Jim giordano

    Jim giordano - 2019-05-01

    Round 2:

    An example to show how to assign a string escape characters for an ASCII terminal. {empty} + {empty} + You can Dimension a string and then assign the elements like an array. Note. The first element of the string is the length, so, using this method ensures the length of the string variable is not changed.

    for-
    An example to show how to assign a string escape characters for an ASCII terminal
    I would have said-
    An example showing how to set a string to an escape sequence for an ANSI terminal

    for-
    The first element of the string is the length, so, using this method ensures the length of the string variable is not changed.

    I still don't get why you are mentioning this here. It actually does change the length to seven, doesn't it?

    Also, I'm still seeing the {empty} stuff, what is that?

     

    Last edit: Jim giordano 2019-05-01
    • Anobium

      Anobium - 2019-05-01

      Edited.

      I used your words.
      I then removed the reference to element(0).
      empty+ is embedded codes for ASCIIDOCS. This forces a new line.

       
  • Chris Roper

    Chris Roper - 2019-05-01

    You may find this attachment useful but it will have to be updated in light of this tread.
    I based it off work I was doing with a VT-100 Terminal emulation and what Anobium had already done for LCD Display emulation.
    It was never released to public so I am not sure how much testing I gave it, but it is in line with what I think you are trying to achieve.

    NOTE: Add attachments is not working so I include it here as inline code. copy and save as VT100.h

    ;   FILE:    VT100.h
    ;   DATE:    18.02.2018
    ;   VERSION: 1.00
    ;   AUTHOR:  C.A.Roper
    
    ;    Driver for VT100 Terminals such as Teraterm.
    ;
    ;    This code is free software; you can redistribute it and/or
    ;    modify it under the terms of the GNU Lesser General Public
    ;    License as published by the Free Software Foundation; either
    ;    version 2.1 of the License, or (at your option) any later version.
    
    ;    This code is distributed in the hope that it will be useful,
    ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
    ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    ;    Lesser General Public License for more details.
    
    ;    If you require a copy of the GNU Lesser General Public
    ;    License along with this code; please write to the Free Software
    ;    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    
    ; add  #include <VT100.h> your source file
    
    #define VT_Locate   ANSI_rev
    #define VT_CLS      ANSIERASECREEN
    #define VT_Print    HSerPrint
    #define VT_NewLine  HSerPrintCRLF
    #define VT_Hex      HSerHex
    #define VT_Cursor   HSerLCDcursor
    #define VT_Space    HSerLCDSpace
    #define VT_Flood    HSerFlood
    #define LeadingZeroActive 2
    
    #define VT_Invert   HSerPrint Chr(27) + "[7m"
    
    'for LCDCURSOR Sub
    #define DisplayON 12
    #define LCDON 12
    
    #define FLASHON 9
    #define FLASH 9
    #define CursorON 10
    
    #define FLASHOFF 14
    #define CursorOFF 13
    
    #define DisplayOFF 11
    #define LCDOFF 11
    
    ; Position cursor on Terminal
    Sub ANSI ( IN ANSIxpos, IN ANSIypos )
        HSerSend 27
        HSerPrint "["
        HSerPrint ANSIypos
        HSerSend 59
        HSerPrint ANSIxpos
        HSerPrint "H"
    End Sub
    
    ; Position cursor on Terminal
    Sub ANSI_rev ( IN ANSIypos, IN ANSIxpos )
        ANSIypos = ANSIypos + 1
        HSerSend 27
        HSerPrint "["
        HSerPrint ANSIypos
        HSerSend 59
        HSerPrint ANSIxpos
        HSerPrint "H"
    End Sub
    
    ; Eraase Terminal
    Sub ANSIERASECREEN
        HSerSend 27
        HSerPrint "["
        HSerPrint "2"
        HSerPrint "J"
        Ansi ( 0, 0 )
    
        HSerSend 27
        HSerPrint "["
        HSerPrint "?"
        HSerPrint "25"
        HSerPrint "l"
    
    end Sub
    
    sub HSerHex (In LCDValue, optional in LCDChar = 1 )
    
        'Revised 01/26/2014 by William Roth
        'Prints Hex value of ByteVal at current cursor location
        'ByteVal must be in the range of 0 to 255 (Dec)
        'ByteVal can be entered as dec, binary or hex
    
        'Extract nibbles and convert to ascii values
        HighChar = (LCDValue / 16)  + 48
        LowChar  = (LCDValue and 15) + 48
    
        'Check for alpha and convert.
        If HighChar > 57 Then HighChar = HighChar + 7
        If LowChar > 57 Then  LowChar = LowChar + 7
    
        'Write chars to LCD - if user specifies LeadingZeroActive then print the leading char
        IF LCDChar = LeadingZeroActive then
           if LCDValue < 16 then
              HSerSend 48
           end if
        end if
    
        'Write high char if LCDValue is > 15 (DEC)
        IF LCDValue > 15 then HSerSend HighChar
    
        HSerSend LowChar
    
    end Sub
    
    ' Dummy function to handle sub call
    sub HSerLCDcursor(In LCDCRSR)
    
    end sub
    
    ' Sub to print a number of spaces - upto 40
    sub HSerLCDSpace(in LCDValue)
              if LCDValue > 40 then LCDValue = 40
              do until LCDValue = 0
                        HSerSend 32
                        LCDValue --
              loop
    end sub
    
    ' Sub to print a line of a number of a specified character
    sub HSerFlood(in MyChar, in MyLen)
      Repeat MyLen
        HSerPrint Chr(MyChar)
      end Repeat
    end sub
    

    Cheers
    Chris

     

    Last edit: Chris Roper 2019-05-01
  • Jim giordano

    Jim giordano - 2019-05-01

    Good job Chris!

    I'm actually in the process of writing my own terminal program for the pc. It's about 3/4 done. There are things about Putty and TeraTerm that just drive me crazy. I don't have all the overhead of supporting a bunch of vt modes I don't care about so it should be pretty lightweight. I just have to decide how I want to handle lines longer than the width of the terminal, to decide if horizontal scrolling is really worth the effort, and if I wrap the lines like most terminals, weither to unwrap the lines when the user makes the window wider or just leave the lines the old width and fill with blanks like most of them do. Then I plan on adding some non-ansi escape sequences to do things more microprocessor oriented. Anyway, I'll use your code to test out my program :)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.