Sign in to follow this  
Followers 0
Skrip

No WEnd? Error

7 posts in this topic

main()



Func main()
$bLoop = 1
While $bLoop = 1
    $text = InputBox("Phone Number Finder", "Please enter the name of the number..." & @LF & "Type /add to enter a number")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
    Else
        If $text = "/add" Then
            $bLoop = 0
            _add()
        Else
        If $text <> "/add" Then
            $bLoop = 0
            _read()
        EndIf
    EndIf
WEnd

Func _add()
    $add_p = InputBox("Add A Phone Number", "Please enter the phone number you want to add.")
    $add_n = InputBox("Add A Name", "Please enter the name of the person whose number you just entered.")
    IniWrite(@ScriptDir & "\Numbers.ini", $add_n, $add_n, $add_p)
    Msgbox(0, "Number Added", "Name and number added to database.")
    main()
EndFunc

Func _read()
    $number_m = IniRead(@ScriptDir & "\Numbers.ini", $text, $text)
    MsgBox(0, "Number", $number_m)
    main()
EndFunc

Why doesn't this work?


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites



main ()

Global $name, $number

Func main ()
$bLoop = 1
While $bLoop = 1
    $name = InputBox("Phone Number Finder", "Please enter the name of the person..." & @LF & "Type /add to enter a number")
 $number = InputBox("Phone Number Finder", "Please enter the number of the person...")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
    Else
        If $name = "/add" Then
            $bLoop = 0
            _add()
        ElseIf $name <> "/add" Then
            $bLoop = 0
            _read()
        EndIf
    EndIf
WEnd
EndFunc

Func _add ()
    $add_p = InputBox("Add A Phone Number", "Please enter the phone number you want to add.")
    $add_n = InputBox("Add A Name", "Please enter the name of the person whose number you just entered.")
    IniWrite(@ScriptDir & "\Numbers.ini", $add_n, $add_n, $add_p)
    Msgbox(0, "Number Added", "Name and number added to database.")
    main()
EndFunc

Func _read ()
    $number_m = IniRead(@ScriptDir & "\Numbers.ini", $name, $name, $number)
    MsgBox(0, "Number", $number_m)
    main()
EndFunc

Exit
Nomad :D

Share this post


Link to post
Share on other sites

Thanks


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

[new error]

C:\AutoIt3\Phone_Number_Holder.au3 (33) : ==> Variable used without being declared.: 
$number_m = IniRead(@ScriptDir & "\Numbers.ini", $name, $name, $number) 
$number_m = IniRead(@ScriptDir & "\Numbers.ini", ^ ERROR

Code, had to change some things around so it can read the number also, and not only write.

Do /add then add some random number, with the name of Me or something. Then in the starting one, try and get it to find Me

main ()

Global $name, $number

Func main ()
$bLoop = 1
While $bLoop = 1
    $name = InputBox("Phone Number Finder", "Please enter the name of the person..." & @LF & "Type /add to enter a number")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - try again!")
    Else
        If $name = "/add" Then
            $bLoop = 0
             $number = InputBox("Phone Number Finder", "Please enter the number of the person...")
            _add()
        ElseIf $name <> "/add" Then
            $bLoop = 0
            _read()
        EndIf
    EndIf
WEnd
EndFunc

Func _add ()
    $add_p = InputBox("Add A Phone Number", "Please enter the phone number you want to add.")
    $add_n = InputBox("Add A Name", "Please enter the name of the person whose number you just entered.")
    IniWrite(@ScriptDir & "\Numbers.ini", $add_n, $add_n, $add_p)
    Msgbox(0, "Number Added", "Name and number added to database.")
    main()
EndFunc

Func _read ()
    $number_m = IniRead(@ScriptDir & "\Numbers.ini", $name, $name, $number)
    MsgBox(0, "Number", $number_m)
    main()
EndFunc

Exit
Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

Couple of problems:

  • main() is your first line, so the function starts before your variables can be are declared.
  • You're needlessly using $number as the default INIRead value in _read()
  • Your functions are calling main(), which will fill the stack and cause recursion errors.
I tweaked it as follows:

Pressing ESC/cancel will quit the app from the main prompt or abort during the _add function.

Global $name, $number
main()

Func main()
    
    While 1
        $name = InputBox("Phone Number Finder", "Please enter the name of the person..." & @LF & "Type /add to enter a number")
        If @error = 1 Then
            Exit
        Else
            If $name = "/add" Then
                _add()
            ElseIf $name <> "/add" Then
                _read()
            EndIf
        EndIf
    WEnd
EndFunc   ;==>main

Func _add()
    Local $add_p = InputBox("Add A Phone Number", "Please enter the phone number you want to add.")
    if @Error then Return
    Local $add_n = InputBox("Add A Name", "Please enter the name of the person whose number you just entered.")
    if @Error then Return
    IniWrite(@ScriptDir & "\Numbers.ini", $add_n, $add_n, $add_p)
    MsgBox(0, "Number Added", "Name and number added to database.")
EndFunc   ;==>_add

Func _read()
    Local $number_m = IniRead(@ScriptDir & "\Numbers.ini", $name, $name, $name & " not found.")
    MsgBox(0, "Number", $number_m)
EndFunc   ;==>_read

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Wow, Thank you. I didn't relise those errors.


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Oops, I made a couple errors myself. Sorry about that. I'm a little pre-occupied with a problem of my own right now so I king of rushed through your script.

Nomad :D

Edited by Nomad

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