帮助你将按键脚本源代码,按照论坛Discuz!语言进行重新格式编排,主要是对语法进行着色,使脚本代码看起来更好看。
1.演示了如何调用系统打开文件对话框,以及如何根据用户的选择,进行下一步的操作(如打开文件等)。
2.演示了在“按键精灵”中,VBScript语言与按键精灵语言是怎么紧密结合在一起工作的(在使用中,你如果不注意,根本体会不到是在使用VBS语言)。
3.演示了如何从头至尾,读取文件中的所有行,以及同时打开两个文件,从一个文件中读、往另外一个文件写操作。
4.演示如何从文件名获取文件的路径。
5.演示如何读写INI文件中脚本配置。
运行环境:分辨率:1440x900 色深:32位 操作系统:Windows XP 按键精灵版本:7.00.3730
@ahfxman, 风烈焰。 9月//变量定义
DimobjDialog,fso
DimfSourceName,fTargetname
DimsLine,s,stemp1,stemp2
DimLineLenOld,LineLenNew
DimMyArray,i1,i,s1
DimDirPath
//变量初始化
ForReading=1:ForWriting=2:ForAppending=8
remColor="Green"
explainColor="Blue"
IniFileName="c:\path.ini"
//==============主程序===============
Gosub读取路径
Gosub打开文件
Rem结束
MessageBox"程序结束,谢谢使用"
EndScript
//==============子程序===============
Sub打开文件
SetobjDialog=CreateObject("monDialog")
objDialog.Filter="脚本文件|*.txt"
objDialog.InitialDir=DirPath
intResult=objDialog.ShowOpen
IfintResult<>0
Gosub保存路径
Gosub改名
Gosub格式编辑
Else
Goto结束
EndIf
Return打开文件
Sub保存路径
sTemp2=objDialog.FileName
MyArray=Split(sTemp2,"\",-1,1)
i=UBound(MyArray)
i1=1
s1=MyArray(0)
Whilei1
s1=s1&"\"&MyArray(i1)
i1=i1+1
EndWhile
s1=s1&"\"
PluginFile.WriteINI("setup","路径",s1,IniFileName)
Return保存路径
Sub读取路径
DirPath="c:\"
PluginDirPath=File.ReadINI("setup","路径",IniFileName)
Return读取路径
Sub改名
fSourceName=objDialog.FileName
fTargetName=Replace(fSourceName,".txt",".ini")
Return改名
Sub格式编辑
Setfso=CreateObject("Scripting.FileSystemObject")
SetfSource=fso.OpenTextFile(fSourceName,ForReading,True)
SetfTarget=fso.OpenTextFile(fTargetName,ForWriting,True)
WhilefSource.AtEndOfStream<>true
sLine=fSource.ReadLine()
lineLenOld=Len(sLine)
s=Trim(sLine)
lineLenNew=Len(s)
sTemp1=Left(s,2)
sTemp2=Right(s,Len(s)-2)
Ifs="[General]"
s="[color="&explainColor&"]"&s
ElseIfs="[Script]"
s="[/color][color="&explainColor&"]"&s&"[/color]"
ElseIfsTemp1="//"
s="[color="&remColor&"]"&s&"[/color]"
Else
EndIf
s=Space(lineLenOld-lineLenNew)&s
fTarget.WriteLine(s)
EndWhile
fSource.Close
fTarget.Close
VBSCallRunApp(fTargetName)
Return格式编辑
文件下载
解压密码:
Tags:按键精灵
来源:三叶资源网,欢迎分享,公众号:iisanye,(三叶资源网⑤群:21414575)