一、shell函数
shell函数是vb中的内部函数,它负责执行一个可执行文件,返回一个variant(double),如果成功的话,代表这个程序的进程id,若不成功,则会返回0。
shell的语法:shell(pathname[,windowstyle])。
pathname 为必需参数。类型为string,它指出了要执行的程序名,以及任何需要的参数或命令行变量,也可以包括路径名。
windowstyle为可选参数。integer类型,指定在程序运行时窗口的样式。windowstyle有以下这些值。
常量 值 描述
vbhide 0 窗口被隐藏,且焦点会移到隐式窗口。
vbnormalfocus 1 窗口具有焦点,且会还原到它原来的大小和位置。
vbminimizedfocus 2 窗口会以一个具有焦点的图标来显示(缺省值)。
vbmaximizedfocus 3 窗口是一个具有焦点的化窗口。
vbnormalnofocus 4 窗口会被还原到最近使用的大小和位置,而当前活动的窗口仍然保持活动。
vbminimizednofocus 6 窗口会以一个图标来显示,而当前活动的窗口仍然保持活动。
二、关于winrar的用法
主要介绍以下如何在winrar中用命令行来压缩和解压缩文件。
压缩:winrar a [-switches] [files] [@file lists]
例如你想把try.mdb压缩到c盘下,可以winrar a c:/try.rar c:/try.mdb
解压缩:如果带目录解压缩
winrar x [-switches] [files] [@file lists] [destionation folder/]
如果在当前目录解压缩,即解压缩时不写目录名
winrar e [-switches] [files] [@file lists] [destionation folder/]
例如你想把try.rar解压缩到c盘下,可以winrar x c:/try.rar c:/try.mdb
三、一个例子
在vb中新建一个工程,在form1中添加两个按钮command1、command2和command3,把他们的caption属性分别设为'压缩文件'、'解压缩文件'和'传递文件'。按command1时把文件try.mdb压缩成try.rar。
private sub command1_click()
dim rarexe as string winrar执行文件的位置
dim source as string 压缩前的原始文件
dim target as string 压缩后的目标文件
dim filestring as string shell指令中的字符串
dim result as long
rarexe='c:/program files/winrar/winrar'
source='c:/try.mdb'
target='c:/try.rar'
filestring = rarexe & ' a ' & target & ' ' & source
result = shell(filestring, vbhide)
end sub
解压的过程类似,按command2可以把try.rar解压生成 try.mdb。在执行了上面的压缩过程后,可以删除文件try.mdb,来解压缩重新生成try.mdb。
private sub command2_click()
dim rarexe as string winrar执行文件的位置
dim source as string 解压缩前的原始文件
dim target as string 解压缩后的目标文件
dim filestring as string shell指令中的字符串
dim result as long
rarexe='c:/program files/winrar/winrar'
source='c:/try.rar'
target='c:/try.mdb'
filestring = rarexe & ' x ' & source & ' ' & target
result = shell(filestring, vbhide)
end sub
文件从一台计算机传输到另一台计算机前,应知道另一台计算机的名字,然后用filecopy语句就可以了。假设要把压缩后try.rar传递到计算机名为'other'的共享目录'want'下。
private sub command3_click()
dim sourcefile, destinationfile
sourcefile ='c:/try.rar ' 指定源文件名。
destinationfile = '//other/want/try.rar' 指定目的文件名。
filecopy sourcefile, destinationfile 将源文件的内容复制到目的文件中。
end sub
【VB中利用Winrar进行文件压缩】相关文章:
2025年外省高中学业水平合格性考试成绩转入江苏认定的通告公布05-15
Vb中控件的自动排列05-15
写未来的作文300字05-15
中国大地保险公司实习报告05-15
小学父爱的作文600字05-15
荷花作文600字05-15
07年4月北师大“中国古代文学史(一)”串讲(5)05-15
寓言作文300字05-15
2023年广东梅州中考成绩查询时间及查分入口[7月7日起]05-15
关于清明节的英语作文:清明节05-15
