【问题标题】:InputBox. Undocumented distinguishing of user click OK with empty field and user click cancel输入框。未记录的用户单击“确定”与空字段和用户单击“取消”的区别
【发布时间】:2015-08-05 15:11:51
【问题描述】:

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>

【问题讨论】:

    标签: inputbox isnumeric


    【解决方案1】:

    接下来我重写了代码,现在它可以正常工作了:

        <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>
    

    【讨论】:

    • 但是很奇怪,相同的 IsNumeric("") 调用给出不同的返回值。
    猜你喜欢
    • 2015-09-02
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多