Jump to content

How to restart or loop? And help.


Recommended Posts

Ok, I was just testing this out so then I can modifiy it and put it in my other script, but I ran into this problem...

Here is the code:

$var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

If @error Then
    $var_1 = MsgBox(1, "Error", "No File(s) chosen")
Else
    $var_2 = MsgBox(1, "Success!", "You chose " & $var)
EndIf

If $var_1 = 1 Then
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)
EndIf

If $var_2 = 2 Then
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)
EndIf

When you run the script a FileOpenDialog pops up. If you press "cancel" then it will say "Error", "No File(s) chosen", with "Ok" and "cancel".

If you press "Ok" it will open another FileOpenDialog. If you press "cancel", it will close.

The problem IS:

If you press "cancel" AGAIN after you pressed "cancel" on the first FileOpenDialog, it will just close, instead of repeating the MsgBox.

I need to insert something that restarts the script at a certain line. Like so:

$var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

If @error Then
    $var_1 = MsgBox(1, "Error", "No File(s) chosen")
Else
    $var_2 = MsgBox(1, "Success!", "You chose " & $var)
EndIf

If $var_1 = 1 Then
    RestartScript (1)
EndIf

If $var_2 = 2 Then
    RestartScript (1)
EndIf

The parameter 1 is which line it should restart on.

What function does this?

Link to comment
Share on other sites

Not sure I completely understood, but this might work.

Local $var, $var_1, $var_2

openfile()

While 1
    Sleep(100)
WEnd

Func openfile()
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(1, "Error", "No File(s) chosen")
    Else
        $var_2 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_1 = 1 Then
        openfile()
    Else
        Exit
    EndIf

    If $var_2 = 2 Then
        openfile()
    Else
        Exit
    EndIf
EndFunc
Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Not sure I completely understood, but this might work.

Local $var, $var_1, $var_2

openfile()

While 1
    Sleep(100)
WEnd

Func openfile()
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(1, "Error", "No File(s) chosen")
    Else
        $var_2 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_1 = 1 Then
        openfile()
    Else
        Exit
    EndIf

    If $var_2 = 2 Then
        openfile()
    Else
        Exit
    EndIf
EndFunc

It worked! But only when you press "cancel" and it says "Error"...

Ok, this is REALLY weird, I quadruple checked this script and everything seems fine, but when I open a file and it says "Success!" ($var_2) I press Cancel and it doesn't go back. It did the same thing in the other script (the first one I posted.).

This part of the script:

If $var_2 = 2 Then
        openfile()

Is not working...

On a side note:

Yes, I think you understood. What's the

While 1
    Sleep(100) WEnd

for? Is it for speeding up the script? When do I implement this? In every script?

Edited by miketh2005
Link to comment
Share on other sites

It worked! But only when you press "cancel" and it says "Error"...

Ok, this is REALLY weird, I quadruple checked this script and everything seems fine, but when I open a file and it says "Success!" ($var_2) I press Cancel and it doesn't go back. It did the same thing in the other script (the first one I posted.).

This part of the script:

If $var_2 = 2 Then
        openfile()

Is not working...

On a side note:

Yes, I think you understood. What's the

While 1
    Sleep(100) WEnd

for? Is it for speeding up the script? When do I implement this? In every script?

The

While 1
sleep(500)
WEnd

keeps your script from closing.

Remember when you script runs to the end it will close. Just think.

...

...

...

...

Exit

Even the exit is not there. Edited by athiwatc
Link to comment
Share on other sites

Ok, this is freakin WEIRD!

I edited the script so it's like this:

Global $var, $var_1, $var_2

openfile()

While 1
    Sleep(100)
WEnd

Func openfile()
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(1, "Error", "No File(s) chosen")
    Else
        $var_2 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_2 = 2 Then
        openfile()
    Else
        Exit
    EndIf

    If $var_1 = 1 Then
        openfile()
    Else
        Exit
    EndIf
EndFunc

NOW, if you select a picture and hit "cancel", it works! BUT, if you hit "cancel" when the OpenFileDialog is up and then hit ANY button, it will open the OpenFileDialog again. LOL, what's wrong with this freakin script? It either doesn't work or it works when it's not supposed to...

Edited by miketh2005
Link to comment
Share on other sites

The problem is with this line, you should as a RULE you should NEVER use "two" "if"s one after the other if it basically check the same thing!

If $var_2 = 2 Then
        openfile()
    Else
        Exit
    EndIf

    If $var_1 = 1 Then
        openfile()
    Else
        Exit
    EndIf

The $var_2 "alway" execute before $var_1 does.

Here the fix.

