[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] [已解决]VBS怎样根据输入的数值运行不同的按键动作?

本帖最后由 qiaoliangih 于 2011-5-11 00:29 编辑

本人在医院工作,经常输入一些重复的药名与化验
所以做了一个vbs,全部用WshShell.SendKeys写的。但功能不完善
有些病号用药多,有些少,化验也是如此,我不得的不每次运行完vbs后修改录入记录。
我想让大家帮忙写个高级一点的。
运行vbs后先会询问这个药需要几个,按照输入的值去输入药量。
然后第二次询问另外一种药,如果是0就不输入,如果是1就输入1,是2就是输入2。
第三次询问有无特殊化验(默认是输出3种化验),如是0,则不输出特殊化验,如果是1,就输出特殊化验。
请大家帮帮忙,谢谢

可否改用vbs来做判断?

TOP

类似于这种
  1. Dim name,sex,birth
  2. name=InputBox("请输入姓名")
  3. sex=InputBox("请输入姓别")
  4. birth=InputBox("请输入出生日期")
  5. Set fso=CreateObject("scripting.filesystemobject")
  6. Set file=fso.createtextfile("" & name & ".txt",True)
  7. file.Close
  8. MsgBox name
  9. set fi=fso.opentextfile("" & name & ".txt",2)
  10. s="姓名:"&name&vbCrLf&"姓别:"&sex&vbCrLf&"出生日期:"&birth
  11. fi.write  s
  12. fi.close
复制代码

TOP

5# batman
谢谢版主大大
我想问下如何用if判断值呢?
  1. 第一种药是必须有的,输入多少数值,就模拟键盘输入相应的数量
  2. 第二种药是非必须的,有人要,就输入相应数值,然后用模拟键盘输入相应的数量。要是不要这个,就输入0,就不调用模拟键盘。也就是不输入。
  3. 第三个是化验,有人要,就输入相应数值,然后用模拟键盘输入相应的数量。要是不要这个,就输入0,就不调用模拟键盘。也就是不输入。
复制代码
if gansu = "0" then
end if
if gansu = ">0" then
WshShell.SendKeys ""&gansu&""

if touxi = "0" then
end if
if touxi = ">0" then
WshShell.SendKeys ""&touxi&""

TOP

  1. Dim tangshui,gansu,touxi
  2. tangshui=InputBox("瓶数")
  3. gansu=InputBox("支数")
  4. touxi=InputBox("次数")
  5. if gansu = "0" then
  6. end if
  7. if gansu = ">0" then
  8. WshShell.SendKeys ""&gansu&""
  9. if touxi = "0" then
  10. end if
  11. if touxi = ">0" then
  12. WshShell.SendKeys ""&touxi&""
复制代码
这样的结构可以实现吗?

TOP

8# fastslz
谢谢做的例子
我已经编辑运行成功,只是有些不足,请看我修改后的
  1. Dim tangshui,gansu,touxi,wshshell
  2. Set WshShell = CreateObject ("Wscript.Shell")
  3. input=InputBox("糖水瓶数")
  4. aSelect(input)
  5. input=InputBox("肝素支数")
  6. bSelect(input)
  7. input=InputBox("透析器次数")
  8. cSelect(input)
  9. Function aSelect(N)
  10.     Select Case N
  11.         Case 0
  12.              Exit Function
  13.         Case Else
  14.              Wscript.sleep 3000
  15.              Wshshell.SendKeys "lhn"
  16.              Wshshell.SendKeys "{ENTER}"
  17.              Wshshell.SendKeys "{ENTER}"
  18.              Wshshell.SendKeys ""&N&""
  19.              Wshshell.SendKeys "{ENTER}"
  20.              Wshshell.SendKeys "{ENTER}"
  21.              Wshshell.SendKeys "{ENTER}"
  22.     End Select
  23. End Function
  24. Function bSelect(B)
  25.     Select Case B
  26.         Case 0
  27.              Exit Function
  28.         Case Else
  29.              Wshshell.SendKeys "gsz"
  30.              Wshshell.SendKeys "{ENTER}"
  31.              Wshshell.SendKeys "{ENTER}"
  32.              Wshshell.SendKeys ""&B&""
  33.              Wshshell.SendKeys "{ENTER}"
  34.              Wshshell.SendKeys "{ENTER}"
  35.              Wshshell.SendKeys "{ENTER}"
  36.     End Select
  37. End Function
  38. Wshshell.SendKeys "xytx"
  39. Wshshell.SendKeys "{ENTER}"
  40. Wshshell.SendKeys "{ENTER}"
  41. Wshshell.SendKeys "{ENTER}"
  42. Wshshell.SendKeys "{ENTER}"
  43. Wshshell.SendKeys "{ENTER}"
  44. Wshshell.SendKeys "xtjc"
  45. Wshshell.SendKeys "{ENTER}"
  46. Wshshell.SendKeys "{ENTER}"
  47. Wshshell.SendKeys "{ENTER}"
  48. Wshshell.SendKeys "{ENTER}"
  49. Wshshell.SendKeys "{ENTER}"
  50. Wshshell.SendKeys "ycxg"
  51. Wshshell.SendKeys "{ENTER}"
  52. Wshshell.SendKeys "{ENTER}"
  53. Wshshell.SendKeys "{ENTER}"
  54. Wshshell.SendKeys "{ENTER}"
  55. Function cSelect(c)
  56.     Select Case c
  57.         Case 0
  58.              Exit Function
  59.         Case Else
  60.              Wshshell.SendKeys "txq"
  61.              Wshshell.SendKeys "{ENTER}"
  62.              Wshshell.SendKeys "{ENTER}"
  63.              Wshshell.SendKeys "{ENTER}"
  64.              Wshshell.SendKeys "{ENTER}"
  65.     End Select
  66. End Function
复制代码
1,运行后,在输入糖水瓶数后,第二个肝素的对话框要隔好几秒才出现,大家帮我提速下
2,当有透析器时,透析器在代码的最低端,希望它在输出时也在最低端。
默认顺序是
xytx
xtjc
ycxg
txq
现在的输出结果是
txq
xytx
xtjc
ycxg
  1. PS:输出结果请用TXT测试
复制代码

TOP

原来有有一部分先执行了,当输入第一个对话框不为0时,它马上就开始执行了,第二,第三都是如此,可以等三个对话框全部输入完毕再开始执行吗?

TOP

目前我在每个Case Else后加了sleep暂时延迟输入,还有其他的好办法吗?

TOP

大家还能帮忙吗

TOP

13# batman
恩,是需要Wshshell.SendKeys的,因为是要输入另外一个软件的。目前只有vbs模拟键盘比较有效

TOP

现在我陷入困境了,彻底没有招了

TOP

17# fastslz
18# fastslz
谢谢,谢谢fastslz 大大给出的完美解决办法,实在是太感谢了!!!!!!

TOP

该脚本我已经使用了大半年,今日想起,心存感激,特来再次感谢

TOP

返回列表