开发者

subtract if the day of the week is a saturday or sunday

if the subtracted date is a saturday or sunday then subtract more days, before adding to arraylist

when i do this, the date stays the same and doesnt subtract, i get a conversion string to double error

Dim aftersubtraction As Date
                    Dim fromatafter As Date
                    aftersubtraction = departuredate.AddDays(-dates1.Text)
                    fromatafter = aftersubtraction.AddDays(-gracep.Text)

                    If fromataf开发者_运维技巧ter.DayOfWeek = "Saturday" Then
                        fromatafter.AddDays(-1)
                        dates.Add(fromatafter.ToString("MM/dd/yyyy"))
                    ElseIf fromatafter.DayOfWeek = "Sunday" Then
                        fromatafter.AddDays(-2)
                        dates.Add(fromatafter.ToString("MM/dd/yyyy"))
                    Else
                        dates.Add(fromatafter.ToString("MM/dd/yyyy"))
                    End If


While fromatafter.DayOfWeek = DayOfWeek.Saturday OrElse fromatafter.DayOfWeek = DayOfWeek.Sunday
    fromatafter = fromatafter.AddDays(-1)
End While
dates.Add(fromatafter.ToString("MM/dd/yyyy"))

You have to assigne the date returned from AddDays to your variable.

And please set option strict and explicit. Why?


if im not mistaken the vb dayofweek function returns an integer and not a string.

' 0 = Sunday ' 1 = Monday ' 2 = Tuesday ' 3 = Wednesday ' 4 = Thursday ' 5 = Friday ' 6 = Saturday

hence the error message.

your getting the string to double error on the

line with the if statement... becase .dayofweek does not return a string... it returns an integer... so an integer is never going to be = "Saturday" or "Sunday"... its going to be equal to 0 or 1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