Sign in to follow this  
Followers 0
jurco

Input dates

7 posts in this topic

I am trying to input two dates to the script, to delimitate a search.

Is there a way to use a pre-made Input box?

I am trying by using an input box, and manipulating the string into the script, but iyou can easly make a mistake if you try to type a date, because of so many factors, as the format you have to use.

Thanks.

Share this post


Link to post
Share on other sites



The standard input statement allows a default value to be specified. If you're wanting to have a custom input box with a different look, then you'd need to create your own with AutoIt GUI.

I made an example script for another user a few weeks back that may prove helpful. I didn't really worry about error-checking the date format, so there's some bugs around the logic - however feel free to take a look at the post.

Hope this helps!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

No automatic system.

But it not so hard.

Ask your user to delimitate the 3 fields with a character. And put an example for being sure about the moth-day-year position.

E.g.

;2004-12-31
Dim $check = 0, $date, $year, $month, $day
While $check <> 3
   $check = 0
   $date = InputBox ( "Input date",'Input the date' & @lf & 'Please use ISO format: yyyy-mm-dd' & @lf & 'Separe the three field with a slash.')
   If @error Then Exit 
   $Year = StringLeft($date,4)
   $Month = StringMid($date,6,2)
   $Day = StringRight($date,2)

   If $year >= 1925 Then
      $Check = $Check + 1;Year check
   Else
      ContinueLoop
   EndIf
   If $month <=12 AND $month>=1 Then
       $check = $check + 1;Month check
   Else
       ContinueLoop
   EndIf
   
   If $day < 1 Then ContinueLoop
   Select;Day check
   Case _Any($month,'01|03|05|07|08|10|12') AND $day<=31
      $check=$check + 1
   Case _Any($month,'04|06|09|11') AND $day<=30
     $check=$check + 1
   Case $month=2 AND Mod(($year-2000),4)=0 AND Not Mod(($year),100)=0 AND $day<=29
      $check=$check + 1
   Case $month=2 AND $day <=28
      $check=$check + 1
   EndSelect
Wend

Msgbox(0,'',$day & '   ' & $month & '   ' & $year)
Exit
Func _Any($ITEM, $LIST)
   Local $LIST, $item, $c
   $LIST = StringSplit($LIST, '|')
   For $C = 1 To $LIST[0]
      If $LIST[$C] = $ITEM Then
         Return 1
      EndIf
   Next
   Return 0
EndFunc;==>_Any

The message says that you should separe the three values with a slash, it sis not true. As you can see any char actually divide. But clear messages are better for BFU, also some guys prefere using dots (2004.06.02) or just spaces (2004 04 03) so this it is quite foolproof. The main problem is about the management of some leap yeas that do not follow the standard 'every four' rule.

If you need more precision you may improve this udf quickly anyway.

Edit: Ok, Bartokv answered while I was writing this code. His answer is probably better, but I'll not delete this for history.

Edit2: An -9 <= month <= 0 were valid. (It would fail the day check anyway... but it is more correct now.)

Edit3: Suddently I saw I wrote StringMid() from 5 for 2 chars... OPS.. I corrected with 6 as it should. Added a line in the case the user press 'Cancel'

Edited by ezzetabi

Share this post


Link to post
Share on other sites

Thanks for your scripts.

I will study them, try to apply them, and I will get in touch.

Share this post


Link to post
Share on other sites

@ezzetabi

I like that _Any function.. have never seen it done like that before. Very simple yet it gets the job done... I'll add it to my library. :ph34r: Thanks alot!

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

I like it also...

I know that it may be changed be a sequence of ORs but I think that code is much more readable with a

If _Any($Alpha,'a|q|b|t|p') Then

than

If $Alpha = 'a' OR $Alpha = 'q' OR $Alpha = 'b' OR $Alpha = 't' OR $Alpha = 'p' Then

So I often use it... :ph34r:

Share this post


Link to post
Share on other sites

I agree, it almost gives it a SQL-like feel. Very cool!

*** Matt @ MPCS

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