[Gambas-user] Using Date datatype for FOR-NEXT

Rolf-Werner Eilert eilert-sprachen at ...221...
Mon Jun 18 08:21:22 CEST 2007


I did this at another place in the program, but with dates which were 
produced by the program.

Here I was looking for a way to produce random dates at any point of 
start to any point of end (when the user clicks "one day ahead" or "one 
day back").

Meanwhile I built a small thing that can calculate the dates itself, 
using a lot of increasing, decreasing and IFs and stuff. But Ron's idea 
is good, isn't it?

Rolf


nando schrieb:
> I put actual dates into an array (sorted) and used FOR EACH to solve my problem.
> -Fernando
> 
> 
> ---------- Original Message -----------
> From: ron <ronstk at ...239...>
> To: info at ...394..., mailing list for gambas users <gambas-user at lists.sourceforge.net>
> Sent: Fri, 15 Jun 2007 15:47:24 +0200
> Subject: Re: [Gambas-user] Using Date datatype for FOR-NEXT
> 
>> On Friday 15 June 2007 08:51, Rolf-Werner Eilert wrote:
>>> Hope this gets through to you, I just read about trouble on the list...
>>>
>>> When I have something like
>>>
>>> IF mydate = Date(Now) + 1 THEN
>>>
>>> this runs well (saying "tomorrow"), but when I have the variables
>>>
>>> startdate, enddate, i
>>>
>>> all of type Date, I cannot make a FOR NEXT loop with them:
>>>
>>> FOR i = startdate to enddate
>>>
>>> It results in errors about wrong datatype ("expected numeric, got date 
>>> instead" etc.)
>>>
>>> Why's that?
>>>
>>> Rolf
>> For the simple 'FOR i = startval to endval' all the variables are numerical.
>>
>> With 'foreach i = startvar to endval' it could be a any datatype but the
>> increment must be also of that datatype. 
>> So it must changed to 'foreach i = startvar to endval step oneday' in that case.
>> However gambas does not support this way of working. :(
>>
>> Another could be 'foreach i in mydatatype_array' and here i is of same datatype 
>> as the mydatatype_array. Just also not as your requirement with an array.
>>
>> In other words, the example you give can't be done that way.
>>
>> FOR i = CINT(startdate) TO CINT(enddate) step CINT( (DAY(Now)+1)-DAY(Now) )
>> The step value calculate to the integer value need for 1 day.
>>
>> The variable i is of course integer here and if you need it as date
>> then CDATE(i) should be used. This is the integer variant of your example.
>>   note:
>>   This is not typed as a working example (or even tested with gambas) but to 
>>   explain/show how it could be done (for VB this worked for me in the past)
>>
>> A more appropriate way will be something like next.
>>   DIM i AS Date
>>   i=startdate
>>   DO
>>     'your code what must be done with i
>>     ...
>>     i=i+1 ' same as DATE(Now)+1
>>   LOOP UNTIL i=enddate ' or enddate+1
>>
>> Hope this explains something.
>>
>> Ron
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2 express and take
>> control of your XML. No limits. Just data. Click to get it now.
>> http://sourceforge.net/powerbar/db2/
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
> ------- End of Original Message -------
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 





More information about the User mailing list