我有这个代码弹出一个消息框,要求用户以mm/dd/yyyy格式输入日期。点击取消时,表示输入有效日期。如果用户取消该框,则消息框应该停止/消失。但我不知道该怎么做。vb代码 - 取消消息框
下面的代码:
Try
Dim docDate As String
Dim batchNumber as String
Dim dDate As Date
Dim match As System.Text.RegularExpressions.Match
'Define the regular expression to check dates
Dim dateRegex As New System.Text.RegularExpressions.Regex(regExpression)
'Prompt for the document date
docDate = Microsoft.VisualBasic.Interaction.InputBox(“Enter the document date (mm/dd/yyyy):”, “Document Date”)
'Match the input against the regex
match = dateRegex.Match(docDate)
'While it doesn't match the regex or a valid date continue to prompt for it
Do While (Not match.Success Or Not Microsoft.VisualBasic.IsDate(docDate))
'Alert the user of the problem
Microsoft.VisualBasic.MsgBox(“Please enter a valid date in the format of mm/dd/yyyy.”)
'Prompt for the document Date
docDate = Microsoft.VisualBasic.Interaction.InputBox(“Enter the document date (mm/dd/yyyy):”, “Document Date”)
'Match the input against the regex
match = dateRegex.Match(docDate)
Loop
'Store the input dates in Date datatypes
dDate = CDate(docDate)
'Set the value into the global variables
GBL_DOCUMENTDATE = dDate
GBL_BATCH = batchNumber
Catch ex As Exception
If (mapInterface = 1) Then
Messagebox.Show(ex.Message, “DateInputTemplate Script Error”)
End If
Return False
End Try
使用DateTimePicker控件,你不必验证任何东西。请阅读[问]并参加[游览]。 – Plutonix
...东西,东西,正则表达式,现在你有两个问题... – LarsTech
我建议阅读精美的文档,它会向你解释当用户选择“取消”时InputBox的返回值。然后,相应地调整循环中的条件。 – Craig