Just the Steps
To implement If...Then
|
Just the Steps
To use If...Then...Else
|
如果程序有两种选择的话可以使用,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
Just the Steps
To Use If...Then...ElseIf
|
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
Just the Steps
To use Select Case
|