[Gambas-user] gb3: Format$

Kevin Fishburne kevinfishburne at ...1887...
Sun Jun 26 00:45:16 CEST 2011


On 06/24/2011 06:42 PM, Benoît Minisini wrote:
>> I'm using this to print a formatted date:
>>
>> Draw.Text("Date and Time: "&  CDate(Server.DateCurrent)&  " ("&
>> Format$(CDate(Server.DateCurrent), "hh:nn:AM/PM")&  ")", 32, ystart - 1)
>>
>> It seems that Format$ actually changes the value of Server.DateCurrent,
>> making it AM when it should be PM. Format$ is actually forcing the hour
>> to be between 1 and 12. Shouldn't Format$ simply return a value and not
>> overwrite the expression?
>
> Format$() does not change its arguments, as any other functions in Gambas.
>
> When AM/PM is specified, the hour is displayed between 1 and 12. If the real
> hour is greater or equal than 12:00, then PM is printed. Otherwise AM is
> printer.

That makes perfect sense and was the expected behavior. I'm not sure 
what's happening here, but this test code:

Public Sub Main()

   Dim t As Float

   t = CFloat(Now) ' Current time and date.

   Print "1: CDate(t):                         " & CDate(t)
   Print "2: Format$(CDate(t), \"hh:nn:AM/PM\"): " & Format$(CDate(t), 
"hh:nn:AM/PM")
   Print "3: CDate(t):                         " & CDate(t)
   Print "4: Format$(CDate(t), \"hh:nn:AM/PM\"): " & Format$(CDate(t), 
"hh:nn:AM/PM")
   Print "5: CDate(t):                         " & CDate(t)

End

Produces these results:

1: CDate(t):                         06/25/2011 18:35:46.837
2: Format$(CDate(t), "hh:nn:AM/PM"): 06:35:PM
3: CDate(t):                         06/25/2011 06:35:46.837
4: Format$(CDate(t), "hh:nn:AM/PM"): 06:35:AM
5: CDate(t):                         06/25/2011 06:35:46.837

I checked, and the value of variable "t" is not being changed. However, 
after the first Format$, CDate(t) returns a different value than before 
the first Format$. Any idea why? Lines 1 and 2 look good, but it seems 
like lines 1 and 3 should print the same value. Somehow the Format$ line 
continues to have an effect on the subsequent lines.

I hope I'm really not so stupid that I'm missing something obvious. I'm 
not even drinking right now!

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list