您现在的位置:学赛首页 > 计算机等级考试 > 复习资料 > 正文
计算机二级VB编程应用:用Winrar压缩文件[2]
http://www.educity.cn 作者:不详 来源:考试大 2007年4月16日 发表评论 进入社区

  三、一个例子

  在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

[1]  [2]