Connecting Tech Pros Worldwide Forums | Help | Site Map

VB.Net Date Serial?

sam
Guest
 
Posts: n/a
#1: Nov 21 '05
Possible convert VB 6 to VB.Net 1.1 for date serial function?


Example, Calendar_Date = DateSerial(1900+(Julian_Date/1000), 1,Julian_Date
Mod 1000) ?

Calendar_Date and Julian_Date are input variable.

Please advise.

Many thanks.



Oenone
Guest
 
Posts: n/a
#2: Nov 21 '05

re: VB.Net Date Serial?


sam wrote:[color=blue]
> Possible convert VB 6 to VB.Net 1.1 for date serial function?[/color]

DateSerial is still supported in VB.NET 1.1. If you can't get it working,
try this:

\\\
Calendar_Date = Microsoft.VisualBasic.DateSerial(1900+(Julian_Date/1000),
1,Julian_Date Mod 1000)
///

If that's not working either, what error message do you get?

--

(O) e n o n e


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#3: Nov 21 '05

re: VB.Net Date Serial?


"sam" <samuellai@ajikl.com.my> schrieb:[color=blue]
> Possible convert VB 6 to VB.Net 1.1 for date serial function?[/color]

VB.NET still supports 'DateSerial'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
sam
Guest
 
Posts: n/a
#4: Nov 21 '05

re: VB.Net Date Serial?


I have an error message during perform dateserial in VB.Net 1.1 based on my
coding as shown as below:

Coding
-------
Imports System
Imports System.Data
Imports Microsoft.VisualBasic

Dim Inv_Date, GL_Date, InvDte,GLdte As Double

InvDte = CDbl(InvDte)
GLdte = CDbl(GLdte)

ADO Connection.....
Try
Do While dbrRD_F0411B.Read
InvDte = CDbl(dbrRD_F0411B("RPDIVJ"))
GLdte = CDbl(dbrRD_F0411B("RPDGJ"))

GL_Date = DateSerial(1900+(GLdte/1000), 1,GLdte Mod 1000)
Inv_Date= DateSerial(1900+(InvDte/1000),1,InvDte Mod 1000)
Loop
End Try

Error Message
---------------
BC30532 : Conversion from 'Date' to 'Double' requires caling the
'Date.ToOADate' method

Please advise.

Many thanks.


"Oenone" <oenone@nowhere.com> wrote in message
news:dNAle.126$s25.40@newsfe1-win.ntli.net...[color=blue]
> sam wrote:[color=green]
>> Possible convert VB 6 to VB.Net 1.1 for date serial function?[/color]
>
> DateSerial is still supported in VB.NET 1.1. If you can't get it working,
> try this:
>
> \\\
> Calendar_Date = Microsoft.VisualBasic.DateSerial(1900+(Julian_Date/1000),
> 1,Julian_Date Mod 1000)
> ///
>
> If that's not working either, what error message do you get?
>
> --
>
> (O) e n o n e
>
>[/color]


Oenone
Guest
 
Posts: n/a
#5: Nov 21 '05

re: VB.Net Date Serial?


sam wrote:[color=blue]
> I have an error message during perform dateserial in VB.Net 1.1 based
> on my coding as shown as below:[/color]

[...][color=blue]
> Dim Inv_Date, GL_Date, InvDte,GLdte As Double
> GL_Date = DateSerial(1900+(GLdte/1000), 1,GLdte Mod 1000)[/color]
[...]

Ah, that's not a problem with DateSerial, that's a problem with variable
typing.

In VB6, dates were stored as Double values so you could directly assign a
Date to a Double variable.

In VB.NET, dates have their own distinct type (Date) and you can't directly
convert between them.

If you want to do what you're doing above, you will need to either:

1. Change your GL_Date (and probably your other variables too) to be defined
As Date instead of As Double. However, this will most likely break your
dbrRD_F0411B calls as they presumably return Double values too. You'll need
to change these to also return Date values.

2. Alternatively, leave your variables as Doubles and use the OLE Automation
Date conversion functions. These two methods are defined against the Date
class are can be used to convert a value from a Date to a Double (the
ToOADate() function) or from a Double to a Date (the FromOADate() function).

\\\
'Convert Date to a Double
GL_Date = DateSerial(2005,5,30).ToOADate

'Convert Double back to a Date
Dim d As Date = Date.FromOADate(GL_Date)
///

Hopefully that'll set you off in the right direction.

--

(O) e n o n e


Closed Thread