Jump to content

Wierd thing happening


Recommended Posts

$s_String = _RandomString(10)
MsgBox(0, "", $s_String)

Func _RandomString($iLen)
    Local $sStr = ""
    While Not StringLen($sStr) = $iLen
        ConsoleWrite( StringLen($sStr) & "=" & $iLen)
        If StringLen($sStr) Then
            $sTemp = Chr(Random(48, 122, 1))
            If StringRegExp($sTemp, "(?i)[a-z0-9]") Then $sStr &= $sTemp
        Else
            $sTemp = Chr(Random(48, 57, 1))
            If StringRegExp($sTemp, "(?i)[0-9]") Then $sStr &= $sTemp
        EndIf
        ConsoleWrite(@TAB & StringLen($sStr) & "=" & $iLen & @CRLF)
    WEnd
    
    Return $sStr
EndFunc   ;==>_RandomString

For some strange reasons it is only get the first character and exiting out of the func. I mean 1=10 is false those leading to true in my statement am I not right?

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

$s_String = _RandomString(10)
MsgBox(0, "", $s_String)

Func _RandomString($iLen)
    Local $sStr = ""
    While Not StringLen($sStr) = $iLen
        ConsoleWrite( StringLen($sStr) & "=" & $iLen)
        If StringLen($sStr) Then
            $sTemp = Chr(Random(48, 122, 1))
            If StringRegExp($sTemp, "(?i)[a-z0-9]") Then $sStr &= $sTemp
        Else
            $sTemp = Chr(Random(48, 57, 1))
            If StringRegExp($sTemp, "(?i)[0-9]") Then $sStr &= $sTemp
        EndIf
        ConsoleWrite(@TAB & StringLen($sStr) & "=" & $iLen & @CRLF)
    WEnd
    
    Return $sStr
EndFunc   ;==>_RandomStringoÝ÷ ØZ+²²ÚÚ«y«(È­Ê'(¶Ø^~*ìµÈZ­§-z¶§uìb¶)à¢ëh~Ø^~éÜ"g
Link to comment
Share on other sites

  • Moderators

While StringLen($sStr) < $iLen

or

While Not (StringLen($sStr) = $iLen)

Your statement says basically "While StringLen() = 0". So the first loop the statement is no longer true.

Edit:

Actually, it's more like Not 1 = 1, I guess that's like -2 = 1 ... :D

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Oh ya thats why, I just said that to someone else the other day, man I feel like a idoit. Thank you Smoke_N.

Also I know that I could do it without the NOT but was just curious to know how to do it, forgot to add the ()

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

  • Moderators

Oh ya thats why, I just said that to someone else the other day, man I feel like a idoit. Thank you Smoke_N.

Also I know that I could do it without the NOT but was just curious to know how to do it, forgot to add the ()

Might shed some insight:
Global $i_len = 4, $i_loop
While 1
    $i_loop += 1
    ConsoleWrite( _
        "Value of Not " & $i_loop & ", (equivlent of StringLen()) = " & Not $i_loop & @CRLF & _
        "Value of $i_len = " & ($i_len > 0) & @CRLF & _
        "True or False on equality = " & ((Not $i_loop) = $i_len) & @CRLF  & @CRLF)
    If ((Not $i_loop) = $i_len) Then ExitLoop
    If $i_loop = 10 Then $i_len = 0
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...