Hack Forums
[.NET] [SOLVED]Days360 in vb6[SOLVED] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [SOLVED]Days360 in vb6[SOLVED] (/showthread.php?tid=4749671)



[SOLVED]Days360 in vb6[SOLVED] - iSmile - Mar 27, 2015

Hi,

Currently I am working on some application. Previously my tool was made in Excel with VBA. Excel is using the days360 code, which I (still) can't use/find in vb6.

I am looking for the right (excel) 'days360' code, which works in my vb6 project on textbox1.text and textbox2.text (which are date values).

Hopefully someone could help me.

Best regards,
iSmile.


* - Danny233223_temp - Mar 27, 2015

If the function uses the parameters startdate and enddate, I found following code from vbcity.com

Code
Public Function Days360(StartDate As Date, EndDate As Date, Optional Method As Boolean = False) As Long
  Dim TempMonths As Long
  Dim StartDay As Long
  Dim EndDay As Long
  StartDay = Day(StartDate)
  EndDay = Day(EndDate)
  If Not Method Then
    If StartDay > 30 Then
      StartDate = DateAdd("d", -1, StartDate)
    End If
    If EndDay = 31 And StartDay > 30 Then
      EndDate = DateAdd("d", 1, EndDate)
    Else
      If EndDay = 31 Then
      EndDate = DateAdd("d", -1, EndDate)
      End If
    End If
  Else
    If StartDay > 30 Then
      StartDate = DateAdd("d", -1, StartDate)
    End If
    If EndDay > 30 Then
      EndDate = DateAdd("d", -1, EndDate)
    End If
  End If
  StartDay = Day(StartDate)
  EndDay = Day(EndDate)
  TempMonths = DateDiff("M", StartDate, EndDate)
  Days360 = (TempMonths * 30) + (EndDay - StartDay)
End Function



* - iSmile - Mar 27, 2015

(Mar 27, 2015 11:02 AM)Danny233223_temp Wrote:  If the function uses the parameters startdate and enddate, I found following code from vbcity.com

Code
Public Function Days360(StartDate As Date, EndDate As Date, Optional Method As Boolean = False) As Long
  Dim TempMonths As Long
  Dim StartDay As Long
  Dim EndDay As Long
  StartDay = Day(StartDate)
  EndDay = Day(EndDate)
  If Not Method Then
    If StartDay > 30 Then
      StartDate = DateAdd("d", -1, StartDate)
    End If
    If EndDay = 31 And StartDay > 30 Then
      EndDate = DateAdd("d", 1, EndDate)
    Else
      If EndDay = 31 Then
      EndDate = DateAdd("d", -1, EndDate)
      End If
    End If
  Else
    If StartDay > 30 Then
      StartDate = DateAdd("d", -1, StartDate)
    End If
    If EndDay > 30 Then
      EndDate = DateAdd("d", -1, EndDate)
    End If
  End If
  StartDay = Day(StartDate)
  EndDay = Day(EndDate)
  TempMonths = DateDiff("M", StartDate, EndDate)
  Days360 = (TempMonths * 30) + (EndDay - StartDay)
End Function
Hi Danny,

Thanks for your quick reply!

Another question, seems I can't figure out how to use this:

As fo
StartDay = Day(StartDate)
EndDay = Day(EndDate)

The both Day I changed
to:
StartDay = text20.text(StartDate)
EndDay = text21.text(EndDate)

As for in the form:
When button clicked:
text22.text = days360

How can i get this working?

Best regards


* - Danny233223_temp - Mar 27, 2015

Hey iSmile,

have you tried to call the function with:
Code
text22.text  = Days360(text20.text, text21.text)



* - iSmile - Mar 27, 2015

(Mar 27, 2015 11:37 AM)Danny233223_temp Wrote:  Hey iSmile,

have you tried to call the function with:
Code
text22.text  = Days360(text20.text, text21.text)

Thank you very much!

It actually worked ^^. +REP over here