Jump to content

What's the wrong in this script?


Recommended Posts

$answer = MsgBox(4, "!!!!!", "Running a lot applications together you task manager has corrupted, Would you like to restart now?")

If $answer = 7 Then
    MsgBox(0, "!!!!!", "Restart soon or your computer will corrupt")
EndIf
Exit
If $answer - 6 Then
    Shutdown(2)
Exit
EndIf

When I pressed "No" My computer rebooted!

Did I type anything wrong in this script?

Visit HugeSoft(TM) To Get Any Coding Help or Anything

Link to comment
Share on other sites

Eh, I'm lazy. So I'll let my code do the talking.

:x

$answer = MsgBox(4, "!!!!!", "Running a lot applications together you task manager has corrupted, Would you like to restart now?")

If $answer = 7 Then MsgBox(0, "!!!!!", "Restart soon or your computer will corrupt")

If $answer = 6 Then MsgBox(0, "", "Computer shut down") ; ShutDown(2)
Edited by Kalin
Link to comment
Share on other sites

I think there are a couple things wrong with your script.

Did you mean to put Exit before the first EndIf Statement? The rest of your script will be unreachable.

You could also use the Else statement instead of another if statement. It isn't necessary when there are only two buttons.

Here are my adjustments:

$answer = MsgBox(4, "!!!!!", "Running a lot applications together you task manager has corrupted, Would you like to restart now?") 
If $answer == 7 Then
     MsgBox(0, "!!!!!", "Restart soon or your computer will corrupt")
Else
     Shutdown(2)
EndIf

Also, the Exit command is not required.

Edited by timsta97
Link to comment
Share on other sites

@ Kalin Where's Exit or EndIf??

With single line if statements, they are not required. Have a look:

If 1 Then MsgBox(0, "Single Line Statement", "This is a single line statement")

If 0 Then
    MsgBox(0, "Multi Line Statement", "This if statement will do more than one thing," & @CRLF & "therefore more than one
    line" & @CRLF $ "will be used."
    ;This is 'another function'
EndIf

I hope this makes it clearer?

shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

You could also use the Else statement instead of another if statement. It isn't necessary when there are only two buttons.

Here are my adjustments:

$answer = MsgBox(4, "!!!!!", "Running a lot applications together you task manager has corrupted, Would you like to restart now?") 
If $answer == 7 Then
     MsgBox(0, "!!!!!", "Restart soon or your computer will corrupt")
Else
     Shutdown(2)
EndIf

Also, the Exit command is not required.

This is a good solution to the one above :x

However I would personally do it another way in case it doesnt end with a value of -6

Here is how I would do it:

$answer = MsgBox(4, "!!!!!", "Running a lot applications together you task manager has corrupted, Would you like to restart now?") 
If $answer = 7 Then
     MsgBox(0, "!!!!!", "Restart soon or your computer will corrupt")
Elseif $answer = 6 Then
     Shutdown(2)
EndIf
Exit

You may notice that in timsta97's version, the if statement condition was:

$answer == 7

However mine is

$answer = 7

Unlike programming languages such as C++, you do not need to check the value of the variable with ==.

Its like magic :P You can set the variable value with its own line.

$var1 = 10

;lines of code

$var1 = 9

There you go :shifty:

if $var1 = 10 Then MsgBox(0, "Hello", "Hello!")

Hope this helps a bit more?

shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

With single line if statements, they are not required. Have a look:

If 1 Then MsgBox(0, "Single Line Statement", "This is a single line statement")

If 0 Then
    MsgBox(0, "Multi Line Statement", "This if statement will do more than one thing," & @CRLF & "therefore more than one
    line" & @CRLF $ "will be used."
    ;This is 'another function'
EndIf

I hope this makes it clearer?

shanet

Uh, are you implying I already didn't know that?

You wouldn't need to use more than one line in the code snippet I gave.

Exit is useless in this script. A good replacement of Exit would of just been to set a timeout for the MsgBox.

Link to comment
Share on other sites

$answer = MsgBox(4, "!!!!!", "Running a lot applications together you task manager has corrupted, Would you like to restart now?")

I don't think I've ever seen Task Manager corrupted. How is that done? <grin>

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Uh, are you implying I already didn't know that?

No I am not. I did it to try and explain to DarkNight1366 how it works. I was not inferring that you dont already know that, especially considering that is in your code already.

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

I don't think I've ever seen Task Manager corrupted. How is that done? <grin>

I think its meant to be a bit of a joke script?

As long as its not dangerous, its not a problem agreed?

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

I don't think I've ever seen Task Manager corrupted. How is that done? <grin>

I think its meant to be a bit of a joke script?

As long as its not dangerous (keylogger, virii) or bots and stuff, its not a problem agreed?

We all love playing jokes on people :x

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

The Data Protection virus likes to play jokes too - it's hard to know the difference ..

post-55206-0-16125200-1294587829_thumb.p

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

ripdad,

Hey did you use ToolTip or something??? Would you please tell me??

lul...

$timeout = 40 ; 40 seconds
$iconID = 2 ; warning icon

TrayTip("WARNING!!!!!!!!!", "OMG U R GETTING HAXED", $timeout, $iconID)

Oh, forgot to add. When using TrayTips you should control the delay with the Sleep() command instead of relying on the timeout alone. It'll still close too fast. So use sleep to add additional time.

Edited by Kalin
Link to comment
Share on other sites

Unlike programming languages such as C++, you do not need to check the value of the variable with ==.

Its like magic :x You can set the variable value with its own line.

$var1 = 10

;lines of code

$var1 = 9

You're right; it isn't necessary, before I learned C++ and C# I never used the double equals, but I always put it in because I now use C# mostly. It doesn't hurt to put it in; it affects the code in no way whatsoever.

Link to comment
Share on other sites

  • Moderators

timsta97,

It doesn't hurt to put it in; it affects the code in no way whatsoever.

Actually it does. :P

Using the == operator forces a case-sensitive comparison between the 2 operands converted to strings, which takes considerable more processing than the = operator.

So the recommendation is to use the == operator only when you need the case sensitive comparison. In all other cases you should use the = operator.

I hope that clears up any misconceptions. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

timsta97,

Actually it does. :P

Using the == operator forces a case-sensitive comparison between the 2 operands converted to strings, which takes considerable more processing than the = operator.

So the recommendation is to use the == operator only when you need the case sensitive comparison. In all other cases you should use the = operator.

I hope that clears up any misconceptions. :x

M23

I remember reading the thread on the usage of the two. It was related to bug or enhancement, too hard to find.

By convention I use == for strings and = for numbers. I thought it forced the conversion to string, wasn't sure it was case sensitivity. Thanks

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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