Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim UTCTime As Date = TextBox1.Text
Dim IndianTime As DateTime = UTCTime.AddHours(5.5)
Dim beforeVal As New TimeSpan(168, 59, 59)
Dim beforeVal1 As New TimeSpan(72, 59, 59)
Dim beforeVal2 As New TimeSpan(23, 59, 59)
Label1.Text = IndianTime.AddSeconds(-beforeVal.TotalSeconds).ToString("G")
Label2.Text = IndianTime.AddSeconds(-beforeVal1.TotalSeconds).ToString("G")
Label3.Text = UTCTime.AddSeconds(-beforeVal2.TotalSeconds).ToString("G")
'////////////
Dim UTCTime1 As Date = Date.UtcNow
Dim IndianTime1 As DateTime = UTCTime1.AddHours(5.5)
Label4.Text = IndianTime1.ToString("G")
If CType(Label4.Text, Date) >= CType(Label3.Text, Date) Then
Label5.Text = "Sorry ! Ticket cannot be cancelled on same day or after journey date"
ElseIf CType(Label4.Text, Date) >= CType(Label2.Text, Date) Then
Label5.Text = "Sorry ! Ticket cannot be cancelled on same day or after journey date"
ElseIf CType(Label4.Text, Date) >= CType(Label1.Text, Date) Then
Label5.Text = "Sorry ! Ticket cannot be cancelled on same day or after journey date"
Else
Label5.Text = "Print"
End If
End Sub
它将始终显示味精label5 对不起!机票不能在同一天或旅程日期后取消 如果我只使用单一结束语句,那么它工作正常。 ...如果我使用上面提到的3个条件,它会在label5中显示错误信息,如对不起!车票不能在同一天或行程日期后取消
,如果我用这个来代替上面的代码....然后正常工作
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim UTCTime1 As Date = Date.UtcNow
Dim IndianTime1 As DateTime = UTCTime1.AddHours(5.5)
Label4.Text = IndianTime1.ToString("G")
If CType(Label4.Text, Date) >= CType(Label3.Text, Date) Then
Label5.Text = "Sorry ! Ticket cannot be cancelled on same day or after journey date"
Else
Label5.Text = "Print"
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim UTCTime As Date = TextBox1.Text
Dim IndianTime As DateTime = UTCTime.AddHours(5.5)
Dim beforeVal As New TimeSpan(168, 59, 59)
Dim beforeVal1 As New TimeSpan(72, 59, 59)
Dim beforeVal2 As New TimeSpan(23, 59, 59)
Label1.Text = IndianTime.AddSeconds(-beforeVal.TotalSeconds).ToString("G")
Label2.Text = IndianTime.AddSeconds(-beforeVal1.TotalSeconds).ToString("G")
Label3.Text = UTCTime.AddSeconds(-beforeVal2.TotalSeconds).ToString("G")
End Sub
你能描述你希望它做什么,和它做什么呢?你有什么例外吗?哪里? – 2011-04-20 08:03:10
如果我使用单一的,如果然后它的作品,如果我使用嵌套如果然后它不会工作 – sanjeel 2011-04-20 08:21:11