Page 1 of 1 1
Topic Options
#188729 - 2008-07-14 02:18 PM Logical OR and "1" vs "-1"
lho Offline
Fresh Scripter

Registered: 2008-07-14
Posts: 5
Hi.

The following makes me mad:
Using OR to check for "0" or "-1" does not work, if the result is "-1".

So, if the file "%appdata%\PATH\file1.rtf" is newer than file @LDrive +"\resources\file1.rtf", the Result is "-1" but for KIX it does not matter and it goes into the THEN tree. But if the result was "1", it works as it should.

 Code:
$RESULT = COMPAREFILETIMES (@LDrive +"\resources\file1.rtf","%appdata%\PATH\file1.rtf")
MESSAGEBOX ("Result=: $RESULT", "Box", 4160)
	IF $RESULT = "0" OR $RESULT = "-1"
		MESSAGEBOX ("Now we are at THEN", "Box", 4160)
	ELSE GOTO SKIP	 
	ENDIF
goto END

:SKIP
MESSAGEBOX ("Now we are at ELSE", "Box", 4160)

:END
exit


Edited by lho (2008-07-15 11:17 AM)

Top
#188730 - 2008-07-14 02:32 PM Re: Logical OR and "1" vs "-1" [Re: lho]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It works fine, try this:
 Code:
For Each $RESULT in Split("-1 0 1")
	$RESULT=CInt($RESULT)
	If $RESULT=0 OR $RESULT=(-1)
		$=MessageBox("In THEN when RESULT="+$RESULT,"Box",4160)
	Else
		$=MessageBox("In ELSE when RESULT="+$RESULT,"Box",4160)
	EndIf
Next

Top
#188732 - 2008-07-14 03:02 PM Re: Logical OR and "1" vs "-1" [Re: Richard H.]
lho Offline
Fresh Scripter

Registered: 2008-07-14
Posts: 5
Hi.
Thanks for the quick reply!
But this example does not work. Here it goes into THEN twice and also runs ELSE once.

I wonder, why the original KIX example for Comparefiletimes
uses almost the same code than I did.

 Code:
$Result = CompareFileTimes(@LDRIVE + "\USER.INI", "C:\WINDOWS\USER.INI")
IF $Result = 1 OR $Result = -3
  COPY @LDRIVE + "\USER.INI" "C:\WINDOWS\USER.INI"
ENDIF 



Edited by lho (2008-07-14 03:04 PM)

Top
#188733 - 2008-07-14 03:21 PM Re: Logical OR and "1" vs "-1" [Re: lho]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
 Quote:
But this example does not work. Here it goes into THEN twice and also runs ELSE once.


It's running a loop with each of the possible values. Look closely at the results... it is working.

Curious. What version of kix are you running.
_________________________
(... better days ahead)

Top
#188755 - 2008-07-15 10:28 AM Re: Logical OR and "1" vs "-1" [Re: Allen]
lho Offline
Fresh Scripter

Registered: 2008-07-14
Posts: 5
I use 4.6.

If i use this example, it acts like described above. No matter what value the variable $RESULT has.
e.g. if I set it to "sdgsgrysdgd": 2* THEN, 1*ELSE

This is, what I'm exactly using:
 Code:
$RESULT = sdgsgrysdgd
MESSAGEBOX ("Result=: $RESULT", "Box", 4160)

For Each $RESULT in Split("-1 0 1")
	$RESULT=CInt($RESULT)
	If $RESULT=0 OR $RESULT=(-1)
		MessageBox("In THEN when RESULT="+$RESULT,"Box",4160)
	Else
		MessageBox("In ELSE when RESULT="+$RESULT,"Box",4160)
	EndIf
Next

Top
#188756 - 2008-07-15 11:16 AM Re: Logical OR and "1" vs "-1" [Re: lho]
lho Offline
Fresh Scripter

Registered: 2008-07-14
Posts: 5
 Originally Posted By: lho

The following makes me mad:
Using OR to check for "0" or "-1" does not work, if the result is "-1".


Well... This one works.

 Code:
$RESULT = COMPAREFILETIMES (@LDrive +"\resources\file1.rtf","%appdata%\PATH\file1.rtf")

IF $RESULT = 0 OR $RESULT = 1
		MessageBox ("Now we are at THEN", "Box", 4160)
               	GOTO END
ELSE
        GOTO SKIP
	GOTO END	
ENDIF

:SKIP
MESSAGEBOX ("Now we are at ELSE", "Box", 4160)

:END
exit

Top
#188757 - 2008-07-15 01:48 PM Re: Logical OR and "1" vs "-1" [Re: lho]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Since it's a VALUE, not a STRING, and you want to check for 0 OR -1, why not simply test for a value less than 1, which would include 0 and -1?

What's with the Gotos, especially the Goto Skip that's immediately followed by Goto End? That will never run the Goto End! Sloppy! "C-" (see! You're bringing out my instructor side...)

In your last test, you're comparing apples and elephants. You manually set $Result to a string, yet are trying to test for a numeric value? If you want to test the logic, try this:
 Code:
$Result = -1 ; alternately set this value to -1, 0, and then 1

If $Result < 1
  $ = MessageBox('Result is -1 or 0', 'Result Status', 4160)
Else
  $ = MessageBox('Result is 1', 'Result Status', 4160)
EndIf

This function really begs for a case statement, though..

 Code:
$File1 = 'this file'    ; change these as appropriate - use full paths
$File2 = 'that file'

; set the Result value based on file time comparison
$Result = CompareFileTimes($File1, $File2)

; Use Select to decide what to do
Select
 Case $Result = -2  ; no source
  'The source file was not found - cannot continue!' ?
  Quit 2
 Case $Result < 0   ; target older or missing - update
  'Updating the target file!' ?
  Copy $File1 $File2
 Case 0             ; files are identical - do nothing
  'Files are identical!' ?
 Case 1             ; target is newer? Is this OK? 
  'Target is newer!' ?
EndSelect

Finally - why messageboxes for all your output? Script development and testing should be done from a command prompt so you can see the errors that are generated - running from explorer will mask many important bits of information.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#188780 - 2008-07-16 10:35 AM Re: Logical OR and "1" vs "-1" [Re: Glenn Barnas]
lho Offline
Fresh Scripter

Registered: 2008-07-14
Posts: 5
Grade accepted and improvement promised...
Good idea, to check for less than "1". But I think, I found what I was looking for. What about you? Still waiting for the impact? ;-)

Top
#188788 - 2008-07-16 12:01 PM Re: Logical OR and "1" vs "-1" [Re: lho]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
No - I've convinced myself that it's on it's 482,932nd orbit by now... ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (StuTheCoder) and 798 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org