问题描述
以下码工作良好:跨度>
For i = 0 to totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
如果工作日<> DayOfWeek.Friday AndAlso工作日<> DayOfWeek.Saturday那么
RqHours + = 1
结束如果
下一页
这里有错误:
Dim daya As string =" Friday"
Dim dayb As string =" Saturday"
For i = 0 to totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
如果 工作日<> daya AndAlso 工作日
<> dayb 然后
RqHours + = 1
结束如果
下一页
The following code working well:
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> DayOfWeek.Friday AndAlso weekday <> DayOfWeek.Saturday Then
RqHours += 1
End If
Next
here is got error:
Dim daya As string = "Friday"
Dim dayb As string= "Saturday"
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> daya AndAlso weekday <> dayb Then
RqHours += 1
End If
Next
请告知
推荐答案
DateTime.DayOfWeek是一个枚举:
DateTime.DayOfWeek is an enumeration:
https://msdn.microsoft.com/en-us/library/system.datetime.dayofweek(v = vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.datetime.dayofweek(v=vs.110).aspx
要将字符串转换为该枚举的其中一个成员,您需要解析它:
To convert the string to one of the members of that enum, you need to parse it:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(sender As System.Object, _
e As System.EventArgs) _
Handles MyBase.Load
Dim daya As String = "Friday"
Dim dayb As String = "Saturday"
Dim dowA As DayOfWeek = _
DirectCast([Enum].Parse(GetType(DayOfWeek), daya), DayOfWeek)
Dim dowB As DayOfWeek = _
DirectCast([Enum].Parse(GetType(DayOfWeek), dayb), DayOfWeek)
Stop
End Sub
End Class
这篇关于将DayOfWeek指定为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!