Global $var, $var_1


While 1
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(1, "Error", "No File(s) chosen")
    Else
        $var_1 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_1 <> 1 Then
        Exit
    EndIf

WEnd
Edited by athiwatc
Link to comment
Share on other sites

I know this doesn't answer the question..

But think about it,

The open file Dialog opens and the user hit's cancel as they have changed their mind..

As if the user want's to be prompted over and over again with Yes/No/OK/Cancel boxes..

Arggg, it's like windows vista with uac.. "Are You Sure?", ohh hang on your canceling, "Are You Sure?", ohh your canceling your cancel "are you sure your sure about being sure"..

Lmao

No offence meant as the whole msgbox idea is a good way to learn loops, but please tell me your not going to put it in a program for users to *cough* enjoy. lol

Link to comment
Share on other sites

The problem is with this line, you should as a RULE you should NEVER use "two" "if"s one after the other if it basically check the same thing!

If $var_2 = 2 Then
        openfile()
    Else
        Exit
    EndIf

    If $var_1 = 1 Then
        openfile()
    Else
        Exit
    EndIf

The $var_2 "alway" execute before $var_1 does.

Here the fix.

Global $var, $var_1


While 1
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(1, "Error", "No File(s) chosen")
    Else
        $var_1 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_1 <> 1 Then
        Exit
    EndIf

WEnd

Thanks for your help.

That doesn't work because if you see the code, I want $var_2 = 2 and $var_1 = 1.

This code works without bugs, but when you press "OK" after you select an image, it goes back to the OpenFileDialog... it should be when you press "OK" it closes.

I know this doesn't answer the question..

But think about it,

The open file Dialog opens and the user hit's cancel as they have changed their mind..

As if the user want's to be prompted over and over again with Yes/No/OK/Cancel boxes..

Arggg, it's like windows vista with uac.. "Are You Sure?", ohh hang on your canceling, "Are You Sure?", ohh your canceling your cancel "are you sure your sure about being sure"..

Lmao

No offence meant as the whole msgbox idea is a good way to learn loops, but please tell me your not going to put it in a program for users to *cough* enjoy. lol

What if the user selected a file and pressed cancel instead of OK? He will think my program doesn't work. Users CAN NOT be THAT lazy. It takes 2 seconds at most to press "OK".

But thanks for saying that, because I just realized. I don't have to make the MsgBox have a OK and Cancel button. just an OK button so that the user knows that no file was selected. If they made a mistake they can always go back into it. Thanks.

But I would still like an answer to this question so that I can learn from it, because I'm sure this will come up again in another script.

Edited by miketh2005
Link to comment
Share on other sites

... If you press "Ok" it will open another FileOpenDialog. If you press "cancel", it will close.

The problem IS:

If you press "cancel" AGAIN after you pressed "cancel" on the first FileOpenDialog, it will just close, instead of repeating the MsgBox.

try this
While 1
    $file = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(5, "Error", "No File(s) chosen")
        If $var_1 = 2 Then Exit
        If $var_1 = 4 Then ContinueLoop
    EndIf

    MsgBox(0, "Success!", "You chose " & $file)
    ExitLoop
WEnd

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Thanks for your help.

That doesn't work because if you see the code, I want $var_2 = 2 and $var_1 = 1.

This code works without bugs, but when you press "OK" after you select an image, it goes back to the OpenFileDialog... it should be when you press "OK" it closes.

What if the user selected a file and pressed cancel instead of OK? He will think my program doesn't work. Users CAN NOT be THAT lazy. It takes 2 seconds at most to press "OK".

But thanks for saying that, because I just realized. I don't have to make the MsgBox have a OK and Cancel button. just an OK button so that the user knows that no file was selected. If they made a mistake they can always go back into it. Thanks.

But I would still like an answer to this question so that I can learn from it, because I'm sure this will come up again in another script.

