Skitty Posted March 18, 2012 Share Posted March 18, 2012 This function is driving me nuts, I can't figure out why it's not working at all, basically it's returning randomized values that are never consistent. Anyone know what I'm doing wrong? basically I need to know when a character is one of those special characters, you'll see what I mean when you copy/paste it into scite.. $Test = _IsAlphaNumetric("1"); should return 1 MsgBox(64,"test 1","Return: " & $Test & @CR & "@Error: " & @Error) $Test = _IsAlphaNumetric("A"); should return 1 MsgBox(64,"test 2","Return: " & $Test & @CR & "@Error: " & @Error) $Test = _IsAlphaNumetric(";"); should return 0 MsgBox(64,"test 3","Return: " & $Test & @CR & "@Error: " & @Error) $Test = _IsAlphaNumetric("`"); should return 0 MsgBox(64,"test 4","Return: " & $Test & @CR & "@Error: " & @Error) $Test = _IsAlphaNumetric("*"); should return 0 MsgBox(64,"test 5","Return: " & $Test & @CR & "@Error: " & @Error) $Test = _IsAlphaNumetric(""); should return 0 MsgBox(64,"test 6","Return: " & $Test & @CR & "@Error: " & @Error) $Test = _IsAlphaNumetric(""); should return 0 MsgBox(64,"test 7","Return: " & $Test & @CR & "@Error: " & @Error) Func _IsAlphaNumetric($Value) $Char = DllStructCreate("char") DllStructSetData($Char,1,$Value) local $aReturn = DllCall("User32.dll","int","IsCharAlphaNumericA","ptr",DllStructGetPtr($Char,1)) If @error Then Return SetError(1,0,0) Return SetError(0,0,$aReturn[0]) EndFunc Link to comment Share on other sites More sharing options...
guinness Posted March 18, 2012 Share Posted March 18, 2012 Why not StringIsAlpha? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Skitty Posted March 18, 2012 Author Share Posted March 18, 2012 Well.. What I'm really trying to do is determine if a character is a control code character, what can I do to determine if a character is a control code character? preferably without using an array of any sort. Link to comment Share on other sites More sharing options...
jchd Posted March 18, 2012 Share Posted March 18, 2012 (edited) Note that you were using Char in the struct (implies conversion to ANSI) and the ANSI version of IsCharAlphaNumericA so don't expect it to give consistent result in case your character is outside (your own) ANSI codepage. Control characters are grouped in ranges: 0x00 .. 0x1F plus 0x7F for the ANSI encoding. For Unicode there are also supplementary control characters 0x80 .. 0x9F (seldom use). A simple Switch on AscW($char) would tell you. Edited March 18, 2012 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JohnOne Posted March 18, 2012 Share Posted March 18, 2012 (edited) Func _blah($c) If Asc($c) > 0 And Asc($c) < 32 Then Return True Return False EndFunc ? EDIT: That's how slow I am It took me seven minutes to check the Asc func and type that out Edited March 18, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
KaFu Posted March 18, 2012 Share Posted March 18, 2012 $Test = _IsAlphaNumetric("1"); should return 1 MsgBox(64, "test 1", "Return: " & $Test & @CR & "@Error: " & @error) $Test = _IsAlphaNumetric("A"); should return 1 MsgBox(64, "test 2", "Return: " & $Test & @CR & "@Error: " & @error) $Test = _IsAlphaNumetric(";"); should return 0 MsgBox(64, "test 3", "Return: " & $Test & @CR & "@Error: " & @error) $Test = _IsAlphaNumetric("`"); should return 0 MsgBox(64, "test 4", "Return: " & $Test & @CR & "@Error: " & @error) $Test = _IsAlphaNumetric("*"); should return 0 MsgBox(64, "test 5", "Return: " & $Test & @CR & "@Error: " & @error) $Test = _IsAlphaNumetric(""); should return 0 MsgBox(64, "test 6", "Return: " & $Test & @CR & "@Error: " & @error) $Test = _IsAlphaNumetric(""); should return 0 MsgBox(64, "test 7", "Return: " & $Test & @CR & "@Error: " & @error) Func _IsAlphaNumetric($Value) $iAsc = Asc($Value) If ($iAsc > 47 And $iAsc < 58) Or ($iAsc > 64 And $iAsc < 91) Or ($iAsc > 96 And $iAsc < 123) Then Return 1 Return 0 EndFunc ;==>_IsAlphaNumetric OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Skitty Posted March 18, 2012 Author Share Posted March 18, 2012 @jhcd Now that you point that out I see how pointless it was what I was doing. Now that I understand the function a little more I see it's not at all what I needed. @JohnOne @KaFu That's more or less what I should be doing I guess, and the reason I mentioned that this should be done preferably without using an array is because that was another method I was thinking about. Thanks for the help! Link to comment Share on other sites More sharing options...
jchd Posted March 18, 2012 Share Posted March 18, 2012 You told us about control chars, so you got it! Now if you stick to ANSI (your codepage) alphameric chars, I'd do: StringIsAlNum($s) If your need is different, then tell us precisely what it is. Maybe the easiest way is simply using a StringRegExp but we need to know which logic to put in the pattern to determine a match. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Skitty Posted March 18, 2012 Author Share Posted March 18, 2012 You told us about control chars, so you got it!Now if you stick to ANSI (your codepage) alphameric chars, I'd do:StringIsAlNum($s)Wow, I can't believe I didn't find that function before...Now I just feel stupid for trying to use the original one I posted before.If your need is different, then tell us precisely what it is. Maybe the easiest way is simply using a StringRegExp but we need to know which logic to put in the pattern to determine a match.No, after everything posted here, I guess we can say I've already got everything sorted So my thanks to everyone who posted! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now