How about String Variables?


Closed Thread
Results 1 to 40 of 41

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    78


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    you have a high ceiling house Demon...

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    OR small screen
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    OK Now that last string of posts are just about the funniest thing I have read around here in a while.

    Or else I am just so tired that I need to get some sleep... Been chasing satelite outages for the last 14 hours and about 500 miles. Spacenet decided to change frequencies in the middle of last night and I woke up to 16 sattelites down. (we use them to bring in electricity load information on a 5 minute basis from major substations in Utah, Wyoming and Nevada.

    Probably just tired...

    You guys and gals are a great bunch.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Jul 2011
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    Yeah, how about STRING variables?????


    Strings are needed ALL THE TIME! I wish PBP would face the music and implement them! Every other compiler I see has them, why not PBP? (And No, I don't want to switch because I've got years and $ invested in this one.)

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    There are many other features besides strings available in other compilers that are not available in PBP.
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    I like strings as well. All my projects have either RS-232 or Ethernet connectivity, and they all have
    menus, user input, etc. I need to handle strings constantly.

    I generally put all my strings into arrays. This is the only way they can be manipulated. Check out
    the ARRAYWRITE command. It is an easy way to load and clear arrays.

    Here is some stuff that I cobbled together that may help the situation. Note that I pulled this from
    various programs, so it has not been tested completely, although most routines should work as-is.
    Use at your own risk!

    Lester may want to move this into the 'code examples' section later.



    Code:
    ;----------------------------------------------------------------------        
            IgnoreCase var bit
            Xs var byte
            Ys var byte
            Zs var byte
            Js var byte
            Ws var byte
            Cmd var byte
            Length1 var word
            Length2 var word
            MaxSearchLen var byte
          
            Str1ArrayLength CON 30
            Str2ArrayLength con 30
            
            MaxCompareLength var byte
            
            Str1 var byte[Str1ArrayLength]
            Str2 var byte[Str2ArrayLength]
    ;---------------------------------------------------------------------------       
       ; Zero out the strings 
         arraywrite Str1,[rep 0\Str1ArrayLength]
         arraywrite Str2,[rep 0\Str2ArrayLength]
    
    ;--------------------------------------------------        
        
    ; Fill input arrays with some test stuff      
           
          ARRAYWRITE Str1,["0123456789ABCDEF"]
          arraywrite Str2,["345"]
    ;-------------------------------------------------      
    
    'LeftString:  ; Str2 contains the leftmost chars of Str1
    ;     Ys = Number of Chars to separate off from Str1      
            YS = 6  ; for testing only
            
    
          If Ys != 0 then 
             For Js = 0 to YS-1
                Str2[Js] = Str1[Js]
             next Js
                Str2[Js] = 0  ; make certain we always end with a nul
          endif  
         return 
    ;----------------------------------------------------  
    ;----------------------------------------------------  
         
    MidString: ; Str2 contains a string of Ys chars derived from Str1 starting at position Zs (zero based) 
        
        ys = 2 :Zs = 4 ; for testing only
    
          If Ys !=0 then
            For Xs = Zs to ((Zs + Ys)-1)
               Str2[Xs-Zs] = Str1[Xs]
            next Xs
               Str2[xs] = 0  ; terminate with a nul
          Endif
           return
    
    ;-------------------------------------------------------------------------------------
    
    RightString:  ; Str2 contains a string consisting of the right-most chars (number defined by Ys) of Str1 
          
           Ys = 4   ; for testing only
    
           Js = Ys - 1
           for xs = Str1ArrayLength to 0 step - 1
                 If Str1[xs] != 0 then
                     Str2 [Js] = Str1[Xs]
                     if Js = 0 then DoneRS
                     Js = Js-1
                  endif
          next xs
    DoneRS:
    ;      return              
    ;---------------------------------------------------------------------------------------         
    LenSTring:  ; Ys contains the length of STR1        
            Js= 0
            While Str1[JS] != 0
               JS = Js + 1
            wend 
            if Js > 1 then  
               Ys = Js - 2 
            else
               YS = 0
            endif  
    ;        return     
    ;----------------------------------------------------------------------------------------        
    InString:   ; Ws contains the position in STR1 where the match with STR2 started
                ; if there is no match, Ws contains 255
                ; if Ignore Case is set to '1', it will, of course, ignore the case.
                
            MaxCompareLength = Str1ArrayLength Min Str2ArrayLength 
            for Xs = 0 to Str1ArrayLength
               If IgnoreCase then 
                    Str2[0] = Str2[0] & %11011111  
                    Str1[Xs] = Str1[XS] & %11011111
               endif     
                   If Str2[0] = Str1[Xs] then   ; Found a match on 1st char of Str2
                   
                   Ws = Xs
                   Js = 1
                     for Ys = Xs + 1 to MaxCompareLength
                        if Str2[Js] = 0 then FoundMatch  ; hit the end of Str2
                           If IgnoreCase then 
                               Str2[Js] = Str2[JS] & %11011111  
                               Str1[Ys] = Str1[Ys] & %11011111
                           endif     
                        if Str2[Js] != Str1[Ys] then NoMatch
                        Js = Js + 1
                     next Ys
                     goto FoundMatch
                  endif
            next Xs            
    NoMatch:
          WS = 255
          return
    FoundMatch:
          return               
    
    ;-----------------------------------------------------------------------------------               
    CommandParser:
    ; Fast searcher! Case sensitive.  Closely based on info provided by Darrel Taylor.
    ; Searches through Str1. If it finds the strings listed in the quotes, it returns which one it found.
    ; the max length of STR1 that will be searched is in MaxSearchLen
       
        Cmd = 255  ; In case of no match
        MaxSearchLen = 20            
     
        Parse01: Cmd=01 : ARRAYREAD Str1,MaxSearchLen,Parse02,[WAIT("Command1")] : GOTO Foundit
        Parse02: Cmd=02 : ARRAYREAD Str1,MaxSearchLen,Parse03,[WAIT("Age")] : GOTO Foundit
        Parse03: Cmd=03 : ARRAYREAD Str1,MaxSearchLen,Parse04,[WAIT("Weight")] : GOTO Foundit
        Parse04: Cmd=04 : ARRAYREAD Str1,MaxSearchLen,Parse05,[WAIT("Address")] : GOTO Foundit
        Parse05: Cmd=05 : ARRAYREAD Str1,MaxSearchLen,Parse06,[WAIT("Command5")] : GOTO Foundit
        Parse06: Cmd=06 : ARRAYREAD Str1,MaxSearchLen,Parse07,[WAIT("Command6")] : GOTO Foundit
        Parse07: Cmd=07 : ARRAYREAD Str1,MaxSearchLen,Parse08,[WAIT("Command7")] : GOTO Foundit
        Parse08: Cmd=08 : ARRAYREAD Str1,MaxSearchLen,Parse09,[WAIT("Command8")] : GOTO Foundit
        Parse09: Cmd=09 : ARRAYREAD Str1,MaxSearchLen,Parse10,[WAIT("Command9")] : GOTO Foundit
        Parse10: Cmd=10 : ARRAYREAD Str1,MaxSearchLen,Parse11,[WAIT("Command10")] : GOTO Foundit
        Parse11: Cmd=11 : ARRAYREAD Str1,MaxSearchLen,Parse12,[WAIT("Command11")] : GOTO Foundit
        Parse12: Cmd=12 : ARRAYREAD Str1,MaxSearchLen,Parse13,[WAIT("Command12")] : GOTO Foundit
        Parse13: Cmd=13 : ARRAYREAD Str1,MaxSearchLen,Parse14,[WAIT("Command13")] : GOTO Foundit
        Parse14: Cmd=14 : ARRAYREAD Str1,MaxSearchLen,Parse15,[WAIT("Command14")] : GOTO Foundit
        Parse15: Cmd=15 : ARRAYREAD Str1,MaxSearchLen,Foundit,[WAIT("Command15")] : GOTO Foundit
        
    Foundit:
        return
    
    ;-------------------------------------------------------------------------------------------
    Charles Linquist

  7. #7
    Join Date
    Feb 2011
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: How about String Variables?

    Thanks Charles for your subroutines.

    This is a snippet of code from a two temperature probe controller, chiller and alarm
    Alarm MIN and MAX
    Chiller MIN and MAX

    Crammed it into a 12f1822, should of used a 12f1840 for more space.

    Use gosub Print_Phrase: with zb pointing to the string.

    eg zb= Ofuzzy1 : gosub Print_Phrase

    will print out the copyright string:
    (C)2011 Ofuzzy1 All Rights Reserved - Not for Life Critical Use!


    Was cramped for space so phrases were pieced together.
    MIN Alarm would be pieced together
    Print_Alarm_Min:
    gosub Print_Alarm: gosub Print_Min:
    return
    '================================================= =====================================


    Code:
    ; Strings are stored in the EEPROM leaving more room for Programs
    ; The last char of the string has $80 added to it mark then end of the string.
    ;  this simplifies string maintenance.
    ; Strings are sent out via DEGUG for Async Serial - RS232
    ; Debug is smaller than serout and serout2
    
    ' print character defines
    CR              con 13
    LF              con 10
    VTAB            CON 11  ' VERTICAL TAB   = Clear Screen
    DEGREE          CON $DF
    Dash            con 45
    Space           con $20
    
    ' ---- The temps  they do all the grunt work with little or no pay :)
    AB          VAR BYTE    ' TEMP
    BB          VAR BYTE    ' TEMP
    xb          var byte    ' temp
    yb          var byte    ' temp
    zb          var byte    ' temp
    
    ' These are stored on the EEPROM Data area -- Leaves room for bigger programs
    '   *** Mark the end of the words with Char + 128
    ; @$10 starts the strings at location $10 [16] in the eeprom
    CharBump        con $80
    Ofuzzy1 data @$10,   "(C)2011 Ofuzzy1 All Rights Reserved - Not for Life Critical Use", "!" + CharBump
    W_Alarm  Data        "Alarm", "_" + CharBump     ; Alarm
    W_Min    Data        "Mi", "n" + CharBump        ; Min
    W_Max    Data        "Ma", "x" + CharBump        ; Max
    W_Normal Data        "Norma", "l" + CharBump
    W_Both_Probes Data   "Both Probe", "s" + CharBump
    W_Enter  Data        "& Ente", "r" + CharBump
    W_YNRQ   Data        "Y=Yes R=Redo N=No Q=Qui", "t" + CharBump
    
    '===========================================================================
    
    
    ; begin MAIN program code
    
    Gosub Print_Copyright
    End
    ;end MAIN program code
    
    ===========
    Print_Copyright:
    gosub CR_LF3 ': gosub CR_LF
    zb= Ofuzzy1 : gosub Print_Phrase
    gosub CR_LF3 ': gosub CR_LF
    return
    '======================================================================================
    Print_Phrase:   ' Call with zb = ROM_Memory_Location [byte] last char is >$80
    bb = 1          ' this could be re-written slicker but it works.
      Do until !BB '  = 0
        read zb, ab
        if ab > CharBump-1 then 
            ab = ab - CharBump
            bb = 0
        endif    
        debug ab
        zb= zb + 1
      loop
    return
    '======================================================================================
    CR_LF3:        ; 3 line feeds
    debug LF,cr
    CR_LF2:        ; 2 line feeds
    debug LF,cr
    CR_LF:
    debug CR,LF    ; 1 line feed
    return
    '======================================================================================
    Print_SP2:
    debug " "
    Print_SP:
    debug " "
    return
    '======================================================================================
    Print_LT:
    gosub Print_SP : gosub Print_lt1: gosub Print_SP 
    return
    '======================================================================================
    
    Print_LT1:
    debug "<": 
    return
    '======================================================================================
    
    Print_GT:
    gosub Print_SP : gosub Print_GT1: gosub Print_SP 
    return
    '======================================================================================
    
    Print_GT1:
    debug ">": 
    return
    '======================================================================================
    Last edited by ofuzzy1; - 12th January 2013 at 20:00.

Similar Threads

  1. How to convert HEX Value as formatted BIN String ?
    By Robson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2007, 02:16
  2. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  3. Variables not appearing in Watch Window MPLabv7.3
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2006, 14:36
  4. String Parsing
    By eoasap in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th February 2006, 17:20
  5. Message String Table using Readcode
    By mytekcontrols in forum Code Examples
    Replies: 2
    Last Post: - 10th July 2005, 23:17

Members who have read this thread : 3

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