欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

vbscript(三) adding intelligence

更新时间: 2014-01-05 01:52:21 责任编辑: Author_N1

 

Vbscript(3) Adding Intelligence

Adding Intelligence

If...Then

Just the Steps

To implement If...Then

1.

On a new line in the script, type If some condition Then.

2.

On the next line, enter the command you want to invoke.

3.

On the next line, type End If.

If...Then...Else

Just the Steps

To use If...Then...Else

1.

On a new line in the script, type If some condition Then.

2.

On the next line, enter the command you want to invoke.

3.

On the next line, type Else.

4.

On the next line, type the alternate command you want to execute when the condition is not true.

5.

On the next line, type End If.

如果程序有两种选择的话可以使用,If….Then …Else

ifThenElse.vbs

Option Explicit
On Error Resume Next
Dim a,b,c,d
a = 1
b = 2
c = 3
d = 4
If a + b = d Then
  WScript.Echo (a & " + " & b & " is equal to " & d)
Else
  WScript.Echo (a & " + " & b & " is equal to " & c)
End If

If...Then...ElseIf

Just the Steps

To Use If...Then...ElseIf

1.

On a new line in the script, type If some condition Then.

2.

On the next line, enter the command you want to invoke.

3.

On the next line, type ElseIf and the new condition to check, and end the line with Then.

4.

On the next line, enter the command you want to invoke when the condition on the ElseIf line is true.

5.

Repeat steps 3 and 4 as required.

6.

On the next line, type End If.

CPUType.vbs

Option Explicit
On Error Resume Next
Dim strComputer
Dim cpu
Dim wmiRoot
Dim objWMIService
Dim ObjProcessor
strComputer = "."
cpu = "win32_Processor='CPU0'"
wmiRoot = "winmgmts:\\" & strComputer & "\root\cimv2"
Set objWMIService = GetObject(wmiRoot)
Set objProcessor = objWMIService.Get(cpu)
If objProcessor.Architecture = 0 Then
  WScript.Echo "This is an x86 cpu."
ElseIf objProcessor.Architecture = 1 Then
  WScript.Echo "This is a MIPS cpu."
ElseIf objProcessor.Architecture = 2 Then
  WScript.Echo "This is an Alpha cpu."
ElseIf objProcessor.Architecture = 3 Then
  WScript.Echo "This is a PowerPC cpu."
ElseIf objProcessor.Architecture = 6 Then
  WScript.Echo "This is an ia64 cpu."
Else
  WScript.Echo "Cannot determine cpu type."
End If

 

Select Case

Just the Steps

To use Select Case

1.

On a new line in the script, type Select Case and a variable to evaluate.

2.

On the second line, type Case 0.

3.

On the third line, assign a value to a variable.

4.

On the next line, type Case 1.

5.

On a new line, assign a value to a variable.

6.

On the next line, type End Select.

上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 01:52:21
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/2307/
本文WWW.DOC100.NET DOC100.NET版权所有。