Jump to content

[SOLVED] Two equal functions, but different result...


Recommended Posts

I don't have idea, but i have two equal code, but give me two different result

This script work, and i have at finish the MsgBox

Func A()
$Path = GUICtrlRead($FolderInput_LvA)
$Pre = "Test.exe"
$Command = "-e -p"
$Folders= _FileListToArray($Path, '*', 1)
$Folders[0] = "@echo off" & @CRLF
  
For $i = 1 to UBound($Folders) -1
    $Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & " " & '"' & $Path & "\" & $Folders[$i] & '"', @TempDir, @SW_HIDE)
Next
If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then
Test()
EndIf
If $Success Then
MsgBox(0,"Information","Success")
FileDelete(@TempDir & "\Test.txt")
EndIf
Return 1
EndFunc

This do the @ComSpec command but i don't have the MsgBox, because the result is different ( i have try to make "If Not $Success Then" and i have the MsgBox)

I have only change the $FolderInput_LvB and the command, i have both code in the same script, but two different Func()

Func B()
$Path = GUICtrlRead($FolderInput_LvB)
$Pre = "Test.exe"
$Command = "-f -p"
$Folders= _FileListToArray($Path, '*', 1)
$Folders[0] = "@echo off" & @CRLF
  
For $i = 1 to UBound($Folders) -1
    $Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & " " & '"' & $Path & "\" & $Folders[$i] & '"', @TempDir, @SW_HIDE)
Next
If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then
Test()
EndIf
If $Success Then
MsgBox(0,"Information","Success")
FileDelete(@TempDir & "\Test.txt")
EndIf
Return 1
EndFunc

What is the problem?

Thanks

Edited by johnmcloud
Link to comment
Share on other sites

upon examination it looks to me (without testing) that perhaps the -f flag is the culprit.

If you run the command in a cmd prompt do you get the results you'd expect?

Also, not too sure about the following statement

$Success = $Folders[$i] = RunWait(.....)

I've never seen a statement with an $var1 = $var2 = Func

Edited by spudw2k
Link to comment
Share on other sites

upon examination it looks to me (without testing) that perhaps the -f flag is the culprit.

If you run the command in a cmd prompt do you get the results you'd expect?

Also, not too sure about the following statement

$Success = $Folders[$i] = RunWait(.....)

I've never seen a statement with an $var1 = $var2 = Func

Mmm how strange...

I have changed to this for second script:

$Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " &  " " & '"' & $Path & "" & $Folders[$i] & '"', @TempDir, @SW_HIDE)
$Success = $Folders[$i]

i have the MsgBox for FuncB(), but if i try to apply THE SAME THING to FuncA() don't work, i have message for B and not for A, before i have MsgBox for A and not for B... :)

Edited by johnmcloud
Link to comment
Share on other sites

Check that these values are correct:

$Path  = GUICtrlRead($FolderInput_LvA)
$Path  = GUICtrlRead($FolderInput_LvB)

Is variable $Success a global? If so, do you assign any values to variable $Success within function Test()?

Edited by LaCastiglione
Link to comment
Share on other sites

I have resolved, this time without your hand guys :)

I have changed this part like this and work for both code:

$Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & " " & '"' & $Path & "" & $Folders[$i] & '"', @TempDir, @SW_HIDE)
Next
If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then
Test()
EndIf
If $Success = 1 Then
MsgBox(0,"Information","Success")
FileDelete(@TempDir & "Test.txt")
Else
MsgBox(16,"Error","Error")
FileDelete(@TempDir & "Test.txt")
EndIf
Return 1

Thanks anyway for support

Edited by johnmcloud
Link to comment
Share on other sites

johnmlcoud,

Congrats!

$Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & " " & '"'...

This is kind of an unusual construct. $success seems to evaluate to true or false depending on the results of the 2nd and third parts of this construct. Is this your intent? How did you arrive at this?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

johnmlcoud,

Congrats!

