Domanda

Sto cercando di loop per ottenere tutti i 2011 date bisettimanali utilizzando questo codice in VB6:

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

Tuttavia, utilizzando il codice di cui sopra non produrre una alla data di bi-settimanale in corso ...

Qualsiasi aiuto sarebbe grande!

data di esempio

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

È stato utile?

Soluzione

Assuming you know the first date you want in 2011, and you know you want 26 fortnights, the code can be simplified extremely. For illustration purposes, add a textbox "Text1" to a form, and set MultiLine = True in the designer. We'll use 1/7/2011 for our starting date:

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

The output that shows in the textbox looks like this:

1/7/2011
1/21/2011
2/4/2011
2/18/2011
3/4/2011
...
12/23/2011
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top