Jump to content

Recommended Posts

Posted

I've just started AutoIt today, and it sounds awesome. I'm pretty experienced with the programming language "Lua", and I've also used a bit of BASIC. However, I don't know the specifics on the syntax and I've fixed it up as much as I can just by using the build-in syntax error finder. However, it keeps reporting undeclared variables, so I'm not sure what to do with that. The method I used is also probably much more complicated than it has to be, but whatever. Anyways, here's my script:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.2.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

Func Char()
    $char=Random(1,36,1)
    
    if $char==1 Then
    $endchar="a"
    EndIf
    if $char==2 Then
    $endchar="b"
    EndIf
    if $char==3 Then
    $endchar="c"
    EndIf
    if $char==4 Then
    $endchar="d"
    EndIf
    if $char==5 Then
    $endchar="e"
    EndIf
    if $char==6 Then
    $endchar="f"
    EndIf
    if $char==7 Then
    $endchar="g"
    EndIf
    if $char==8 Then
    $endchar="h"
    EndIf
    if $char==9 Then
    $endchar="i"
    EndIf
    if $char==10 Then
    $endchar="j"
    EndIf
    if $char==11 Then
    $endchar="k"
    EndIf
    if $char==12 Then
    $endchar="l"
    EndIf
    if $char==13 Then
    $endchar="m"
    EndIf
    if $char==14 Then
    $endchar="n"
    EndIf
    if $char==15 Then
    $endchar="o"
    EndIf
    if $char==16 Then
    $endchar="p"
    EndIf
    if $char==17 Then
    $endchar="q"
    EndIf
    if $char==18 Then
    $endchar="r"
    EndIf
    if $char==19 Then
    $endchar="s"
    EndIf
    if $char==20 Then
    $endchar="t"
    EndIf
    if $char==21 Then
    $endchar="u"
    EndIf
    if $char==22 Then
    $endchar="v"
    EndIf
    if $char==23 Then
    $endchar="w"
    EndIf
    if $char==24 Then
    $endchar="x"
    EndIf
    if $char==25 Then
    $endchar="y"
    EndIf
    if $char==26 Then
    $endchar="z"
    EndIf
    if $char==27 Then
    $endchar="0"
    EndIf
    if $char==28 Then
    $endchar="1"
    EndIf
    if $char==29 Then
    $endchar="2"
    EndIf
    if $char==30 Then
    $endchar="3"
    EndIf
    if $char==31 Then
    $endchar="4"
    EndIf
    if $char==32 Then
    $endchar="5"
    EndIf
    if $char==33 Then
    $endchar="6"
    EndIf
    if $char==34 Then
    $endchar="7"
    EndIf
    if $char==35 Then
    $endchar="8"
    EndIf
    if $char==36 Then
    $endchar="9"
    EndIf
    Return $endchar
EndFunc

Func MakeString()
    $numchars=Random(4,8)
    For $count = 1 to $numchars
        Char()
        Execute("$char_" & $count & "=" & $endchar)
    Next
    if $numchars==4 Then
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4
    EndIf
    if $numchars==5 Then
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5
    EndIf
    if $numchars==6 Then
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5 & $char_6
    EndIf
    if $numchars==7 Then
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5 & $char_6 & $char_7
    EndIf
    if $numchars==8 Then
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5 & $char_6 & $char_7 & $char_8
    EndIf
EndFunc

MakeString()

Send($finalstring)

And here's the errors:

>C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\Documents and Settings\Aric\Desktop\npad.au3"
AutoIt3 Syntax Checker v1.54  Copyright (c) Tylo 2006

C:\Documents and Settings\Aric\Desktop\npad.au3(131,45) : WARNING: $endchar: possibly used before declaration.
        Execute("$char_" & $count & "=" & $endchar)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(134,23) : WARNING: $char_1: possibly used before declaration.
    $finalstring=$char_1 &
    ~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(134,33) : WARNING: $char_2: possibly used before declaration.
    $finalstring=$char_1 & $char_2 &
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(134,43) : WARNING: $char_3: possibly used before declaration.
    $finalstring=$char_1 & $char_2 & $char_3 &
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(134,52) : WARNING: $char_4: possibly used before declaration.
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(137,62) : WARNING: $char_5: possibly used before declaration.
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(140,72) : WARNING: $char_6: possibly used before declaration.
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5 & $char_6
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(143,82) : WARNING: $char_7: possibly used before declaration.
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5 & $char_6 & $char_7
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(146,92) : WARNING: $char_8: possibly used before declaration.
    $finalstring=$char_1 & $char_2 & $char_3 & $char_4 & $char_5 & $char_6 & $char_7 & $char_8
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(153,18) : WARNING: $finalstring: possibly used before declaration.
Send($finalstring)
~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3(131,45) : ERROR: $endchar: undeclared global variable.
        Execute("$char_" & $count & "=" & $endchar)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Aric\Desktop\npad.au3 - 1 error(s), 10 warning(s)
