Announcement

Collapse
No announcement yet.

How to write dynamic string from MagicCode

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

  • How to write dynamic string from MagicCode

    Using PrintStrings doesn't print anything. Have something to do with Unicode?

    Code:
    // MagicCode1
    //
    
    ActivateForm(9);
    WriteObject(tStrings,6,2);
    WriteObject(tStrings,7,2);
    
    to(key_bffr);print("123456");
    key_ptr:=str_Ptr(key_bffr);
    
    //print([STR]key_bffr);
    PrintStrings(5,key_ptr,1);

  • #2
    I've got it working using the code below (without using PrintStrings). Is there a way to enlarge the font without using txt_Height or txt_Width? Txt_Height/Width to enlarge makes it pixelated (unlike a string object displayed with a large font).
    Can it be done with PrintStrings?


    Code:
    / MagicCode1
    //
    
    
    ActivateForm(9);
    WriteObject(tStrings,6,2);
    WriteObject(tStrings,7,2);
    
    to(key_bffr);print("123456");
    key_ptr:=str_Ptr(key_bffr);
    
    //print([STR]key_bffr);
    //PrintStrings(5,key_ptr,1);
    
    
    txt_FontID(hFont1) ;
    txt_FGcolour(BLACK) ;
    txt_BGcolour(WHITE) ;
    txt_Height(2);
    txt_Width(2);
    putstrCentred(400,133,key_bffr);


    Comment


    • #3
      Hi jeremy,

      You can use this line of code:

      Code:
      //---------------------------------------
      //MagicCode - Constant/Global/Data
      
      var strUni[10];
      
      func ANSI2Uni(var *ansi, var *uni)
      var i, ch ;
      repeat
      ch := str_GetByte(ansi++) ;
      uni[i++] := ch ;
      until (!ch) ;
      endfunc
      //---------------------------------------
      
      ANSI2Uni(str_Ptr("123456"), strUni);
      PrintStrings(1,strUni,1);
      Best Regards,
      Kevin

      Comment


      • #4
        Thanks, Kevin! It works.
        Is there any way (when using PrintStrings) to center the text? May have to use monospace font and padding blanks.

        Comment


        • #5
          Hi jeremy,

          You need to manually add spaces as there is no formatting on dynamic strings.

          You can refer to application note: ViSi-Genie Labels, Texts, and Strings for more information

          Thus, the right -, centre -, or left - alignment of a predefined string when
          being formatted in the strings editor in Workshop does not apply to
          dynamic strings. Furthermore, a dynamic string does not automatically fit
          into the area defined by the strings container object. It will only be printed
          starting at the x and y coordinates of the strings container object.
          Formatting of predefined strings is set during design time, while formatting
          of dynamic strings is up to the host.

          Best Regards,
          Kevin

          Comment


          • #6
            Is conversion to Unicode necessary for dynamic strings?

            Is there a Magic equivalent to the host WRITE_STR command?

            If it's easy for the host to write a string, it should be easy for the LCD to write a string, too.

            Thanks!

            Comment


            • #7
              Hi jeremy,

              Is conversion to Unicode necessary for dynamic strings?
              Yes, you can refer to the ViSi-Genie Reference Manual for more information:

              Click image for larger version

Name:	PrintStrings.png
Views:	57
Size:	8.1 KB
ID:	68580

              Best Regards,
              Kevin




              Comment

              Working...
              X