Jump to content



Photo

HELP! Please solve this!


  • Please log in to reply
8 replies to this topic

#1 reecedorward

reecedorward

    Seeker

  • Active Members
  • 27 posts

Posted 28 April 2012 - 01:59 AM

I have been to the help files, posted previously on here and been directed to the help files, but that doesnt help on the account that im new at this and I physically need someone to solve this code for me to understand how it should be written or what function goes where etc.... I have even tried to google possible solutions, which is quite hard becase im not too sure if what im googling for will get me the answer!

AutoIt         
While 1 Local $test1 = InputBox("Test1", "Test1", "Type a Number") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test1 = True Then   ExitLoop EndIf WEnd While 1 Local $test2 = InputBox("Test2", "Test2", "Type a Number Again") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test2 = True Then   ExitLoop EndIf WEnd Local $goto = MsgBox(4,"Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox")   If $goto = 6 Then ;### Goto $test1 InputBox   If $goto = 7 Then ;### Goto $test2 InputBox   EndIf   EndIf


Curse this script, ive been trying to figure it out all morning!!! >;)





#2 Realm

Realm

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 608 posts

Posted 28 April 2012 - 02:44 AM

Hello reecedorward,

Your script works fine on my end, Maybe I don't understand what it is that you intend on it doing for you. If you could explain a little more about what your trying to achieve, what it is not doing that you expect it to do. Then maybe we could give you a suggestion or two in the right direction.

Realm
...and then we shall see if your insanity can be cured!______________________________________________________________________My Contributions: RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.

#3 kaotkbliss

kaotkbliss

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,106 posts

Posted 28 April 2012 - 02:56 AM

instead of using while 1 loops, make them functions.

AutoIt         
  _Test1() Func _test1() Local $test1 = InputBox("Test1", "Test1", "Type a Number") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test1 = True Then   ; EndIf EndFunc _Test2() Func _Test2() Local $test2 = InputBox("Test2", "Test2", "Type a Number Again") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test2 = True Then   ; EndIf EndFunc Local $goto = MsgBox(4,"Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox")   If $goto = 6 Then _Test1();### Goto $test1 InputBox   If $goto = 7 Then _Test2();### Goto $test2 InputBox


*edit* forgot to remove the loops lol

Edited by kaotkbliss, 28 April 2012 - 02:58 AM.

Posted Image010101000110100001101001011100110010000001101001011100110010000001101101011110010010000001110011011010010110011100100001My first project Allin1 Program launcherBill CalculatorGot <Insert problem here>?There's an AutoIt script for that!

#4 jchd

jchd

    Whatever your capacity, resistance is futile.

  • MVPs
  • 3,247 posts

Posted 28 April 2012 - 04:19 AM

Testing a string against the keyword True will probably not give the result you expect.
Refer to the Help file (again).
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQL tutorial (covers generic SQL, but most of it apply to SQLite as well)An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious workPCRE v8.32 regexp pattern documentation. AutoIt uses a slightly older version so that more advanced features are not all available.RegExp tutorial: enough to get started

#5 reecedorward

reecedorward

    Seeker

  • Active Members
  • 27 posts

Posted 28 April 2012 - 05:58 AM

Hello reecedorward,

Your script works fine on my end, Maybe I don't understand what it is that you intend on it doing for you. If you could explain a little more about what your trying to achieve, what it is not doing that you expect it to do. Then maybe we could give you a suggestion or two in the right direction.

Realm

Basically when the script gets to the msgbox at the end.. I want to be able to direct the script back to the first inputbox by pressing Yes on the msgbox or to direct the script back to the second inputbox by pressing No...
So to try and map it out it goes like this:

FIRST INPUTBOX (type a number and click OK to goto the second inputbox)

Type a number, clicks OK

SECOND INPUTBOX (type a number and click OK to goto the msgbox)

Type a number, clicks OK

MSGBOX (click Yes to go back to the first inputbox or click no to go back to the second inputbox)

User presses YES

FIRST INPUTBOX (Here we are again back at the top of the script)

