Sign in to follow this  
Followers 0
OneSeven

Variable type problem in compiled script

3 posts in this topic

#1 ·  Posted (edited)

I think I've found a bug in 3.2.1.13/14... the following code should execute silently, as none of the characters in $illegal_chars could possibly exist in the string sent to the function call... right? It works as expected in 3.2.0.1, but with the beta, there's something weird going on when the number 28 is found anywhere in the string. Somehow, the two numbers in sequence are being treated as a single character.

Sorry if I haven't explained it very well, but try running the following code in both the Release and the Beta versions and you'll see what I mean.

For $i = 1 To 100
    _ValidateString ("some text " & Random(1, 250, 1))
Next
Exit

Func _ValidateString($string)
;Check that there are no illegal characters in a string
;The string should contain alpha/numeric characters and  the period only.
    
    Local $illegal_chars = "(){}[]<>\/?,:;|~`'!@#$%^&*="""; if any of these chars are found, this function will return an error.
    Local $char
    
    For $char In StringSplit( $illegal_chars, "" );iterate through each $illegal_chars in turn
        If StringInStr ( $string, $char ) Then
            MsgBox ( 0, "Error", "Bad char found in string '" & $string & "', character:" & $char );debugging
            SetError (1)
            ExitLoop
        EndIf
    Next

    SetError ( 0 )

EndFunc

If others can verify that there's no problem with my code here, and this issue hasn't been raised previously, I suggest this topic be moved to bug reports.

EDIT: Sorry, just realised that title is misleading - wrote that before doing some further testing and forgot to change it. At the time I was running from SciTE with the Release version, but compiling with Beta.

Edited by OneSeven

Share this post


Link to post
Share on other sites



not sure what your trying to compare exactly, but you are comparing a number and a number ends up in the array when you do a stringsplit

here's your with a couple of consolewrites added in so you can see the what and why

; original
For $i = 1 To 100
    _ValidateString ("some text " & Random(1, 250, 1))
Next
Exit

Func _ValidateString($string)
;Check that there are no illegal characters in a string
;The string should contain alpha/numeric characters and  the period only.
    
    Local $illegal_chars = "(){}[]<>\/?,:;|~`'!@#$%^&*="""; if any of these chars are found, this function will return an error.
    Local $char
    
     ConsoleWrite("String: " & $string & @LF)
    For $char In StringSplit( $illegal_chars, "" );iterate through each $illegal_chars in turn
         ConsoleWrite("Char: " & $char & @LF)
        If StringInStr ( $string, $char ) Then
            MsgBox ( 0, "Error", "Bad char found in string '" & $string & "', character:" & $char );debugging
            SetError (1)
            ExitLoop
        EndIf
    Next

    SetError ( 0 )

EndFunc
oÝ÷ ØÚ0ò.׫²Ö§wZ·*.®Úòx-¡Ú-+"²ÞÁ¬¨}Ú"­jëh×6
; suggested
For $i = 1 To 100
    _ValidateString ("some text " & Chr(Random(1, 250, 1)))
Next
Exit

Func _ValidateString($string)
;Check that there are no illegal characters in a string
;The string should contain alpha/numeric characters and  the period only.
    
    Local $illegal_chars = "(){}[]<>\/?,:;|~`'!@#$%^&*="""; if any of these chars are found, this function will return an error.
    Local $char
    Local $a_chars = StringSplit( $illegal_chars, "" )
     ConsoleWrite("String: " & $string & @LF)
     For $x = 1 To $a_chars[0];iterate through each $illegal_chars in turn
        ConsoleWrite("Char: " & $a_chars[$x] & @LF)
        If StringInStr ( $string, $a_chars[$x] ) Then
            MsgBox ( 0, "Error", "Bad char found in string '" & $string & "', character:" & $a_chars[$x] );debugging
            SetError (1)
            ExitLoop
        EndIf
    Next

    SetError ( 0 )

EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

The first element returned by StringSplit is 28 because you have 28 elements in your string.

$char[0] = 28

$char[1] = (

$char[2] = )

.....

Remove an element and you will see that your function shows 27 to be a "illegal".

Work thru the changelog and you might find why beta is different than the production version for your function, I do not know.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


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
Sign in to follow this  
Followers 0