[Part 1 - Original question]
我有30,31,28或29的值,这是一个月的总天数。
我想制作一个for循环
如果我选择28,它应该显示28次msgbox。
如果我选择31,它应该显示一次msgbox 31次。
我试过的代码:
Dim dayst As Variant
Dim tot1 As Variant
tot1 = DateDiff("d", "01/2011", DateAdd("m", 1, "01/2011"))
tot1 = Split(tot1, ",")
For Each dayst In tot1
MsgBox dayst
Next
以上代码在msgbox中显示“31”,而不是像“1”,“2”,...“31”
我希望显示一个msgbox,从1到31递增31次。
[Part 2 - Updated request]
默认列值示例
ID 1 2 ..... 31 totaldays
001 Yes Yes .... Yes 31
002 Yes Yes .... Yes 31
003 Yes Yes .... Yes 31
.....
001 is coming from table
Yes is the default column value for 1 to 31 or 1 to 28
totaldays should be no of days permonth.
如何使用vb6完成此操作。
答案 0 :(得分:3)
你可以使用这样一个简单的循环 - 虽然我不明白你为什么要连续提供28-31个MsgBox提示
Dim tot1 As Long
Dim lngDays As Long
tot1 = DateDiff("d", "01/2011", DateAdd("m", 1, "01/2011"))
For lngDays = 1 To tot1
MsgBox lngDays
Next
<强> Updated version - adds early exit option
强>
Dim tot1 As Long
Dim lngDays As Long
Dim lngExit As Long
tot1 = DateDiff("d", "01/2011", DateAdd("m", 1, "01/2011"))
For lngDays = 1 To tot1
lngExit = MsgBox(lngDays, vbOKCancel, "Press Cancel to exit")
If lngExit = vbCancel Then Exit Sub
Next