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