>Exit code: 2   Time: 0.208

If any of you AutoIt Pros out there could fix this up for me, that'd be great. Thank you for reading.

  • Moderators
Posted (edited)

I would try to learn how AutoIt arrays work, your life would be much easier.... Execute can't split up vars, you may want to look at Assign() or Eval().

Edit:

Also, you have $finalstring declared in a local scope within a function, but the way you are using send (outside the function) you are acting like it is a Global Var.

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.

Posted

  SmOke_N said:

I would try to learn how AutoIt arrays work, your life would be much easier.... Execute can't split up vars, you may want to look at Assign() or Eval().

Edit:

Also, you have $finalstring declared in a local scope within a function, but the way you are using send (outside the function) you are acting like it is a Global Var.

Hmm, I think I know what you're saying about locals. You see, in the version of lua I used to use, you'd define a variable like:

Variable=10

And then, to put it in a string, you'd do:

print("/"Variable/" is: "..Variable.."!")
[code]

Which would return:
[code]
"Variable" is: 10!

But variable would automatically be a global var. If you wanted something to be local to a function, you'd use:

local Variable=10

So this automatically makes a var local to a function if it's in one? Hmm, alright then...

  • Moderators
Posted

Let me see if I can shorten that for you just a tad:

;Send(_MakeString())
MsgBox(0, '', _MakeString())
Func _MakeString()
    Local $aSplit = StringSplit('abcdefghijklmnopqrstuvwxyz0123456789', '')
    Local $sHoldString = ''
    For $iCC = 1 To Random(4, 8, 1)
        $sHoldString &= $aSplit[Random(1, 36, 1)]
    Next
    Return $sHoldString
EndFunc
Uncomment Send and comment msgbox to actually send.

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.

Posted

  SmOke_N said:

Let me see if I can shorten that for you just a tad:

;Send(_MakeString())
MsgBox(0, '', _MakeString())
Func _MakeString()
    Local $aSplit = StringSplit('abcdefghijklmnopqrstuvwxyz0123456789', '')
    Local $sHoldString = ''
    For $iCC = 1 To Random(4, 8, 1)
        $sHoldString &= $aSplit[Random(1, 36, 1)]
    Next
    Return $sHoldString
EndFunc
Uncomment Send and comment msgbox to actually send.
I knew there must have been a more simple way. Thank you!
  • Moderators
Posted
  mblunk said:

I knew there must have been a more simple way. Thank you!

NP, when and if I ever play with Lua, I'll come find you to answer some questions for me :whistle:

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.

  • 4 weeks later...
Posted

  SmOke_N said:
Let me see if I can shorten that for you just a tad:

;Send(_MakeString())
MsgBox(0, '', _MakeString())
Func _MakeString()
    Local $aSplit = StringSplit('abcdefghijklmnopqrstuvwxyz0123456789', '')
    Local $sHoldString = ''
    For $iCC = 1 To Random(4, 8, 1)
        $sHoldString &= $aSplit[Random(1, 36, 1)]
    Next
    Return $sHoldString
EndFuncoÝ÷ ÙIÜ¢iÔÖ§uÊ&éíÈ£hiËnjYr±éÝþ«¨µâj}ý¶­¶¬±Êâ¦Ü(®DÊËaj׫®âX§{¦®¶­s`¢f÷"b33c¶42ÒFò&æFöÒBÂÂ

So is the problem in me or what :whistle:

Posted (edited)

  Mr. Zero said:

Works for me. Post the errors... :whistle:

Errors:

CODE

Line 6 (File "\randomstringgenenerator.au3"):

For $iCC = 1 To Random (4, 8, 1)

For $iCC = 1 To ^ ERROR

Error: Incorrect number parameters in function call.

Suggestions?

EDIT: Uff, I had an old version of AutoIt :P

Edited by ValdeZ
Posted

  ValdeZ said:

Errors:

CODE

Line 6 (File "\randomstringgenenerator.au3"):

For $iCC = 1 To Random (4, 8, 1)

For $iCC = 1 To ^ ERROR

Error: Incorrect number parameters in function call.

Suggestions?

What the...?

What version do you have of AutoIt?

It is the right function...

Posted

  Mr. Zero said:

What the...?

What version do you have of AutoIt?

It is the right function...

I don't know what was it, maybe AutoIt 2? But anyway, now it works.

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