Sign in to follow this  
Followers 0
Reeling

If and While won't work!

7 posts in this topic

#1 ·  Posted (edited)

Solved

I have a script i'm trying to make. Problem is this one If and While statement won't work and for the life of me I can't figure out why. Maybe you guys can see something I'm not.

Here it is:

#include <Date.au3>
$test1 = "10"
$test2 = "6"
$diff = "10"
Global $seconds = @SEC
Global $minutes = @MIN
Global $hours = @HOUR
Global $day = @MDAY
Global $month = @MON
Global $year = @YEAR
Assign( "start", $year&"/"&$month&"/"&$day&" "&$hours&":"&$minutes&":"&$seconds&"")
Assign( "end", $year&"/"&$month&"/"&$day&" "&$hours + 3&":"&$minutes&":"&$seconds&"")
Global $diff = _DateDiff('n', $start, $end)
If $test1 > $test2 Then
   While $diff > "0"
  
        
   Tooltip($diff & ":" & $seconds, 1400, 500)
   sleep(1000)
  
   MsgBox(0, "t", $diff)
  
  
   WEnd
   EndIF

When I run this nothing pops up, no msg box no nothing. I tried putting a msg box before the "if" statement to make sure the $diff variable was working, and it is.

Edited by Reeling

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <Date.au3>
$test1 = 10
$test2 = 6
$diff = 10
Global $seconds = @SEC
Global $minutes = @MIN
Global $hours = @HOUR
Global $day = @MDAY
Global $month = @MON
Global $year = @YEAR
Global $start =  $year&"/"&$month&"/"&$day&" "&$hours&":"&$minutes&":"&$seconds
Global $end = $year&"/"&$month&"/"&$day&" "&$hours + 3&":"&$minutes&":"&$seconds
Global $diff = _DateDiff('n', $start, $end)
If $test1 > $test2 Then
   While $diff > 0


   Tooltip($diff & ":" & $seconds, 1400, 500)
   sleep(1000)

   MsgBox(0, "t", $diff)


   WEnd
EndIF

Try to avoid making comparisons of numbers in string format for one.

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

While $diff > "0"

You are comparing a number and a string.

Edited by tsolrm

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

While $diff > "0"

You are comparing a number and a string.

how can i fix it? im pretty new.

@ApudAngelorum

The $test1 and $test2 variables aren't always going to be static, they will be variables that are changing so is there a different way I can compare them, considering that fact?

Edited by Reeling

Share this post


Link to post
Share on other sites

"0" is a string, 0 is a number. There's a pretty strong difference.

Being new means you should spend reasonable time reading the help file. Datatypes, Variables, and such are fundamental basics.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

"0" is a string, 0 is a number. There's a pretty strong difference.

Being new means you should spend reasonable time reading the help file. Datatypes, Variables, and such are fundamental basics.

That's what I thought but low and behold, this still doesn't work.

#include <Date.au3>
$test1 = "10"
$test2 = "6"
$diff = "10"
$var0 = 0
Global $seconds = @SEC
Global $minutes = @MIN
Global $hours = @HOUR
Global $day = @MDAY
Global $month = @MON
Global $year = @YEAR
Assign( "start", $year&"/"&$month&"/"&$day&" "&$hours&":"&$minutes&":"&$seconds&"")
Assign( "end", $year&"/"&$month&"/"&$day&" "&$hours + 3&":"&$minutes&":"&$seconds&"")
Global $diff = _DateDiff('n', $start, $end)
If 10 > 6 Then
   While $diff > 0
  
        
   Tooltip($diff & ":" & $seconds, 1400, 500)
   sleep(1000)
  
   MsgBox(0, "t", $diff)
  
  
   WEnd
   EndIF

Ideas?

Edit: +3 hours takes me in to the next day so it bugs out and sets $diff to 0, anyway to fix this?

Edit 2: solved, thanks for help

Edited by Reeling

Share this post


Link to post
Share on other sites

Pff, Ignore my previous stupidity, what's wrong is that you're doing the date diff function wrong, also we just told you not to make comparisons with strings and numbers!


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

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