YAY! My first ALMOST made from scratch script is done >_<

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\rce_aw_wierd\hacks\soldat.kxf
Global $Form1_1 = GUICreate("DJ5's Soldat and Notepad Opener", 637, 445, 206, 152)
GUISetIcon("C:\Documents and Settings\Mike\My Documents\Icons\Icons\Devices\84.ico")
GUISetBkColor(0x800000)
Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Mike\My Documents\My Pictures\soldat DS.jpg", 0, 0, 636, 444, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Button1 = GUICtrlCreateButton("Open Notepad", 272, 376, 83, 25, $WS_GROUP, $WS_EX_CLIENTEDGE)
GUICtrlSetCursor(-1, 3)
Global $Button2 = GUICtrlCreateButton("Open Soldat", 279, 178, 75, 25, $WS_GROUP, $WS_EX_CLIENTEDGE)
GUICtrlSetCursor(-1, 3)
Global $Button3 = GUICtrlCreateButton("About", 416, 304, 83, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 3)
Global $Label1 = GUICtrlCreateLabel("Not working? Browse for Soldat.", 239, 205, 156, 17)
GUICtrlSetBkColor(-1, 0xC0C0C0)
Global $Button4 = GUICtrlCreateButton("Browse...", 280, 224, 75, 17, $WS_GROUP)
GUICtrlSetCursor(-1, 3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $var, $var_1

$var = "C:\Soldat\Soldat.exe"


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Run("Notepad.exe", "", @SW_MAXIMIZE)
        Case $Button2
            Run($var)
        Case $Button3
            #Region --- CodeWizard generated code Start ---
            ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
            MsgBox(64, "About DJ5's Soldat and Notepad Opener", "DJ5's Soldat and Notepad Opener" & @CRLF & @CRLF & "Author: DJ5 " & @CRLF & "Email: PM me at:" & @CRLF & "Website: http://www.anarchynetwork.com/")
        Case $Button4
            openfile()
    EndSwitch
WEnd

Func openfile()
    $var = FileOpenDialog("Please select your main soldat file. (should be Soldat.exe)", "", "Executable Files(*.exe)", 1, "Soldat.exe")

    If @error Then
        MsgBox(0, "Error", "No File(s) chosen")
    Else
        $var_1 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_1 = 2 Then
        openfile()
    EndIf
EndFunc   ;==>openfile

Is everything ok? It runs fine :(

1 last request for this project!

Is there a ReadIn and WriteIn function like in pascal?

What I need is for the program to save the user's soldat filepath. (the filepath you choose when you hit "Browse...")

I was thinking write to a sfp.txt(sfp standing for "soldat file path") or sfp.ini file the filepath after the user selects it (WriteIn) and then when the program starts it will check if there is a sfp.txt or sfp.ini and if there is it will read the file and take the file path from it and load it. (ReadIn)

Link to comment
Share on other sites

This should be what you want.

Global $var


While 1
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        If MsgBox(4, "Error", "No File(s) chosen" & @CRLF & "Are you sure you want to cancel") = 6 Then Exit
    Else
        If MsgBox(4, "Success!", "You chose " & $var & @CRLF & "Did you select this file") = 6 Then Exit
    EndIf
WEnd
Link to comment
Share on other sites

YAY! My first ALMOST made from scratch script is done >_<

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\rce_aw_wierd\hacks\soldat.kxf
Global $Form1_1 = GUICreate("DJ5's Soldat and Notepad Opener", 637, 445, 206, 152)
GUISetIcon("C:\Documents and Settings\Mike\My Documents\Icons\Icons\Devices\84.ico")
GUISetBkColor(0x800000)
Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Mike\My Documents\My Pictures\soldat DS.jpg", 0, 0, 636, 444, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Button1 = GUICtrlCreateButton("Open Notepad", 272, 376, 83, 25, $WS_GROUP, $WS_EX_CLIENTEDGE)
GUICtrlSetCursor(-1, 3)
Global $Button2 = GUICtrlCreateButton("Open Soldat", 279, 178, 75, 25, $WS_GROUP, $WS_EX_CLIENTEDGE)
GUICtrlSetCursor(-1, 3)
Global $Button3 = GUICtrlCreateButton("About", 416, 304, 83, 25, $WS_GROUP)
GUICtrlSetCursor(-1, 3)
Global $Label1 = GUICtrlCreateLabel("Not working? Browse for Soldat.", 239, 205, 156, 17)
GUICtrlSetBkColor(-1, 0xC0C0C0)
Global $Button4 = GUICtrlCreateButton("Browse...", 280, 224, 75, 17, $WS_GROUP)
GUICtrlSetCursor(-1, 3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $var, $var_1

$var = "C:\Soldat\Soldat.exe"


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Run("Notepad.exe", "", @SW_MAXIMIZE)
        Case $Button2
            Run($var)
        Case $Button3
            #Region --- CodeWizard generated code Start ---
            ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
            MsgBox(64, "About DJ5's Soldat and Notepad Opener", "DJ5's Soldat and Notepad Opener" & @CRLF & @CRLF & "Author: DJ5 " & @CRLF & "Email: PM me at:" & @CRLF & "Website: http://www.anarchynetwork.com/")
        Case $Button4
            openfile()
    EndSwitch
WEnd

Func openfile()
    $var = FileOpenDialog("Please select your main soldat file. (should be Soldat.exe)", "", "Executable Files(*.exe)", 1, "Soldat.exe")

    If @error Then
        MsgBox(0, "Error", "No File(s) chosen")
    Else
        $var_1 = MsgBox(1, "Success!", "You chose " & $var)
    EndIf

    If $var_1 = 2 Then
        openfile()
    EndIf
EndFunc   ;==>openfile

Is everything ok? It runs fine :(

1 last request for this project!

Is there a ReadIn and WriteIn function like in pascal?

What I need is for the program to save the user's soldat filepath. (the filepath you choose when you hit "Browse...")

I was thinking write to a sfp.txt(sfp standing for "soldat file path") or sfp.ini file the filepath after the user selects it (WriteIn) and then when the program starts it will check if there is a sfp.txt or sfp.ini and if there is it will read the file and take the file path from it and load it. (ReadIn)

See For files

FileReadLine()
FileWriteLine()

For console use

ConsoleRead and ConsoleWrite
Edited by athiwatc
Link to comment
Share on other sites

try this

While 1
    $file = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(5, "Error", "No File(s) chosen")
        If $var_1 = 2 Then Exit
        If $var_1 = 4 Then ContinueLoop
    EndIf

    MsgBox(0, "Success!", "You chose " & $file)
    ExitLoop
WEnd

thats basicly a more complicated version of:

Global $var, $var_1


While 1
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(5, "Error", "No File(s) chosen")
    Else
        MsgBox(0, "Success!", "You chose " & $var)
    EndIf

    If $var_1 <> 4 Then
        Exit
    EndIf

WEnd

I wanted to know how to have $var_1 = 1 and $var_2 = 2, but thanks for showing me the loop.

Ok, with your code I made this, which works!

Global $var, $var_1, $var_2

While 1
    $file = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)
    If @error Then
        $var_1 = MsgBox(5, "Error", "No File(s) chosen")
        If $var_1 = 2 Then Exit
        If $var_1 = 4 Then ContinueLoop
    EndIf
    $var_2 = MsgBox(4, "Success!", "You chose & $file Is this OK?")
    If $var_2 = 6 Then Exit
    If $var_2 = 7 Then ContinueLoop
    ExitLoop
WEnd

The thing I need help on with this is this part, which doesn't work (which I thought it wouldn't):

$var_2 = MsgBox(4, "Success!", "You chose & $file Is this OK?")

If I do:

$var_2 = MsgBox(4, "Success!", "You chose" & $file "Is this OK?")

It would return an error...

EDIT: Oops, didn't see the post above me. Disregard this.

Also, last question. What is console use?

ConsoleRead and ConsoleWrite

Edited by miketh2005
Link to comment
Share on other sites

thats basicly a more complicated version of:

Global $var, $var_1


While 1
    $var = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)

    If @error Then
        $var_1 = MsgBox(5, "Error", "No File(s) chosen")
    Else
        MsgBox(0, "Success!", "You chose " & $var)
    EndIf

    If $var_1 <> 4 Then
        Exit
    EndIf

WEnd

I wanted to know how to have $var_1 = 1 and $var_2 = 2, but thanks for showing me the loop.

Ok, with your code I made this, which works!

Global $var, $var_1, $var_2

While 1
    $file = FileOpenDialog("Hi", @WindowsDir & "\", "Images (*.jpg;*.bmp)", 1 + 4)
    If @error Then
        $var_1 = MsgBox(5, "Error", "No File(s) chosen")
        If $var_1 = 2 Then Exit
        If $var_1 = 4 Then ContinueLoop
    EndIf
    $var_2 = MsgBox(4, "Success!", "You chose & $file Is this OK?")
    If $var_2 = 6 Then Exit
    If $var_2 = 7 Then ContinueLoop
    ExitLoop
WEnd

The thing I need help on with this is this part, which doesn't work (which I thought it wouldn't):

$var_2 = MsgBox(4, "Success!", "You chose & $file Is this OK?")

If I do:

$var_2 = MsgBox(4, "Success!", "You chose" & $file "Is this OK?")

It would return an error...

From

$var_2 = MsgBox(4, "Success!", "You chose" & $file "Is this OK?")

To

$var_2 = MsgBox(4, "Success!", "You chose" & $file & "Is this OK?")
Link to comment
Share on other sites

Thanks alot. I found that out when I saw your script >_<. What is a console?

Console is part of CUI and not GUI

I think in pascal Readln is use for Files right?(I didn't program in pascal a long.....time)

Console is the "black" screen like when you use cmd. it's something like that.

But in your case I think you want files so use FileReadLine and FileWriteLine

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