Strings......and how to join them


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1

    Question Strings......and how to join them

    Hello all. So, I have learned more off this forum than I ever imagined (I now have a fully functional temperature/humidity controller, which I can send via FM RF about 100 metres using serin2/serout2, switch on humidifiers, switch on de-humidifiers, switch on heaters, coolers)...so now I need to know how to make a string of several different variables, I.E. out= A joined with B and joined with C. Am I making sense?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    You have to do it the hard way...OR...
    If you're savvy enough, you could define a large array, then split that array up into smaller arrays manually...OR...
    If you're really savvy, you could define a string array at a certain ram location, then define a second array at a second ram location, define a third array at a third location, all locations being sequential (not neccessarily one after another, but in a sequence). Then using a little trick, you can access the whole array using the name of the first array. PBP doesn't check for the end of an array (no bounds checking) so if you try to get an index that's larger than one that is actually defined, you can 'run into' the next array.
    For instance:
    string var byte[16] $100
    string2 var byte[16] $110
    string3 var byte[16] $120
    string4 var byte[16] $130
    that'll put string at $100, string2 at $110, string3 at $120, string4 at $130, and so on...
    You can get to all 3 strings by:
    string[ whatever ]
    To get to the 3rd byte of string4, position 51, would be:
    string[ 51 ]
    Of course this would only work with fixed length strings.
    You could easily 'terminate' each individual string with a $00, like VB does, and could easily write a routine to put individual strings together into one main string.

    I guess what it really boils down to is...What exactly are you trying to do? You're a bit vague...
    Last edited by skimask; - 17th July 2008 at 18:19.

  3. #3


    Did you find this post helpful? Yes | No

    Default well, it goes like this........

    Really, all I want to do is take a constant i(2 bits) add a variable in t(3 bits) add another variable in h(3bits) and make it all one long(ish) variable of 8 bits, so I end up with string = iittthhh. I guess I could "join" them in the serout2 command (serout2,portpin,mode,i,t,h) but that didn't seem to work very well for me

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Really, all I want to do is take a constant i(2 bits) add a variable in t(3 bits) add another variable in h(3bits) and make it all one long(ish) variable of 8 bits, so I end up with string = iittthhh. I guess I could "join" them in the serout2 command (serout2,portpin,mode,i,t,h) but that didn't seem to work very well for me
    You might have wanted this intead of what you had:

    SEROUT2 portpin, mode, [ ( ( i << 6 ) + ( t << 3 ) + h ) ]

    The way you had it, all it would do would send out 3 different bytes of value corresponding to i, t, and h.

  5. #5


    Did you find this post helpful? Yes | No

    Default Continuing on.....

    Excellent call on the SEROUT. Good to know I can do that to join strings. I got this error though on the receiver....

    ERROR: Macro SERIN2STR?WL not found in macro file.
    ERROR: Macro HSEROUTSTR?W not found in macro file.

    Which means I need an include file somewhere.......

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gringobomba14 View Post
    Excellent call on the SEROUT. Good to know I can do that to join strings. I got this error though on the receiver....

    ERROR: Macro SERIN2STR?WL not found in macro file.
    ERROR: Macro HSEROUTSTR?W not found in macro file.

    Which means I need an include file somewhere.......
    Are you using PicBasic or PicBasicPro?

Members who have read this thread : 0

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