|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
|
2007-6-14 11:44 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 47 楼』:
使用 LLM 解释/回答一下
1.因为Msgbox的第三个参数是标题,像下面这样就可以省些力气:
MsgBox "1",,"2"
2.凡是将一对象引用赋给变量,就需要使用 Set关键字。那么什么是对象引用呢?凡是字符串、数值、布尔值之外的变量都是对象引用。
3. Run在运行解析时,遇到空格会停止,解决的方法是使用双引号。比如:wscript.shell.run"""D:\Study\VBS\windows 脚本编程核心技术精解"""。
run函数有三个参数,第一个参数是你要执行的程序的路径,第二个程序是窗口的形式,0是在后台运行;1表示正常运行;2表示激活程序并且显示为最小化;3表示激活程序并且显示为最大化...; 第三个参数是表示这个脚本是等待还是继续执行,如果设为了true,脚本就会等待调用的程序退出后再向后执行。
1. Because the third parameter of Msgbox is the title, you can save some effort like the following:
MsgBox "1",,"2"
2. Whenever you assign an object reference to a variable, you need to use the Set keyword. Then what is an object reference? Any variable other than strings, numeric values, and Boolean values is an object reference.
3. Run stops when encountering spaces during runtime resolution. The solution is to use double quotes. For example: wscript.shell.run"""D:\Study\VBS\windows 脚本编程核心技术精解"""。
The run function has three parameters. The first parameter is the path of the program you want to execute. The second parameter is the form of the window. 0 is running in the background; 1 means running normally; 2 means activating the program and displaying it as minimized; 3 means activating the program and displaying it as maximized... The third parameter indicates whether this script waits or continues to execute. If set to true, the script will wait until the called program exits before continuing to execute.
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-6-14 12:05 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 48 楼』:
使用 LLM 解释/回答一下
1.On Error Resume Next
这行语句可以告诉vbs在运行时跳过发生错误的语句,紧接着执行跟在它后面的语句。
2.虽然On Error Resume Next语句可以防止vbs脚本在发生错误时停止运行,但是它并不能真正处理错误,要处理错误,你需要在脚本中增加一些语句,用来检查错误条件并在错误发生时处理它。
vbscript提供了一个对象err对象,他有两个方法clear,raise,5个属性:description,helpcontext,helpfile,number,source。err对象不用引用实例,可以直接使用。
1.On Error Resume Next
This line of code can tell VBS to skip the statement where an error occurs during runtime and immediately execute the statement that follows it.
2. Although the On Error Resume Next statement can prevent the VBS script from stopping when an error occurs, it cannot truly handle the error. To handle the error, you need to add some statements in the script to check the error condition and handle it when an error occurs.
VBScript provides an object, the err object, which has two methods: clear and raise, and five properties: description, helpcontext, helpfile, number, and source. The err object can be used directly without referencing an instance.
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-6-14 15:17 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 49 楼』:
使用 LLM 解释/回答一下
关于操作注册表我想说的:
1.显然要借助(引用)Wscript.Shell。
2.路径的最后是用"\"结尾的,比如"HKCU\....\Thing\",就表示这是个项;若没有"\",如"HKCU\....\Thing",则表示这是个键值(键值跟数据不是一个概念)
3.对于写操作,可以在(路径上的)一个项后进行随意的延伸,不用去担心这个项或键值本身是否存在;如果不存在,那就是“一路”新增,如果存在,那就是修改。All Right?!
4.若想删除一个键值,则Wscript.Shell.Regdelete "HKCU\....\Thing";
若想把该键值的数据清空,则Wscript.Shell.Regwrite "HKCU\....\Thing",""。
Last edited by Billunique on 2007-6-14 at 04:35 PM ]
About operating the registry, I would like to say:
1. Obviously, we need to rely on (reference) Wscript.Shell.
2. The end of the path is with the "\" ending, for example, "HKCU\....\Thing\" means this is a key; if there is no "\", such as "HKCU\....\Thing", then it means this is a value (value and data are not the same concept)
3. For write operations, you can freely extend after a key in (on the path), without worrying about whether the key or value itself exists; if it does not exist, then it is "added all the way", and if it exists, then it is modified. All Right?!
4. If you want to delete a value, then Wscript.Shell.Regdelete "HKCU\....\Thing";
If you want to clear the data of that value, then Wscript.Shell.Regwrite "HKCU\....\Thing", "".
Last edited by Billunique on 2007-6-14 at 04:35 PM ]
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-6-14 16:29 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
|
2007-6-15 12:02 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 51 楼』:
使用 LLM 解释/回答一下
用下面这些代码放在VB编辑器里试试大致可以明白关于文件操作的一些东西:
Set fs=CreateObject("scripting.filesystemobject")
'Set ff=fs.GetFile("d:\bak\11.txt")
'MsgBox ff
'i=ff.Attributes
'MsgBox i
Set fo=fs.OpenTextFile("d:\bak\11.txt")
'MsgBox fo
v=fo.Read(5)
MsgBox v
line1=fo.ReadLine
line2=fo.ReadLine
MsgBox line2
con=fo.ReadAll
MsgBox con
'11.txt文件的内容可以是这样:
cndos.1111 aaa
22222
想说明的是,OpenTextFile之后进行的Read操作,好像是在“切割”文本似的;上面的先读了到下面就只能读到其“切”完的加上自己“能力范围”内的那部分(我也说不清楚,呵呵)。ReadLine的能力范围只是读一行,不能读指定行。
Write和WriteLine的用法类似,不过Open的时候需要“OpenTextFile(~.txt,2,”其中1表只读、2表写、8表追加;true为不存在则创建,默认为false。
若想既写又读,那么必须在要进行具体操作前把模式(即1、2、8)先定好,一种操作对应一个模式,否则脚本就会报错。
Last edited by Billunique on 2007-6-15 at 07:50 PM ]
Try using the following code in the VB editor to roughly understand some things about file operations:
Set fs = CreateObject("scripting.filesystemobject")
'Set ff = fs.GetFile("d:\bak\11.txt")
'MsgBox ff
'i = ff.Attributes
'MsgBox i
Set fo = fs.OpenTextFile("d:\bak\11.txt")
'MsgBox fo
v = fo.Read(5)
MsgBox v
line1 = fo.ReadLine
line2 = fo.ReadLine
MsgBox line2
con = fo.ReadAll
MsgBox con
'The content of the 11.txt file can be like this:
cndos.1111 aaa
22222
What is to be explained is that the Read operation after OpenTextFile seems to be "cutting" the text; the above read first, and then only can read the part after "cutting" plus the part within its "capability range" (I can't explain it clearly, heh heh). The capability range of ReadLine is only to read one line, and cannot read a specified line.
The usage of Write and WriteLine is similar, but when opening, it needs "OpenTextFile(~.txt, 2, ", where 1 means read-only, 2 means write, 8 means append; true means create if it doesn't exist, and the default is false.
If you want to both write and read, then you must set the mode (that is, 1, 2, 8) first before performing specific operations. One operation corresponds to one mode, otherwise the script will report an error.
Last edited by Billunique on 2007-6-15 at 07:50 PM ]
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-6-15 19:29 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 52 楼』:
使用 LLM 解释/回答一下
运用数组
Variable arrays are just groups of variables that can be accessed using an index number. This is especially useful if your script needs to look up information stored in variables.
Variable arrays always need to be declared so that VBScript knows how much storage space it should reserve. You can declare variable arrays using Dim or ReDim.
Dim initializes a variable array of fixed size. You need to specify the number of elements the array should hold, and you cannot expand or shrink the array afterwards.
Using Dim, you need to specify the number of entries as a constant or absolute number. You are not allowed to use a variable to feed the size of Dim. ReDim will also accept variables.
大致说的就是ReDim比Dim好,可以随时改变数组的大小,那我们就用ReDim好了呗:)下面是一个简单例子:
Dim myarray(5)
myarray(0)="Unknown"
myarray(1)="Removable"
myarray(2)="Fixed"
myarray(3)="Remote"
myarray(4)="CD-ROM"
myarray(5)="RAM-Drive"
'find out the type of drives
Set fs = CreateObject("scripting.filesystemobject")
'get all drives:
Set drives = fs.Drives
' Drives属性:返回一个Drives集合,包含了本机上所有可用的Drive对象
For Each drive In drives
letter = drive.DriveLetter
kind = myarray(drive.DriveType)
list = list & "Drive " & letter & " is of type "& kind & vbCr
Next
' DriveLetter属性:返回盘符
' DriveType属性:返回一个数值,指示驱动器类型,事实上系统的定义和该例上面的定义是一致的。
MsgBox list
Last edited by Billunique on 2007-6-18 at 11:56 AM ]
Using Arrays
Variable arrays are just groups of variables that can be accessed using an index number. This is especially useful if your script needs to look up information stored in variables.
Variable arrays always need to be declared so that VBScript knows how much storage space it should reserve. You can declare variable arrays using Dim or ReDim.
Dim initializes a variable array of fixed size. You need to specify the number of elements the array should hold, and you cannot expand or shrink the array afterwards.
Using Dim, you need to specify the number of entries as a constant or absolute number. You are not allowed to use a variable to feed the size of Dim. ReDim will also accept variables.
It generally says that ReDim is better than Dim because it can change the size of the array at any time, so let's just use ReDim. Here's a simple example:
Dim myarray(5)
myarray(0)="Unknown"
myarray(1)="Removable"
myarray(2)="Fixed"
myarray(3)="Remote"
myarray(4)="CD-ROM"
myarray(5)="RAM-Drive"
'find out the type of drives
Set fs = CreateObject("scripting.filesystemobject")
'get all drives:
Set drives = fs.Drives
' The Drives property: returns a Drives collection containing all available Drive objects on the local machine
For Each drive In drives
letter = drive.DriveLetter
kind = myarray(drive.DriveType)
list = list & "Drive " & letter & " is of type " & kind & vbCr
Next
' The DriveLetter property: returns the drive letter
' The DriveType property: returns a number indicating the drive type, in fact, the system's definition is consistent with the definition above in this example.
MsgBox list
Last edited by Billunique on 2007-6-18 at 11:56 AM ]
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-6-18 11:49 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 53 楼』:
使用 LLM 解释/回答一下
Split和Join
其实用Split可以简化上面的代码。
MyArray="unknown;Removable;Fixed;Remote;CD-ROM;RAM-Drive"
MyArray=Split(MyArray,";")
.......
Split其实就是用分隔符将一段字符串“弄”成数组。
而Join就是把数组里的各个元素“弄”成字符串。比如:
Myarray(0)="This "
Myarray(1)="is "
Myarray(2)="Billunique"
MyString=Join(Myarray)
'Then MyString="This is Billunique"
### Split and Join
Actually, Split can simplify the above code.
MyArray="unknown;Removable;Fixed;Remote;CD-ROM;RAM-Drive"
MyArray=Split(MyArray,";")
.......
Split is actually using a delimiter to turn a string into an array.
And Join is to turn each element in the array into a string. For example:
Myarray(0)="This "
Myarray(1)="is "
Myarray(2)="Billunique"
MyString=Join(Myarray)
'Then MyString="This is Billunique"
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-6-18 18:51 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 54 楼』:
使用 LLM 解释/回答一下
三月没来了,实在惭愧啊,又一次被方向迷失了......
I haven't been here for three months. I'm really ashamed. I've been lost again...
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-9-17 19:14 |
|
|
gne3
高级用户
    DOS学徒
