Real Software Forums
http://forums.realsoftware.com/

Convert VB to RB
http://forums.realsoftware.com/viewtopic.php?f=13&t=25174
Page 1 of 1

Author:  tcbasic [ Tue Nov 11, 2008 12:30 am ]
Post subject:  Convert VB to RB

I've written a utility to convert a file created with a program written in Visual Basic. Visual Basic has a Date type that I used to write some date info to the file.

Now I'm trying to convert the file and I need that Date information to be converted as well. The VB Date type uses a Double to represent the date and time information. I was hoping that I could assign this to the TotalSeconds property of the Date Class and it would work but it didn't. The values are different and I'm not sure how to parse out the VB date info.

Does anybody know a way I can convert this VB date data using Real Basic or how VB represents Date info in the Date type?

tc
-----------
REAL Basic r4.2
Windows Vista

Author:  QueenZ [ Tue Nov 11, 2008 3:57 am ]
Post subject:  Re: Convert VB to RB

Sorry, no ideas (newbie in programming here) but i'm interested in your converter.. Can it really convert my VB projects to RB projects..? when is it going to be ready?

Author:  jefftullin [ Wed Nov 12, 2008 3:20 pm ]
Post subject:  Re: Convert VB to RB

Off the top of my head, I think its a baseline problem.
The question you need to ask is 'what date is 0.000' in VB, and 'what date is 0.00' in RB's datetime.

Quick testing in VB using this code
Dim d As Date
MsgBox Format(CDate(0), "dd/mm/yyyy") '30th Dec 1899
MsgBox Format(Now(), "0.00000000") '39764.6576252


shows that ground zero in VB is effectively 01/01/1900
And that today is 39764.something

I did a bit of digging and found that Microsoft at least has two systems of date accounting in Excel.
1900 for compatibility with MSDOS, and 1904 for compatibility with Mac programs, which started counting in 1904 to 'avoid' having to account for 1900 as a leap year. (It says here...:> )

The difference between the two date systems is 1,462 days; that is, the serial number of a date in the 1900 Date System is always 1,462 days greater than the serial number of the same date in the 1904 date system. 1,462 days is equal to four years and one day (including one leap day).

You may therefore be on the right lines, but 1462 days out in the calc...

Author:  tcbasic [ Mon Nov 17, 2008 11:44 pm ]
Post subject:  Re: Convert VB to RB

Thanks for your help on this. What I ended up doing was using a 2 step approach instead of 1 step. I used VB to convert the Date variable to a couple of strings, one for the date and one for the time. I wrote these to a file that I later converted using RealBasic and the ParseDate function.

This did the trick, but again thanks for the info.

tc

Author:  Zhu [ Sat Jan 03, 2009 7:58 am ]
Post subject:  Re: Convert VB to RB

If you see some code like this in VB:
Dim d as Date
d=CDate(x) ' x is a double

You need convert it to RB like this:
Dim d as Date=new date
d.Year=1899
d.Month=12
d.Day=30
d.Hour=0
d.Minute=0
d.Second=0
d.TotalSeconds=d.TotalSeconds+x*86400

Author:  tcbasic [ Wed Jan 07, 2009 12:27 am ]
Post subject:  Re: Convert VB to RB

Hey Zhu,

Thanks so much for finding my post and responding. I used your code and it worked perfectly allowing me to eliminate the extra step of doing a quasi-conversion with VB. This makes my project update task a lot eaiser.

Thanks again, and Happy New Year!

tc

Author:  jhai_salvador [ Fri Jun 08, 2012 12:26 am ]
Post subject:  Re: Convert VB to RB

Now how can you convert the date to double?

Since vb6 Cdbl also works with date and RB does not allow that.

Author:  Zhu [ Fri Jun 08, 2012 2:32 am ]
Post subject:  Re: Convert VB to RB

jhai_salvador wrote:
Now how can you convert the date to double?

Since vb6 Cdbl also works with date and RB does not allow that.


Simply using d.TotalSeconds to return the double.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/