Sign in to follow this  
Followers 0
Remo1075

If only running once

7 posts in this topic

Hello all,

I'm sure this is a very simple fix but I just can't see it. After the gui/_func() closes it runs the next bit of code below which runs fine but only once. If I hit "No" answer 7 it should run the func() again then run in to the below code yet again. But the 2nd time around it seems to skip the if $answer = 7 bit and go to the setup.exe. It should continue to run through the If statement and call the Func() again as long as I keep selecting NO.

;If CRC32 = 695689BD then pop up a box to ask if you are sure, if yes then continue on, if no then call _func()
Global $sFile = @WindowsDir & "\Config.xml"
Global $sData
Global $answer
$sData = _CRC32ForFile($sFile)
If $sData = "695689BD" Then
$answer = MsgBox(68, "File hash check is " & $sData , "Only English will be installed, are you sure?" & @CRLF & _
                                                      "Nur Englisch wird installiert, sind Sie sicher?")
EndIf


If $answer = 7 Then ;No
_Func()
EndIf
If $answer = 2 Then ;Cancel
Exit
EndIf

;Execute the script with all param
;run some setup.exe

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you want it to keep calling _Func() until $answer = 2 use this:

;If CRC32 = 695689BD then pop up a box to ask if you are sure, if yes then continue on, if no then call _func()
Global $sFile = @WindowsDir & "\Config.xml"
Global $sData
Global $answer
$sData = _CRC32ForFile($sFile)

If $sData = "695689BD" Then
    Do
        _Func()
    Until $answer = 2
EndIf

Func _Func() ; I didn't see a _Func in your code so just added this.
    $answer = MsgBox(68, "File hash check is " & $sData , "Only English will be installed, are you sure?" & @CRLF & _
                                                          "Nur Englisch wird installiert, sind Sie sicher?")
EndFunc

; Run some setup.exe

Clearly, in this case the _Func isn't very useful as it's only one command, so you could just put the content directly in the Do ... Until loop.

Edited by d4ni

Share this post


Link to post
Share on other sites

The function is a GUI that is about 130 lines of code. I don't want to call the msgbox untill $answer = 2 but have it go around again if the user hit's NO again. It seems to do it once then never shows the msgbox the next time around. Calling the main gui func again would always make the value If $sData = "695689BD" as it starts again with a new file. Basicly the code works below that I have, but only once.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

maybe you can link your $answer variable to a gui button? if so use a

while 1

loop to call guigetmsg

it will then wait for an answer

if yes or 1 call this function

if no or 2 call another function

when the function is finished it will return to the while 1 loop unless it hits an exit command.

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!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I will try it with guigetmsg quickly.

$answer variable is the variable for the msgbox()

On a msgbox(68, "","") ( shows info icon and YES and NO Button )

Button Pressed Return Value

OK 1

CANCEL 2

ABORT 3

RETRY 4

IGNORE 5

YES 6

NO 7

TRY AGAIN ** 10

CONTINUE ** 11

Because 7 = NO it calls the gui/func again then runs through ALL of the original 1st post code again. But the 2nd time it does not run the If $answer = 7 statement for whatever reason. it just jumps to the end and runs the setup.exe.

$answer = MsgBox(68, "File hash check is " & $sData , "Only English will be installed, are you sure?" & @CRLF & _
                                                      "Nur Englisch wird installiert, sind Sie sicher?")
Edited by Remo10

Share this post


Link to post
Share on other sites

I don't know if this is correct, but I tend to think of code working like this:

line in script 1

line in script 2

line in script 3

line in script 4

function

Now say at some point (maybe line 2) it calls the function. When the function completes it returns to where it left off and starts running from the next line (line 3)


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!

Share this post


Link to post
Share on other sites

Yes, yes I'm sure you have hit the nail on the head. It's not a problem with the code, but it's like it's run once and now it's moving on to the next line.

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