如何使用 MsgBox 在 VBS 中使用用户输入正确配置条件操作? [英] How do I properly configure conditional actions with user input in VBS with MsgBox?

查看:82
本文介绍了如何使用 MsgBox 在 VBS 中使用用户输入正确配置条件操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让 VBS 脚本与 msgbox 一起工作一段时间.当我使用单个 msgbox 语句时,它可以工作.一旦我开始添加条件输入选项,它就不起作用.

I have been trying to get a VBS script to work for a while now with msgbox. When I use a single msgbox statement, it works. As soon as I start adding conditional input options, then it doesn't work.

我在超级用户上发布了这个问题,并被告知使用dim"语句,并在此网站上发布,现在我已经完成了这两项工作.这是我正在尝试的一些有效代码.(请忽略我的例子.)

I posted this question on Super User and I was told to use the "dim" statement, and to post on this website, and I have done both now. Here is some of the code I am trying that works. (Please ignore my example.)

Option Explicit
Dim vbsmsg, vbsyes, vbsno
vbsmsg=MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed?", 1+48, "Format Drive C:")

当我通过快捷方式运行上面的代码时,我得到一个这样的对话框:

When I run the above code via a shortcut I get a dialog like this:

但是如果我添加以下内容,单击确定"或取消"时会出现运行时错误

But if I add the following, I get a run-time error when clicking "OK" or "Cancel"

If vbsmsg=1 Then
    vbsyes=MsgBox("The contents of your C: Drive could not be successfully deleted.", 0+64, "Error Formatting Drive C: - System Error 5")
If vbsmsg=2 Then
    vbsno=MsgBox("Not all of the contents of your C: Drive were successfully deleted. Please try again.", 0+64, "Error Formatting Drive C: - System Error 303")

错误中的行/字符在系统错误 303"中的0"和3"之间

The line/character in the error is between the "0" and "3" in "System Error 303"

我已经尝试了大量故障排除.我已经尝试过更改 dim 语句,添加显式选项,使用 1 和 2 而不是 6 和 8 等......似乎没有任何效果.当我注释掉第二部分时,执行文件后没有出现错误,而是关闭了我.我很肯定我的所有语法都是正确的并且格式正确.我将 1 和 2 更改为 vbOK 和 vbCancel,当我将其更改回来时,它根本不起作用,并立即给了我此页面上显示的错误.

I have tried a great deal of troubleshooting already. I have tried altering the dim statement, adding option explicit, using 1 and 2 instead of 6 and 8, etc... nothing seems to work. When I commented out the 2nd part, instead of getting an error after executing the file, it just closed on me. I am positive all of my syntax is correct and in the right format. I changed 1 and 2 to vbOK and vbCancel and when I changed it back it wouldn't work at all and gave me the error pictured on this page right away.

如果有人知道我的例子有什么问题,我将不胜感激.我对使用 VBS 文件还很陌生,但我已经使用 .bat 文件很长时间了,但这些原则似乎都在这里不起作用,

If anyone knows what is wrong with my examples, I would greatly appreciate it. I am fairly new to working with VBS files, but I have been working with .bat files for a long time and none of those principles seem to be working here,

我会很感激任何帮助,即使它很小,

I would appreciate any assistance, even if it is small,

推荐答案

试试这个例子:

Option Explicit
Dim Title,Question
Title = "user input in VBS with MsgBox"
Question = MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed ?",vbYesNo+vbQuestion, Title)
If Question = vbYes Then
    MsgBox "We proceed wipping your C:\ drive",vbExclamation,Title
    'Call your sub here to continue proceeding your script
Else
    MsgBox "Canceling the operation !",vbCritical,Title
    Wscript.Quit()
End If

有关 MsgBox 的更多信息常量

For more information about MsgBox Constants

这篇关于如何使用 MsgBox 在 VBS 中使用用户输入正确配置条件操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