Jump to content

Arrays loops and functions


Mintz
 Share

Recommended Posts

I have the following function, its not done, but my first case statement is bring up some problems.

I want array $l to have $n elements, and the current element should be element $x which changers per loop. so when the whole loop is done i should have an array with $n amount of random letters but autoit is not accepting $l[$x] = etc...

all elements in $l are equal to 0

can someone shed some light on this, and or tell me what i'm doing wrong? thanks

Randomcreate(7)
Func Randomcreate($Lvl, $numbers = 0, $caps = 0, $symbols = 0)

    Select
    case $numbers = 0 and $caps = 0 and $symbols = 0
    $n = $lvl
    $x = 0
        dim $l[$n]
    while $x <> $n
        $l[$x] = Random(Chr("a"), chr("z"), 1)
        $x = $x + 1
    WEnd
    Return $l[0]&$l[2]
EndSelect
EndFunc
Link to comment
Share on other sites

I have the following function, its not done, but my first case statement is bring up some problems.

I want array $l to have $n elements, and the current element should be element $x which changers per loop. so when the whole loop is done i should have an array with $n amount of random letters but autoit is not accepting $l[$x] = etc...

all elements in $l are equal to 0

can someone shed some light on this, and or tell me what i'm doing wrong? thanks

Randomcreate(7)
Func Randomcreate($Lvl, $numbers = 0, $caps = 0, $symbols = 0)

    Select
    case $numbers = 0 and $caps = 0 and $symbols = 0
    $n = $lvl
    $x = 0
        dim $l[$n]
    while $x <> $n
        $l[$x] = Random(Chr("a"), chr("z"), 1)
        $x = $x + 1
    WEnd
    Return $l[0]&$l[2]
EndSelect
EndFunc
You are using Chr("a") but maybe you mean Asc("a") - see help.

How are you seeing what the elements in $l are? You have declared $l inside the function which means it will be a local variable and not seen outside. You need to declare it as Global and refer to it in the function, or even better, pass it to the function using ByRef.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi, this remebered me of an old funciton I created that I call "_RandomizeStr", it's basically a function that can be used for creating a random string, with a Prefix and Suffix if wanted, I'll post it here, if you wanna try it out:

$i_Lenght is the lenght of the string

$i_Mode is the mode it will use, first mode (0), is that it randomly creates a new random character on each loop through the string, the second mode (1), is that it creates 3 random chars(small letter, big letter, and a number), and randomly creates the string with those set characters

$s_Prefix, is optional, it takes a string, and adds that in front of the randomized string, same with $s_Suffix, but after the randomized string.

This is a quite good function to create quick and (quite) secure passwords, etc.

Func _RandomizeStr($i_Lenght, $i_Mode = 0, $s_Prefix = "", $s_Suffix = "")
    
    Local $s_Ret
    Local $a_RandomChars[3]
    
    If $i_Mode = 0 Then
        
        For $i = 1 To $i_Lenght
            
            $a_RandomChars[0] = Random(48, 57, 1)
            $a_RandomChars[1] = Random(97, 122, 1)
            $a_RandomChars[2] = Random(65, 90, 1)
            
            $s_Ret &= Chr($a_RandomChars[Random(0, 2, 1)])
            
        Next
        
    ElseIf $i_Mode = 1 Then
        
        $a_RandomChars[0] = Random(48, 57, 1)
        $a_RandomChars[1] = Random(97, 122, 1)
        $a_RandomChars[2] = Random(65, 90, 1)
        
        For $i = 1 To $i_Lenght
            
            $s_Ret &= Chr($a_RandomChars[Random(0, 2, 1)])
            
        Next
        
    EndIf
    
    Return $s_Prefix & $s_Ret & $s_Suffix

EndFuncoÝ÷ Ù©ÞÅ©©æ®¶­sbb33c´VÖÂÒõ&æFöÖ¦U7G"ÂÂgV÷C²gV÷C²ÂgV÷C´÷FÖÂæ6öÒgV÷C²

Would create a random email address to use

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