But if the user presses no when the script is at the MSGBOX it would go to the second inputbox

Does this help explain it any better?

instead of using while 1 loops, make them functions.

AutoIt         
_Test1() Func _test1() Local $test1 = InputBox("Test1", "Test1", "Type a Number") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test1 = True Then   ; EndIf EndFunc _Test2() Func _Test2() Local $test2 = InputBox("Test2", "Test2", "Type a Number Again") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test2 = True Then   ; EndIf EndFunc Local $goto = MsgBox(4,"Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox")   If $goto = 6 Then _Test1();### Goto $test1 InputBox   If $goto = 7 Then _Test2();### Goto $test2 InputBox


*edit* forgot to remove the loops lol

This ACTUALLY WORKS! Though now I have encountered another problem... when i click "YES" when the msgbox is up at the end... it DOES take me back to the first inputbox... but when I goto type a number in and click ok... the script ends??? it doesnt continue to the second input box :S

Man, so close to getting it!

#6 Realm

Realm

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 608 posts

Posted 28 April 2012 - 07:15 AM

Hello reecedorward,

Is this what you are trying to acomplish?
AutoIt         
Local $goto _Test1() _Test2() While 1    $goto = MsgBox(4,"Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox")    MsgBox(0, '', $goto)    If $goto = 6 Then       _Test1();### Goto $test1 InputBox    ElseIf $goto = 7 Then       _Test2();### Goto $test2 InputBox    Else       ;do something else, or maybe exit application    EndIf WEnd Exit Func _test1()    Local $test1 = InputBox("Test1", "Test1", "Type a Number")    If @error Then       $exit = MsgBox(4, "Exit?", "Are you sure?")       If $exit = 6 Then Exit    EndIf    If $test1 = True Then       ;    EndIf EndFunc Func _Test2()     Local $test2 = InputBox("Test2", "Test2", "Type a Number Again")     If @error Then       $exit = MsgBox(4, "Exit?", "Are you sure?")       If $exit = 6 Then Exit    EndIf    If $test2 = True Then       ;    EndIf EndFunc


Realm
...and then we shall see if your insanity can be cured!______________________________________________________________________My Contributions: RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.

#7 reecedorward

reecedorward

    Seeker

  • Active Members
  • 27 posts

Posted 28 April 2012 - 11:52 AM

Hello reecedorward,

Is this what you are trying to acomplish?

AutoIt         
Local $goto _Test1() _Test2() While 1    $goto = MsgBox(4,"Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox")    MsgBox(0, '', $goto)    If $goto = 6 Then       _Test1();### Goto $test1 InputBox    ElseIf $goto = 7 Then       _Test2();### Goto $test2 InputBox    Else       ;do something else, or maybe exit application    EndIf WEnd Exit Func _test1()    Local $test1 = InputBox("Test1", "Test1", "Type a Number")    If @error Then       $exit = MsgBox(4, "Exit?", "Are you sure?")       If $exit = 6 Then Exit    EndIf    If $test1 = True Then       ;    EndIf EndFunc Func _Test2()     Local $test2 = InputBox("Test2", "Test2", "Type a Number Again")     If @error Then       $exit = MsgBox(4, "Exit?", "Are you sure?")       If $exit = 6 Then Exit    EndIf    If $test2 = True Then       ;    EndIf EndFunc


Realm

This is the CLOSEST SOLUTION I have had yet! Thanks for that... Though I have edited your script around a little and I came up with this:

AutoIt         
_Test1() _Test2() Local $goto Func _test1() Local $test1 = InputBox("Test1", "Test1", "Type a Number") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf If $test1 = True Then _Test2() ; EndFunc   ;==>_test1 Func _Test2() Local $test2 = InputBox("Test2", "Test2", "Type a Number Again") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf   ; EndFunc   ;==>_Test2 While 1 $goto = MsgBox(4, "Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox") If $goto = 6 Then   _Test1();### Goto $test1 InputBox ElseIf $goto = 7 Then   _Test2();### Goto $test2 InputBox Else   ;do something else, or maybe exit application EndIf WEnd Exit


