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

[RESOLVED] CStr - string conversion function broken and function return value?

$
0
0
In need to develop/add yearly workday calendar to app developed ages ago, faced problem related to function return value.

Code:

[Private Sub Form_Load()
Dim i As Integer
Dim x As String

Text1.Text = ""
'Text1.MultiLine =True 'set to true in designtime
For i = 2000 To 2024
    x = x & LaskePaasianen(i) & vbCrLf
Next i

Text1.Text = x
End Sub

Private Function LaskePaasianen(ByVal iEasterYear As Integer) As String
'Computes easter sunday using Gaussin, Zellerin, Lichtenbergin et al. method.
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer
Dim g As Integer
Dim h As Integer
Dim i As Integer
Dim k As Integer
Dim L As Integer
Dim m As Integer
Dim EMonth As Integer
Dim EDay As Integer

a = iEasterYear Mod 19
b = iEasterYear \ 100
c = iEasterYear Mod 100
d = b \ 4
e = b Mod 4
f = (b + 8) \ 25
g = (b - f + 1) \ 3
h = (19 * a + b - d - g + 15) Mod 30
i = c \ 4
k = c Mod 4
L = (32 + 2 * e + 2 * i - h - k) Mod 7
m = (a + 11 * h + 22 * L) \ 451
EMonth = (h + L - 7 * m + 114) \ 31 'Easter month
EDay = ((h + L - 7 * m + 114) Mod 31) + 1 'Easter day

LaskePaasiainen = CStr(CDate(DateSerial(iEasterYear, EMonth, EDay) + TimeSerial(0, 0, 0)))
'LaskePaasiainen = FormatDateTime(CDate(DateSerial(iEasterYear, EMonth, EDay) + TimeSerial(0, 0, 0)), vbShortDate)
'GoodFriday = DateSerial(iEasterYear, EMonth, EDay - 2) 'Pitkäperjantai (Good Friday) = EDay - 2
End Function

Any idea why LaskePaasiainen function returns 'nill'?

Tested it with...
Len(LaskePaasianen(i)) -> returns 0

Likewise neither of these methods in below, does not work...
Code:

Private Function LaskePaasianen(ByVal iEasterYear As Integer) As Date 'declaration
.
LaskePaasiainen = FormatDateTime(CDate(DateSerial(iEasterYear, EMonth, EDay) + TimeSerial(0, 0, 0)), vbShortDate) 'return value

Code:

Private Function LaskePaasianen(ByVal iEasterYear As Integer) As String 'declaration
.
LaskePaasiainen = Format$(CDate(DateSerial(iEasterYear, EMonth, EDay) + TimeSerial(0, 0, 0)),"dd.mm.yyyy") 'return value


Viewing all articles
Browse latest Browse all 21233

Trending Articles



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