popupmenu select to text encoding

  1. 2 weeks ago

    Denis D

    is not verified Mar 14 Montreal, QC, Canada

    Hi everyone,
    How can i convert popupmenu choosing result... as text to a textEncoding function
    s = TextField1.Text.ConvertEncoding(Encodings.(Popupmenu result))
    Beside use Select Case... For each encoding possibility
    Each way that i've tried result to type mismatch error
    thanks

    @Denis D — You cannot use directly the name from your popup. However, you may use the internetName and use it to retrieve the corresponding encoding with:

    Function FindEncoding( withName as String ) as TextEncoding
        for i as integer=0 to Encodings.Count - 1
        if Encodings.Item( i ).internetName=withName then
            return Encodings.Item( i )
        end if
    End Function
  2. Emile S

    Mar 14 Europe (France, Strasbourg)

    Put your code in PopupMenu1.Change, using the (PopupMenu) displayed encoding ?

  3. Denis D

    is not verified Mar 14 Montreal, QC, Canada
    Edited 2 weeks ago

    I'm not sure to understand... Or my question is not clear enough
    I want to apply the result of the selection... which is the text encoding possibility TO another text
    So i want to convert text selection...to a convert function to apply
    Yes my code is in Change event... but
    s = TextField1.Text.ConvertEncoding(Encodings.(Popupmenu result.text))
    return error of type mismatch... that i understand... because it's a text and xojo want the encoding object

  4. Emile S

    Mar 14 Europe (France, Strasbourg)

    I do not recall exactly how i've done it; maybe I used:

    Select Case PopupMenu1.Text
    
    Case UTF-8
    // Apply here the UTF8 encoding to the selected text
    
    Case <another-encodeing>
    // and so on…
    
    End Select

    After all, above is just some lines of code (unless you absolutely have to use a specific encoding, this millenium default encoding is UTF-8 (IMHO).

    I cannot run Xojo right now (all memory used by multiple applications).

  5. Denis D

    is not verified Mar 14 Montreal, QC, Canada

    Thanks Emile
    But i mentioned

    Beside use Select Case... For each encoding possibility

    I search for a shortcut to assign automatically the chosen encoding

  6. Stéphane M

    Mar 14 Answer France

    @Denis D — You cannot use directly the name from your popup. However, you may use the internetName and use it to retrieve the corresponding encoding with:

    Function FindEncoding( withName as String ) as TextEncoding
        for i as integer=0 to Encodings.Count - 1
        if Encodings.Item( i ).internetName=withName then
            return Encodings.Item( i )
        end if
    End Function
  7. Jeff T

    Mar 14 Midlands of England, Europe

    UNTESTED:

    The popupmenu has rows.
    Each row has a rowtag
    A rowtag is a variant

    If you addrow with the NAME of the encoding, then set the popup.rowtag(popup.lastindex) = <theencoding>

    You may be able to get the ROWTAG back from the popup, and use that directly.

  8. Denis D

    is not verified Mar 14 Montreal, QC, Canada

    @Stéphane Mons
    Thanks it work... partially
    The list of Encodings.Item( i ).internetName didn't contain all encoding ( or the name's doesn't match )
    specially the one that i need... DosLatin1

  9. @Denis D — Well it does contain it, but not with this name. Look at Encodings.DosLatin1.InternetName to see its internet name (well, according to Xojo)

  10. Denis D

    is not verified Mar 14 Montreal, QC, Canada

    Great !!
    Thank you

  11. Denis D

    is not verified Mar 14 Montreal, QC, Canada

    Nahhh not very convenient !
    Convert from popupmenu.text TO ( find matching internetName )... then convert i to TextEncoding
    The Select Case listing is faster to code

or Sign Up to reply!