Vba 我有一个do-until循环,它使用一个布尔值和一个输入框。试图从输入循环中获取str变量
在visualbasics中,我有一个do-until循环来确保以正确的方式输入日期。如何在输入框中获取用户输入并将其保存为日期变量Vba 我有一个do-until循环,它使用一个布尔值和一个输入框。试图从输入循环中获取str变量,vba,excel,Vba,Excel,在visualbasics中,我有一个do-until循环来确保以正确的方式输入日期。如何在输入框中获取用户输入并将其保存为日期变量 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 becaus
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
存储输入,然后对其进行比较。如果
dateInput
设置为Date
类型,则检查失败,因为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
存储输入,然后对其进行比较。如果
dateInput
设置为Date
类型,则检查失败,因为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