Jump to content

Prompt if invalid character/symbol is found in Inputbox


Recommended Posts

Hi Experts,

I need your expertise on this one and need help.:(

I've been searching whole day to see what should be the correct way in checking symbols or characters inputted in inputbox that is invalid. As of the current symbol that is invalid is "Greek letter mu (03BC)" which should be the correct symbol to use is "micro sign (00B5)" but both symbols is the same in actual character but different hexadecimal code.

Now, I want to prompt the (0x03BC) hexadecimal code as invalid once it was inputted in my inputbox as actual character/symbol " μ ", but could not find a way how to do this. However, I have found something like below related issue but I think this is not what I want but similar to it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

;checks input to ensure the letter 'r' is not typed

AdlibRegister("check", 100)

Local $msg

GUICreate("Test", 300, 300)
Global $input = GUICtrlCreateInput("", 10, 10, 280, 40)

GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    ExitLoop
            EndSelect
    WEnd

GUIDelete()

Func check()
    If StringInStr(GUICtrlRead($input), Hex(0x03BC, 4)) Then ;~ This is the actual character "µ" and this is the hexadecimal code "0x03BC"
        MsgBox(0, "", "Illegal character entered.") ;inform user
        GUICtrlSetData($input, StringTrimRight(GUICtrlRead($input), 1))
    EndIf
EndFunc

 

Need your help Experts, please.:'( Thank you in advance.

 

KS15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Based on your example, this modified example informs the user that one unicode character will be replaced with another unicode character.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

AdlibRegister("check", 250)

Local $msg

GUICreate("Test", 300, 300)
Global $input = GUICtrlCreateInput("  " & ChrW(0x03BC), 10, 10, 280, 40)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            AdlibUnRegister("check")
            ExitLoop
    EndSelect
WEnd

GUIDelete()

Func check()
    If StringInStr(GUICtrlRead($input), ChrW(0x03BC)) Then ;~ This is the actual character "µ" that has the hexadecimal unicode code "0x03BC".
        MsgBox(0, "Illegal character entered.", 'Unicode character 0x03BC, "' & ChrW(0x03BC) & '"' & @CRLF & _
                '   will be replaced with, ' & @CRLF & _
                'Unicode character 0x00B5, "' & ChrW(0x00B5) & '"')
        GUICtrlSetData($input, StringReplace(GUICtrlRead($input), ChrW(0x03BC), ChrW(0x00B5)))
        MsgBox(0, "", "Done", 1)
    EndIf
EndFunc   ;==>check

 

Link to comment
Share on other sites

@Malkey,

Wow, you save my whole day. Thank you so much Malkey, but I never saw ChrW() function in my searching glad you're here.:D

This is exactly what I wanted to do. Thumbz up men, wowwww....^_^

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...