Announcement

Collapse
No announcement yet.

Display string and char

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

  • Display string and char

    Hi all,

    I need another information.

    I try to read data from file, display it in a text box, modify it with a keyboard and save.
    I dont know if the best way is use char or string.
    Because i try tu read txt file like a string but the key buttons are char.
    So i don't know if the best way is use always char or string, convert the key of the keyboard in string and add it.

    Someone has example on this?

    Thanks

  • #2


    Have a read of appnote 4D-AN-P2006 http://www.4dsystems.com.au/appnotes/ and see if that helps your understanding
    Mark

    Comment


    • #3


      Thanks,

      but my problem is like this

      nch := 1;
      while (nch != 0)
      nch := file_GetS(pRstring,10,h);
      if (nch != 0)
      str_Cat(&txtString ,&pRstring);
      if (line == n)
      str_Cat(txtString + nch,pstring);
      else
      str_Cat(txtString + chars,pRstring);
      endif
      leng := str_Length(txtString);
      line++;
      endif
      wend

      i want to read line per line in a txt file and replace one of this (line == n) with another one (pstring).
      All of the sting must be fill in a buffer and ther rewrite in the same file.
      But strCat doesn't work
      I tryed also with str_Cat(txtString ,pRstring); but the same.
      If i try to read the pRstring, the string is corect so i don't know how to use this

      Comment


      • #4


        It's a bit unclear to me what you are trying to achieve.

        But from what you have in your code it makes me think you are not wanting to concatenate strings, but to replace parts of them.

        Maybe you want to use str_ByteMove()?
        Mark

        Comment


        • #5


          Hi,

          sorry, now i try to be clear.

          I create a buffer[100] that have to be fill with all the string present in the file.
          I read every line in the file with file_GetS and put it in a temp tempbuffer[10]
          then i want to insert this string in buffer[100] and make this for every line.

          At the end i want to replace the old file with the data of buffer[100]

          Federico

          Comment


          • #6


            I'm sorry that still doesn't help much.

            I did ask before if you'd tried using str_ByteMove() as the code you have shown only uses str_Cat() which is for concatenating strings, not 'building' them.

            Perhaps post some more of your code?
            Mark

            Comment


            • #7


              Hi,

              sorry i was very busy.
              I solved the problem but now i have another question, probably it has a very easy solution (i hope)
              I have a number in a file.
              I read it wit the function file_GetS and i have it in string.
              There is a way to convert the string "4000" in the number 4000 and sand it like a number with COM?

              thanks

              Comment


              • #8


                Err, not 100% sure I understand the question.

                Anyway.

                Anything you can 'print' on the screen you can send to the comport, eg.

                to(COM0) ;
                print([STR] somestring) ;
                Mark

                Comment


                • #9


                  Sorry for my english.

                  I mean, I have a string "4000" but i want to send a number 4000 using COM
                  so i want to convert string "4000" to number 4000

                  Comment


                  • #10


                    Um, so say you want it written as a 16 bit binary number, this should do it, hopefully you can work out any other format from that

                    #platform "uLCD-32PTU"

                    #inherit "4DGL_16bitColours.fnc"


                    func GetNumber(var str)
                    var ch, n;
                    n := 0 ;
                    while ( str_GetC(&str, &ch))
                    if ((ch > '9') || (ch < '0')) break;
                    n := n * 10;
                    n := n + (ch -'0');
                    wend
                    return n;
                    endfunc

                    var string[10];

                    func main()
                    var i ;
                    to(string) ;
                    print("4000") ;
                    i := GetNumber(str_Ptr(string)) ;
                    print(i) ;
                    serout(i > 8) ; // write to com port
                    serout(i) ;
                    repeat
                    forever

                    endfunc
                    Mark

                    Comment


                    • #11


                      Why i have this problem?

                      I want to fill in the global variable pRstring, the n line


                      var Rbuffer[10];
                      pRstring := str_Ptr(Rbuffer);


                      func ReadParam(var n)
                      var h;
                      var line := 0;
                      h := file_Open("ini.cnf", 'r');
                      while (line

                      Comment


                      • #12


                        to(COM0); str_Printf(&pRstring, "%d");
                        it print a wrong char but if i print
                        to(COM0); str_Printf("", pRstring)
                        this is ok.

                        Afther that if i try to use the pRstring in your function doesn't work because i don't have decimal number.
                        Haven't you explained the problem yourself? The first str_Printf is going to treat the first two characters as a signed integer and print them, the second one is going to treat it as a string, which will definitely lead to two different outputs. Have a look in the manual.

                        Also, using file_GetS to read a 'binary' file (if the file contains something that is usable by %d then it must be a binary file) will be fraught with problems.
                        Mark

                        Comment

                        Working...
                        X