Jump to content

Recommended Posts

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 post
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to post
Share on other sites

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 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 here
RegExp tutorial: enough to get started
PCRE 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 post
Share on other sites

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 :oops:

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to post
Share on other sites

$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

Link to post
Share on other sites

@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 post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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 post
Share on other sites

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 :oops:

So my thanks to everyone who posted!

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...