Writing a single unicode character into a WORD

PeteB123
2013-11-01
2013-11-01
  • PeteB123

    PeteB123 - 2013-11-01

    Hi folks,
    I am looking to use a WORD data type to store a unicode character - I have chosen the WORD datatype as this is the underlying data type of the WSTRING.

    Basically I would like to be able to say:

    VAR
        wTemp: WORD;
    END_VAR
    wTemp := "<";
    

    and to have the hex value of < put into the variable.

    I have found a way around this problem but it is very un-eloquent and goes like this:

    VAR
        wsTempString: WSTRING := "<";
        wTempWord: WORD;
    END_VAR
    wTempWord := wsTempString[0];
    

    This has the desired effect of placing the hex value of < into wTempWord, but the readability of the program is awful, is there a way I can write the unicode character straight into the WORD variable.
    I'm thinking of C in doing this:

    temp = 'A';
    

    Any help appreciated.

    /Pete

     
  • timvh

    timvh - 2013-11-01

    I don't know if a function for this already exists, but it is pretty easy to make:

    FUNCTION WS_TO_W : WORD
    VAR_INPUT
       WS   : WSTRING(1);
    END_VAR
    VAR
       pW : POINTER TO WORD;
    END_VAR
    
    pW := ADR(WS);
    WS_TO_W := pW^;
    

    Then call this from your application

    wWord := WS_TO_W("<");
    
     

Log in to post a comment.