按键精灵1级2级3级4级5级6级认证答案2 下载本文

Function 查询(文本路径, 编号) Dim fso, myfile, i, flag, tempp flag = 1

Set fso = CreateObject(\If fso.FileExists(文本路径) Then

Set myfile = fso.openTextFile(文本路径, 1, false) Else flag = 0 End If

For i = 1 To 编号 - 1

If Not myfile.AtEndOfLine Then myfile.SkipLine

tempp = myfile.Line End If Next

If flag = 1 Then

If Not myfile.AtEndOfLine Then 查询 = myfile.ReadLine Else

查询 = \编号不存在!\End If

myfile.close Else

查询 = \文件不存在!\End If

Set fso = Nothing End Function

Function 搜索(文本路径, 关键字) Dim ForReading, ForWriting

ForReading = 1 : ForWriting = 2 : 搜索 = \Dim objFSO, objFile, strLine, strNewFile

Set objFSO = CreateObject(\Set objFile = objFSO.OpenTextFile(文本路径, ForReading) Do Until objFile.AtEndOfStream strLine = objFile.Readline

If Instr(1, strLine, 关键字) > 0 Then 搜索 = strLine & \& 搜索 TracePrint \搜索=\& 搜索

strNewFile = strNewFile & strLine & vbcrlf Loop

objFile.Close

Set objFile = objFSO.OpenTextFile(文本路径, ForWriting) objFile.Write strNewFile objFile.Close

Set objFSO = Nothing End Function

Sub 删除(文本路径, 编号)

Dim ForReading ,ForWriting ForReading = 1 ForWriting = 2

Dim objFSO,objFile,strLine,strNewFile

Set objFSO = CreateObject(\Set objFile = objFSO.OpenTextFile(文本路径,ForReading) Do Until objFile.AtEndOfStream strLine = objFile.Readline

If CInt(编号) = objFile.Line - 1 or CInt(编号) = 0 Then strNewFile = strNewFile Else

strNewFile = strNewFile & strLine & vbcrlf End If Loop

objFile.Close

Set objFile = objFSO.OpenTextFile(文本路径,ForWriting) objFile.Write strNewFile objFile.Close

Set objFSO = Nothing End Sub

Sub 增加(文本路径, 文本内容) Dim ForReading ,ForWriting

ForReading = 1 : ForWriting = 2

Dim objFSO, objFile, strLine, strNewFile

Set objFSO = CreateObject(\Set objFile = objFSO.OpenTextFile(文本路径, ForReading) Do Until objFile.AtEndOfStream strLine = objFile.Readline

strNewFile = strNewFile & strLine & vbcrlf Loop

TracePrint objFile.Line

strNewFile = strNewFile & objFile.Line & \& 文本内容 & vbcrlf objFile.Close

Set objFile = objFSO.OpenTextFile(文本路径, ForWriting) objFile.Write strNewFile objFile.Close

Set objFSO = Nothing End Sub EndScript

'六、3、动态监控文本内容,当文本内容增加时(文本内容不会减少)自动输出增加的内容到所有标题包含\接收\关键字的文本(批量消息发送器),请写出代码

'六、4、写一个子程序,可以改变窗口内的某个子窗口的大小为特定值,子窗口大小随顶层窗口变化而比例变化(提示:改变顶层窗口,判断子窗口大小),请写出代码

'六、5、利用函数输出杨辉三角,需要的参数为杨辉三角的行数,请写出代码 '六、杨辉三角百度说明:http://baike.uu456.com/view/7804.htm

'五:1、写出三种计算颜色相似度的算法,函数返回值为相似度.请写出代码 MsgBox 颜色相似度1(\\颜色相似度1\MsgBox 颜色相似度2(\\颜色相似度2\MsgBox 颜色相似度3(\\颜色相似度3\Function 颜色相似度1(当前颜色, 对比颜色)

Call Plugin.Color.ColorToRGB(当前颜色, R1, G1, B1) Call Plugin.Color.ColorToRGB(对比颜色, R2, G2, B2)

颜色相似度1 = 1 - round((abs((R1 - R2) / 255) + abs((G1 - G2) / 255) + abs((B1 - B2) / 255)) / 3, 3)

End Function

Function 颜色相似度2(当前颜色, 对比颜色)

Call Plugin.Color.ColorToRGB(当前颜色, R1, G1, B1) Call Plugin.Color.ColorToRGB(对比颜色, R2, G2, B2)

颜色相似度2 = 1 - round((abs(R1 - R2) + abs(G1 - G2) + abs(B1 - B2)) / 255 / 3, 3) End Function

Function 颜色相似度3(当前颜色, 对比颜色)

Call Plugin.Color.ColorToRGB(当前颜色, R1, G1, B1) Call Plugin.Color.ColorToRGB(对比颜色, R2, G2, B2)

颜色相似度3 = 1 - round((abs(R1 / 255 - R2 / 255) + abs(G1 / 255 - G2 / 255) + abs(B1 / 255 - B2 / 255)) / 3, 3)

End Function

'五:2、(前台)区域范围为(100,150)到(200,300)内的所有点是否均为\是则弹出对话框\没有其他颜色\否则弹出第一个点的颜色值并退出程序. 请写出代码

Dim x, y, RtColor x = 100 : y = 150 Do While y < 301 For x = 100 To 200

RtColor = Plugin.Color.GetPixelColor(x, y, 0) If RtColor <> \Then Exit do Next : y = y + 1 Loop

If RtColor <> \Then

MessageBox X & \, \& Y & \坐标点颜色为:\& RtColor Else

MessageBox \没有其他颜色\End If EndScript

'五:3、写一个函数,要求:返回一个数值范围内所有偶数之和。参数1、参数2:整数型,数字 提示:For循环与VBS命令函数应用。

TracePrint 求偶数之和(1, 61) TracePrint 求偶数之和(3, 19) TracePrint 求偶数之和(0, 83) TracePrint 求偶数之和(2, 1) EndScript

Function 求偶数之和(参数1, 参数2)

Dim 差, i

求偶数之和 = 0 : 差 = Abs(参数1 - 参数2) If 差 mod 2 = 1 Then : 差 = 差 - 1 : End If For i = 0 To 差 / 2 - 1

求偶数之和 = 求偶数之和 + 差 - i * 2

'TracePrint \& i & \求偶数之和=\& 求偶数之和 & \差=\& 差 - i * 2

Next

End Function

'五:4、遍历字符串\取出所有小写字母及数字,并按照与原来相反的顺序拼接

成新的字符串,请写出代码 Dim Str, k, XiaoXie, 新字符串 Str = \For k = 1 To Len(Str)

XiaoXie = LCase(mid(Str, k, 1)) If XiaoXie = mid(Str, k, 1) Then 新字符串 = XiaoXie & 新字符串 End If Next

TracePrint 新字符串

'五:5、写一个脚本,要求:在画图工具中画一个渐变放大的多边形(大于4边)漩涡效果图。 提示:For循环的应用。

Call 画多边漩涡(400, 200, 50, 7) //五边形 EndScript

Sub 画多边漩涡(x, y, r, n) //x 圆心横坐标 y 圆心纵坐标 //r 半径 n 多边形的边数 Const PI = 3.1415926 Dim x1, y1 //起点坐标 dim x2, y2 //下一个点坐标 x1 = x y1 = y - r Dim t t = PI

For i = 1 To 30 If i > 1 Then MoveTo x1, y1 Delay 20 LeftUp 1 End If

MoveTo x1, y1 Delay 20 LeftDown 1

t = t - pi * 2 / n x2 = x + int(r * sin(t))