Announcement

Collapse
No announcement yet.

Format a string at fixed column positions

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Format a string at fixed column positions

    All, I am trying to create a string that has values at certain column positions.
    I thought direct pointer positions would be the correct way, but.......

    var mystring[80];
    var EGT_INS := 1;
    var EGT_LA := 0;
    var EGT_LC := 0;
    var EGT_HC := 1290;
    var EGT_HA := 1470;
    var p;

    p := str_Ptr (mystring); // raise a string pointer
    str_PutWord (p, "EGT"); // put chars EGT starting at location 0
    str_PutWord (p+9, EGT_INS); // put a 1 at column 9
    str_PutWord (p+22, EGT_LA); // put a 0 at column 22
    str_PutWord (p+32, EGT_LC); // put a 0 at column 32
    str_PutWord (p+42, EGT_HC); // put 1290 at columns 42 to 45
    str_PutWord (p+52, EGT_HA); // put 1470 at columns 52 to 55
    str_PutWord (p+56, 0); // ending NULL

    print([STR] mystring);

    I have also tried PutByte, but the results seem the same. I have tried To(mystring) then print the "EGT" to start with, but when it prints out, all I get is the EGT and nothing else from mystring.

    I have tried with and without a NULL terminator.
    How is the correct way to go about this?
    I am wanting the different values (text format) at positions 9, 22, 32, 42,52). I have even tried hardcodeing them in quotes "1", "1290", etc....

    Any ideas?
    ch701builder

  • #2
    Hello,

    There may be a more efficient way to do this but this function does the same thing almost, it doesn't like an odd numbered position eg 9

    Code:
    var mystring[80];
    var EGT_INS := 1;
    var EGT_LA := 0;
    var EGT_LC := 0;
    var EGT_HC := 1290;
    var EGT_HA := 1470;
    var p;
    var n;
    var tempstring[20];
    
    to(mystring);
    print("                                                      ");
    to(tempstring);
    print("EGT");
    addToString(0);
    to(tempstring);
    print(EGT_INS);
    addToString(10);
    to(tempstring);
    print(EGT_LA);
    addToString(22);
    to(tempstring);
    print(EGT_LC);
    addToString(32);
    to(tempstring);
    print(EGT_HC);
    addToString(42);
    to(tempstring);
    print(EGT_HA);
    addToString(52);
    print ([STR]mystring);
    
    func addToString(var pointer)
    
    var nextpos;
    var testbyte1;
    var testbyte2;
    var tempval;
    
    nextpos := 0;
    testbyte1 := tempstring[nextpos] & 0xFF;
    testbyte2 := tempstring[nextpos] >> 8;
    
    while(testbyte1 != 0 || testbyte2 != 0)
     if(testbyte1 != 0) tempval := (32 << 8) + testbyte1;
     if(testbyte2 != 0) tempval := (testbyte2 << 8) + 32;
     if(testbyte2 != 0 && testbyte1 != 0) tempval := (testbyte2 << 8) + (testbyte1 & 0xff);
     mystring[(pointer / 2) + nextpos] := tempval;
     nextpos ++;
     testbyte1 := tempstring[nextpos] & 0xFF;
     testbyte2 := tempstring[nextpos] >> 8;
    wend
    
    for(n := 0; n < 20; n++)
      tempstring[n] := 0;
    next
    
    endfunc
    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      Paul,
      Aww yeah... I forgot about the addToString......
      Thanks a bunch.
      I'll make it work!!!

      Keith

      Comment

      Working...
      X