Jump to content

HELP! Please solve this!


Recommended Posts

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!

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!!! >;)

Link to comment
Share on other sites

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

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

instead of using while 1 loops, make them functions.

_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

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Testing a string against the keyword True will probably not give the result you expect.

Refer to the Help file (again).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

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.

_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!

Link to comment
Share on other sites

Hello reecedorward,

Is this what you are trying to acomplish?

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

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Hello reecedorward,

Is this what you are trying to acomplish?

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:

_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!

Link to comment
Share on other sites

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

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

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

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:

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