的InputBox。未记录的区分用户单击确定与空字段和用户单击取消

时间:2015-08-05 15:11:51

标签: inputbox isnumeric

IsNumeric函数根据用户的不同返回不同的值。如果用户使用空字段按OK,我的代码将按原样运行。但是当用户按下取消时,我的代码退出循环。为什么?我需要InputBox对话框仍然无限显示,直到用户输入数字。怎么做?

    <package>
 <job id="NonDisabledServicesCollecting">
<COMMENT>
************************************************************
1 comment
2 
3 
************************************************************
</COMMENT>
  <script language="VBScript">
flash_folder="I:\123\"
str_flash_folder_colFiles = ""
num_flash_folder_colFiles = 0
Set flash_folder_colFiles = CreateObject("Scripting.FileSystemObject").GetFolder(flash_folder).Files
Dim table_flash_folder_colFiles()
ReDim Preserve table_flash_folder_colFiles(flash_folder_colFiles.Count) 'zero-element not used
For Each flash_folder_objFile in flash_folder_colFiles
  num_flash_folder_colFiles = num_flash_folder_colFiles + 1
  table_flash_folder_colFiles(num_flash_folder_colFiles) = flash_folder_objFile.Name
  str_flash_folder_colFiles = str_flash_folder_colFiles + cstr(num_flash_folder_colFiles) + " " + flash_folder_objFile.Name + vbCrLf
Next

Dim response
Do
  response = InputBox("Please enter the number that corresponds to your selection:" + vbCrLf + str_flash_folder_colFiles, "Choose DLL to copy...")
  If response = "" Then WScript.Echo "Input is empty." 'Detect Cancel
WScript.Echo response
WScript.Echo IsNumeric(response)
  If IsNumeric(response) Then Exit Do                  'Detect value response.
  WScript.Echo "You must enter a numeric value."
Loop
selected_flush_DLL= flash_folder + table_flash_folder_colFiles(cint(response))
WScript.Echo selected_flush_DLL

  </script>
 </job>
</package>

1 个答案:

答案 0 :(得分:0)

我下一步重写代码,现在它可以正常工作:

    <package>
 <job id="NonDisabledServicesCollecting">
<COMMENT>
************************************************************
1 comment
2 
3 
************************************************************
</COMMENT>
  <script language="VBScript">
flash_folder="I:\123\"
str_flash_folder_colFiles = ""
num_flash_folder_colFiles = 0
Set flash_folder_colFiles = CreateObject("Scripting.FileSystemObject").GetFolder(flash_folder).Files
Dim table_flash_folder_colFiles()
ReDim Preserve table_flash_folder_colFiles(flash_folder_colFiles.Count) 'zero-element not used
For Each flash_folder_objFile in flash_folder_colFiles
  num_flash_folder_colFiles = num_flash_folder_colFiles + 1
  table_flash_folder_colFiles(num_flash_folder_colFiles) = flash_folder_objFile.Name
  str_flash_folder_colFiles = str_flash_folder_colFiles + cstr(num_flash_folder_colFiles) + " " + flash_folder_objFile.Name + vbCrLf
Next

Dim response
Do
  response = InputBox("Please enter the number that corresponds to your selection:" + vbCrLf + str_flash_folder_colFiles, "Choose DLL to copy...")
  If response = "" Then 
    WScript.Echo "Input is empty."       'Detect Cancel
  Else
    if IsNumeric(response) Then
      Exit Do  'Detect value response.
    else
      WScript.Echo "You must enter a numeric value."
    end if
  End If 
Loop
selected_flush_DLL= flash_folder + table_flash_folder_colFiles(cint(response))
WScript.Echo selected_flush_DLL

  </script>
 </job>
</package>