我有這個代碼彈出一個消息框,要求用戶以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