Guidance
指路人
g.yi.org
software / rapidq / Examples / Console / printf / printf.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
' This is an example of how you can write your own PRINTF in Rapid-Q
' If you're familiar with C, then this can be an invaluable tool

     $APPTYPE CONSOLE

     SUBI PRINTF (...)
      N = 1   ' Number count
      M = 2   ' String count

      FOR I = 1 TO LEN(PARAMSTR$(1))
       SELECT CASE MID$(PARAMSTR$(1), I, 1)
       CASE "%"
        I = I + 1
        SELECT CASE LCASE$(MID$(PARAMSTR$(1), I, 1))
        CASE "d"
         PRINT INT(PARAMVAL(N));      ' Use this to print number
         N = N + 1
        CASE "f"                       ' Float
         PRINT PARAMVAL(N);
         N = N + 1
        CASE IS = "l" AND LCASE$(MID$(PARAMSTR$(1), I+1, 1)) = "d"
         PRINT INT(PARAMVAL(N));
         N = N + 1
         I = I + 1
        CASE "s"
         PRINT PARAMSTR$(M);          ' Strings stored here
         M = M + 1
        CASE ELSE
         PRINT MID$(PARAMSTR$(1), I-1, 2);
        END SELECT
       CASE "\"
        I = I + 1
        SELECT CASE LCASE$(MID$(PARAMSTR$(1), I, 1))
        CASE "n"
         PRINT
        CASE ELSE
         PRINT MID$(PARAMSTR$(1), I-1, 2);
        END SELECT
       CASE ELSE
        PRINT MID$(PARAMSTR$(1), I, 1);
       END SELECT
      NEXT
     END SUBI



     CLS
     PRINTF("Number: %d, string: %s and this is %5 undefined.\n", 123, "hello")
     PRINTF "Num 1: %ld, Num 2: %f, Num 3: %d, Num 4: %d\n", 2^10-30/5*10, 498.234, 91, 100
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-4-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:43:28