Run this script and you will see that all but 1 error remains.. and that is after you type a number in the first inputbox, it goes to the second inputbox.. which is all good untill you goto type a number into the second inputbox, it for some reason (instead of going to the final msgbox) brings up the second inputbox for a second time.. AND THEN.. it goes to the msgbox... after that the loop then becomes exactly how I wanted it and nothing goes wrong..
I just cant figure out why the script makes the second inputbox come up twice the first time round....

If anyone knows why or how to prevent this, please feel free to let me know,

Thanks for everyones help!

#8 jchd

jchd

    Whatever your capacity, resistance is futile.

  • MVPs
  • 3,247 posts

Posted 28 April 2012 - 12:53 PM

It looks like this is what you want to achieve. Note that by adding a condition variable you can drive the logic flow and make the program clearer instead of "going" here and there and invoking test1 or test2 from several places, which is much harder to follow. The best proof of what I'm trying to say is that yourself can't see why test2 is run twice.
Hint: it's just because of what I tried to make you see in my previous post (which you ignored).
AutoIt         
Local $whatnext, $firstRun = True While 1 If $firstRun Then   $whatnext = 6 Else   $whatnext = MsgBox(4, "Time to go back", "Press Yes to bring $test1 Inputbox or press No to bring $test2 Inputbox") EndIf If $whatnext = 6 Then   _Test1() ;### $test1 InputBox   If $firstRun Then    $whatnext = 7    $firstRun = False   EndIf EndIf If $whatnext = 7 Then   _Test2() ;### $test2 InputBox Else   ;do something else, or maybe exit application EndIf WEnd Func _test1() Local $test1 = InputBox("Test1", "Test1", "Type a Number") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf ; EndFunc   ;==>_test1 Func _Test2() Local $test2 = InputBox("Test2", "Test2", "Type a Number Again") If @error Then   $exit = MsgBox(4, "Exit?", "Are you sure?")   If $exit = 6 Then Exit EndIf ; EndFunc   ;==>_Test2

Make yourself a favor and ban the words GOTO and BRANCH from your coding vocabulary. Use building blocks and the word PERFORM instead:
While <condition>
perform_that()
end While

If <other condition>
perform_this()
end if

Edited by jchd, 28 April 2012 - 12:55 PM.

SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQL tutorial (covers generic SQL, but most of it apply to SQLite as well)An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious workPCRE v8.32 regexp pattern documentation. AutoIt uses a slightly older version so that more advanced features are not all available.RegExp tutorial: enough to get started

#9 reecedorward

reecedorward

    Seeker

  • Active Members
  • 27 posts

Posted 29 April 2012 - 01:41 AM

Thankyou jchd, Realm & kaotkbliss!

You have all been very helpful (and patient) :)

It's all a learning process for me, and have learned alot already since first finding out about AutoIt. I had a mate show me his way of doing it, which worked to an extent, though I managed to edit it further and accomplish the EXACT result I was looking for. Here is the final script:

AutoIt         
Call("Test1f") Func test1f() While 1 Local $test1 = InputBox("Test1", "Test1", "Type a Number") If @error Then $exit = MsgBox(4, "Exit?", "Are you sure?") If $exit = 6 Then Exit EndIf If $test1 = True Then Call("test2f") EndIf WEnd EndFunc ;==>test1f Call("Test2f") Func test2f() While 1 Local $test2 = InputBox("Test2", "Test2", "Type a Number Again") If @error Then $exit = MsgBox(4, "Exit?", "Are you sure?") If $exit = 6 Then Exit EndIf If $test2 = True Then Call("test3f") EndIf WEnd EndFunc ;==>test2f Call("Test3f") Func test3f() While 1 Local $goto = MsgBox(4, "Time to go back", "Press Yes to goto $test1 Inputbox or press No to goto $test2 Inputbox") If $goto = 6 Then Call("Test1f") If $goto = 7 Then Call("Test2f") WEnd EndFunc


;)

Edited by reecedorward, 29 April 2012 - 01:41 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users