Matt @ MPCS Posted December 26, 2004 Share Posted December 26, 2004 (edited) I have been updating some of my older scripts for distrobution to some of my AutoIt supporting clients and came across something strange. I think when the StringSplit function was updated (before the 12/01 release) a new bug was introduced. According to the documentation:If you use a blank string "" for the delimiters, each character will be returned as an element.Well a month or so ago I posted my Random String Generation code on Scripts and Scraps and it worked fine, but now running the 12/01/04 release of 3.0.103 it won't seperate my string into an array by charaters. I have made some code changes and I am pretty sure it is clean code, but if another developer could take a look to make sure I am not missing something; I would appriciate it. The code is as follows:Func GetRandString( $Len, $Options, $OtherChars = "" ) Dim $Chars, $CharArray, $GenString If Not StringIsInt( $Len ) Then Return -1 Select Case BitAND( $Options, 1 ); Include UpperCase $Chars = $Chars & "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Case BitAND( $Options, 2 ); Include LowerCase $Chars = $Chars & "abcdefghijklmnopqrstuvwxyz" Case BitAND( $Options, 4 ); Include Numbers $Chars = $Chars & "0123456789" Case BitAND( $Options, 8 ); Include Special $Chars = $Chars & "~`!@#$%^&*()_+=-|}{[]\:';<>?/.," & Chr(34) Case BitAND( $Options, 16 ); Include Others $Chars = $Chars & $OtherChars EndSelect If $Chars = "" Then Return -2 $CharArray = StringSplit( $Chars, "", 0 ) For $i = 1 to $Len $GenString = $GenString & $CharArray[Int(Random( 1, $CharArray[0] ))] Next Return $GenString EndFuncThanks guys!MattEDIT: Removed Debug code Edited December 26, 2004 by Matt @ MPCS Link to comment Share on other sites More sharing options...
Developers Jos Posted December 26, 2004 Developers Share Posted December 26, 2004 Its a known and solved bug. use the last Unstable and try again.... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted December 26, 2004 Author Share Posted December 26, 2004 Its a known and solved bug.use the last Unstable and try again.... <{POST_SNAPBACK}>Thanks JDeb, I wasn't sure.Matt Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted December 26, 2004 Author Share Posted December 26, 2004 Problem fixed! Below you will find my corrected code for those who are curious. Func GetRandString( $Len, $Options, $OtherChars = "" ) Dim $Chars, $CharArray, $GenString If Not StringIsInt( $Len ) Then Return -1 If BitAND( $Options, 1 ) Then; Include UpperCase $Chars = $Chars & "ABCDEFGHIJKLMNOPQRSTUVWXYZ" EndIf If BitAND( $Options, 2 ) Then; Include LowerCase $Chars = $Chars & "abcdefghijklmnopqrstuvwxyz" EndIf If BitAND( $Options, 4 ) Then; Include Numbers $Chars = $Chars & "0123456789" EndIf If BitAND( $Options, 8 ) Then; Include Special Characters $Chars = $Chars & "~`!@#$%^&*()_+=-|}{[]\:';<>?/.," & Chr(34) EndIf If BitAND( $Options, 4 ) Then; Include User Defined $Chars = $Chars & $OtherChars EndIf If $Chars = "" Then Return -2 $CharArray = StringSplit( $Chars, "", 0 ) For $i = 1 to $Len $GenString = $GenString & $CharArray[Int(Random( 1, $CharArray[0] ))] Next Return $GenString EndFunc Matt Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted December 27, 2004 Author Share Posted December 27, 2004 Small bug fixed. This is part of a String/Filename library I am working on for my clients, so as soon as I get it done I plan to post the whole library (Under scripts and scraps where it belongs). Thanks to those of you using my code. Func GetRandString( $Len, $Options, $OtherChars = "" ) Dim $Chars, $CharArray, $GenString If Not StringIsInt( $Len ) Then Return -1 If BitAND( $Options, 1 ) Then; Include UpperCase $Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" EndIf If BitAND( $Options, 2 ) Then; Include LowerCase $Chars = $Chars & "abcdefghijklmnopqrstuvwxyz" EndIf If BitAND( $Options, 4 ) Then; Include Numbers $Chars = $Chars & "0123456789" EndIf If BitAND( $Options, 8 ) Then; Include Special Characters $Chars = $Chars & "~`!@#$%^&*()_+=-|}{[]\:';<>?/.," & Chr(34) EndIf If BitAND( $Options, 16 ) Then; Include User Defined $Chars = $Chars & $OtherChars EndIf If $Chars = "" Then Return -2 $CharArray = StringSplit( $Chars, "", 0 ) For $i = 1 to $Len $GenString = $GenString & $CharArray[Int(Random( 1, $CharArray[0] ))] Next Return $GenString EndFunc Matt Link to comment Share on other sites More sharing options...
layer Posted December 28, 2004 Share Posted December 28, 2004 can't wait !! FootbaG 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