Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 22096

Code Makes No Sense to Me

$
0
0
I'm no vb expert by any stretch of the imagination.

While looking at a piece of VB6 code to convert to C#, I found myself dumbfounded as to why this code was written the way it was.

Maybe I'm missing something.

This code is part of a code module that contains functions for figuring out MOON PHASES.

What this particular function appears to do is simply return the date "12/30/1899" along with the TIME found in the string "sTime" passed to it.


Code:

Function pfunDayZero(sTime As String) As String

Dim dDate As String, iPosition As Integer, dTemp As String
Dim sReplace As String, iStart As Integer

    'Initialize
    iStart = 1
    iPosition = 0
    dDate = CVDate(1 + TimeValue(sTime))
    sReplace = Day(DateSerial(1899, 12, 30))
   
    'Search routine
    Do
        dTemp = dDate
        iStart = 1 + iPosition
        iPosition = InStr(iStart, dTemp, Day(DateSerial(1899, 12, 31)))
        Mid(dTemp, iPosition, Len(sReplace)) = sReplace
        If Not IsDate(dTemp) Then dTemp = dDate
       
    Loop Until DateValue(dTemp) = 0

    pfunDayZero = dTemp


End Function

It seems that no matter what date or time is passed to the above function, I get back 12/30/1899 plus the original TIME passed into the function as a Date/Time string.

For example:

sTime = "05/06/2010 05:00:00"

You get back "12/30/1899 05:00:00".


So why does this code include all kinds of conversions and string parsing, etc.?

It would seem to me that all I'd have to do to rewrite this in my C# (or any other language) is to simply get the TIME value from any passed date and to append that TIME to "12/30/1899" before returning it.

Does anyone see an INTENT for the above code that I am missing?

All the functions in this module seem to work fine in getting me the correct moon phases, so I have to assume they are working fine.


TIA

Webbiz

Viewing all articles
Browse latest Browse all 22096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>