Frage

Ich versuche zu schleifen, um alle zwei wöchentlichen Daten von 2011 mit diesem Code in VB6 zu erhalten:

Dim HardDate As Date
Dim NumberOfDaysSince As Integer
Dim modulus As Integer
Dim DaysToNext As Integer
Dim nextpayday As Date
Dim x As Integer

x = 1
DateToday = Date
HardDate = Format(Now, "m/dd/yyyy")

Do While x <> 20
    NumberOfDaysSince = DateDiff("d", HardDate, DateToday)
    modulus = NumberOfDaysSince Mod 14
    DaysToNext = 15 - modulus
    nextpayday = Date + DaysToNext

    Debug.Print nextpayday
    HardDate = DateAdd("d", 1, nextpayday)
    DateToday = DateAdd("d", 10, HardDate)
    x = x + 1
Loop

Die Verwendung dieses Codes oben erzeugt jedoch kein zweiwöchentliches Datum ...

Jede Hilfe wäre großartig!

Datum Beispiel

Pay Begin Date | Pay End Date | Check Date | Posts
-------------------------------------------------------------------
1/14/2011      | 1/24/2011    | 2/10/2011  | 2/3/2011
1/28/2011      | 2/10/2011    | 2/24/2011  | 2/17/2011
2/11/2011      | 2/24/2011    | 3/10/2011  | 3/3/2011

David

War es hilfreich?

Lösung

Angenommen, Sie wissen das erste Datum, das Sie 2011 gewünscht haben, und Sie wissen, dass Sie 26 Wochen Zeit wünschen, der Code kann extrem vereinfacht werden. Zum Abbildungszwecken fügen Sie einem Formular einen Textfeld "Text1" hinzu und setzen Sie Multiline = True im Designer. Wir werden 1/7/2011 für unser Startdatum verwenden:

Dim HardDate As Date
Dim x As Integer

x = 1
HardDate = "1/7/2011"
Text1.Text = HardDate
Do Until x = 26
    HardDate = DateAdd("d", 14, HardDate)
    Text1.Text = Text1.Text & vbCrLf & HardDate
    x = x + 1
Loop

Die Ausgabe, die in der Textbox angezeigt wird, sieht folgendermaßen aus:

1/7/2011
1/21/2011
2/4/2011
2/18/2011
3/4/2011
...
12/23/2011
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top