$Success = $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & " " & '"'...

This is kind of an unusual construct. $success seems to evaluate to true or false depending on the results of the 2nd and third parts of this construct. Is this your intent? How did you arrive at this?

kylomas

Thanks for congrats, but i'm only a noob respect of all guru of this forum.

Yes, was my intent, I got there at random attempts and seem work fine for my script

Work like $success is 1 if $Folders[$i]=1 if RunWait=1

If one of there is 0 the result is 0, i think :)

Edited by johnmcloud
Link to comment
Share on other sites

Here's what I get:

Global $Success = ''
Global $Test = ''

$Success = $Test = 123

ConsoleWrite("$Success: " & $Success & @CRLF & "$Test: " & $Test & @CRLF)

$Success: False
$Test:

My guess is that $Test is not being assigned to and so it returns false which gets assigned to $Success.

Edited by LaCastiglione
Link to comment
Share on other sites

  • Moderators

Kylomas,

I wonder what a dev thinks of that construct????

This Mod thinks it is an abomination and it only works by pure luck. ;)

johnmcloud,

I would strongly advise against using non-standard contructs of that sort - you will only get bitten by one not working as you expect one day. And will you be able to remember how it is supposed to work when you look again at the script in several months time? :)

Go for simplicity - AutoIt is slow enough that any time you save will be minimal, and large enough when compiled that you do not save much in size terms by condensing assign statements like that. Finally anything involving Booleans should be simple as possible as getting their logic right is difficult enough as it is :D

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

@m23,

Interesting though that this resolves to True

Local $a = 5, $b = 6, $c = 6
$a = $b = $c
ConsoleWrite($a & @LF & $b & @LF & $c & @lf)

kylomas

edit: conjecture...ternary ops come to mind!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

It evaluates as true because $b equals $c, they're both 6.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

kylomas,

Ternary ops have been brought up several times in other closed parts of the forum - the last time it was sort of agreed that in a language that strives for ease of use they were an unneccesary complication. Although I did like one pro-ternary comment in particular (and it did not come from the person you might think!): :)

I still don't find that just because it's easier to cut your head off with a chainsaw than an axe that a chainsaw isn't a viable tool. Yes it can turn the situation ugly much faster than an axe, but that's all up to the user. You can't save people from stupid.

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

$a = $b = $C isn't any different than doing something like If $B = $C Then <do something>. It's evaluating whether or not $B equals $C and if it does (True), do something. The initial value of $a is overwritten by the boolean comparison result.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

brewmanNH,

OF course, my conjecture was only that the form was vaguely reminiscent of ternary ops..

@m23,

I still don't find that just because it's easier to cut your head off with a chainsaw than an axe that a chainsaw isn't a viable tool. Yes it can turn the situation ugly much faster than an axe, but that's all up to the user. You can't save people from stupid.

my new mantra

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

$a = $b = $C isn't any different than doing something like If $B = $C Then <do something>. It's evaluating whether or not $B equals $C and if it does (True), do something. The initial value of $a is overwritten by the boolean comparison result.

I think BrewManNH is right because:
Global $Success = ''
Global $Test = 123

$Success = $Test = 123

ConsoleWrite("$Success: " & $Success & @CRLF & "$Test: " & $Test & @CRLF)

I still think of AutoIt in terms of a low-level language.

Edited by LaCastiglione
Link to comment
Share on other sites

Of course if you really want one line you could make it less ambiguous by using $a = ($b = $c), no?

I sometimes use redundant parentheses to make things more clear (or more ovbious).

Now this may be a stupid question, but how does AutoIt know that $a = $b = $c means "assign to $a the result of the comparision $b=$c", rather than "set $a equal to $b, and then compare to $c (since per the helpfile when two operators have the same precedence the expression is evaluated left to right.)? It looks like an equal sign that's the first operator on any line is assumed to be assignment, whereas any other use of equal is assumed to be comparison?

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