我有一个做直到循环,使用一个布尔值和一个input框。 试图从input循环中获取一个strvariables

在VisualBasic中,我有一个做直到循环来确保dateinput正确的方式。 如何在input框中input用户input并将其保存为datevariables?

Private Sub cmdbtn3_Click() 'create a booleanvariable Dim blDone As Boolean 'ask for there name strName = InputBox("Please Enter Your Name", "Step 1") 'create a do while not because we want a repeat until blDone is True Do While Not blDone 'set the value of the input box with the product list equal to the boolean 'ask for the date of the start, have a do loop until date1 blDone = InputBox("Please Enter the Estimated Starting Date of CU" & vbNewLine & "Example 05/24/2014") Like "##/##/####" 'Create a msg that explains what the input must be If Not blDone Then MsgBox "the input didn't match the pattern '01/23/2014' where:" _ & vbNewLine & vbTab & "'01' must bethe month" _ & vbNewLine & vbTab & "'23' must be the date" _ & vbNewLine & vbTab & "'2014' must be the year" 'I need to save the value of the date as Loop End Sub 

存储input,然后做比较。 如果dateInput设置为Datetypes,那么您的检查将失败,因为01/01/2000更改为1/1/2000 。 我通过在Variant捕获它来检查,然后将其转换并存储在dateOutput中。

 Private Sub cmdbtn3_Click() 'create a booleanvariable Dim blDone As Boolean, dateInput As Variant, dateOutput As Date 'ask for there name strName = InputBox("Please Enter Your Name", "Step 1") 'create a do while not because we want a repeat until blDone is True Do While Not blDone 'set the value of the input box with the product list equal to the boolean 'ask for the date of the start, have a do loop until date1 dateInput = InputBox("Please Enter the Estimated Starting Date of CU" & vbNewLine & "Example 05/24/2014") blDone = dateInput Like "##/##/####" 'Create a msg that explains what the input must be If Not blDone Then MsgBox "the input didn't match the pattern '01/23/2014' where:" _ & vbNewLine & vbTab & "'01' must bethe month" _ & vbNewLine & vbTab & "'23' must be the date" _ & vbNewLine & vbTab & "'2014' must be the year" 'I need to save the value of the date as Loop dateOutput = CDate(dateInput) End Sub