积分 526
发帖 252
注册 2007-2-12
状态 离线
|
『第 55 楼』:
使用 LLM 解释/回答一下
哈哈,你的第二帖对我有启发。谢谢
Haha, your second post has inspired me. Thanks
|
|
2008-1-11 20:04 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 56 楼』:
使用 LLM 解释/回答一下
过来打个招呼,我最爱的论坛之一!!好久不见~
Come and say hello, one of my favorite forums!! Long time no see~
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2008-8-18 11:13 |
|
|
a574616737
初级用户
 
积分 28
发帖 13
注册 2008-8-24
状态 离线
|
『第 57 楼』:
使用 LLM 解释/回答一下
想楼住学习,等有上大学有时间时,也来这里写写学习笔记
Want to learn from the building owner. When I have time after going to college, I will also come here to write study notes.
|
|
2008-8-25 10:07 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 58 楼』:
使用 LLM 解释/回答一下
呱呱,露个脸,吐个泡泡
Gua gua, show your face, blow a bubble
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2010-5-12 14:24 |
|
|
zzz19760225
超级版主
        
积分 3673
发帖 2020
注册 2016-2-1
状态 离线
|
|
2016-2-9 21:21 |
|
|
zzz19760225
超级版主
        
积分 3673
发帖 2020
注册 2016-2-1
状态 离线
|
|
2017-12-4 13:48 |
|