练习题:

1、输入3个数,输出其中最大的那个值。

Option Explicit
Dim intA,intB,intC
intA=CInt(InputBox("请输入a:"))
intB=CInt(InputBox("请输入b:"))
intC=CInt(InputBox("请输入c:"))
If intA>intB And intA>intC Then
MsgBox "最大值是:"&intA
ElseIf intB>intC Then
MsgBox "最大值是:"&intB
Else
MsgBox "最大值是:"&intC
End If

2、判断输入的字符类型。

Dim a,b,c
a=InputBox("请输入一个字符:")
b=Asc(a)
If b>= And b<= Then
c=
ElseIf b>= And b<= Then
c=
ElseIf b>= And b<= Then
c=
Else
c=
End if Select Case c
Case
MsgBox "输入为数字:"&a
Case
MsgBox "输入为大写字母:"&a
Case
MsgBox "输入为小写字母:"&a
Case
MsgBox "输入为其它符号:"&a
End Select

3、输入一组数字,倒序输出。

Dim a()
For i= To
a(i)=InputBox("请输入第"&i+&"数字:")
Next
MsgBox "你输入的数字倒序输出为:"&a()&","&a()&","&a()&","&a()&","&a()

4、用VBS实现冒泡排序,输入10个数,按从小到大或从大到小的顺序排列。

Option Explicit  
Dim i,j,usernum(),tempnum
For i= To
usernum(i)=CInt(InputBox("请输入第"&i+&"个数"))
Next
For i= To
For j= To -i Step
If usernum(j)>usernum(j+) Then
tempnum=usernum(j)
usernum(j)=usernum(j+)
usernum(j+)=tempnum
End If
Next
Next
For i= To
MsgBox(usernum(i))
Next
'方法二
Dim a()
For i= To
a(i)=cint(InputBox("请输入第"&i&"数字:"))
Next
Function change(x,y)
If x>y Then
tem=x
x=y
y=tem
End If
End Function
For i= To
For j= To -i
change a(j),a(j+)
next
Next
MsgBox a()&","&a()&","&a()&","&a()&","&a()&","&a()&","&a()&","&a()&","&a()&","&a()

5、用VBS实现用户名和密码的输入验证,先输入用户名再输入密码:用户名必须是4~10位的字符,否则提示用户名为空、少于4位或多于10位。密码必须是Mercury(不区分大小写),如果输入为空则提示用户输入密码,如果连续三次未输入正确密码则提示用户重新登录,然后退出。

Dim strUsername,strPassword
Do
strUsername=CStr(InputBox("please input your UserName!","Input Name"))
If Len(strUsername)< or Len(strUsername)> Then
MsgBox "用户名必须是4-10位字符!请重新输入!",,"用户名输入不正确!"
Else
Exit Do
End If
Loop x=
Do
strPassword=CStr(InputBox("please input the password!","Input password"))
strPassword=LCase(strPassword)
If strPassword="mercury" Then
MsgBox "用户"&strUsername&"登陆成功!",,"登陆成功!"
Exit Do
Else
MsgBox "密码不正确!",,"密码不正确!"
x=x+
If x= Then
MsgBox "请重新登陆!",,"请重新登陆!"
Exit do
End If
End If
Loop

6、计算两个数求余的结果,要求:计算出错时输出错误。

Option Explicit
On Error Resume Next Function getmod(a,b)
getmod=a Mod b
End Function Dim c,ua,ub
ua=CInt(InputBox("请输入一个数"))
ub=CInt(InputBox("请再输入一个数"))
c=getmod(ua,ub)
If Err Then '可以自主产生错误 Err.Raise 6
MsgBox Err.Number &"---"& Err.Description
Err.Clear
Else
MsgBox c
End If

7、随机数。

Dim strInput,arrg
strIput=InputBox("请输入5个词语,用,分开!")
arrg=Split(strIput,",")
For Each element In arrg
Randomize '初始化随机生成器,后面的值5也可以省略而是用系统的种子
MsgBox arrg(Int(*Rnd)) '随机输出数组中的元素值
Next

8、写日志到文本文件中。

Function Writelog(str)
Const ForReading=,ForWriting=,ForAppending=
Dim fso,fil,msg
' 创建一个文件系统对象(File System Object)
Set fso = CreateObject("Scripting.FileSystemObject")
' 创建一个文件对象,通过fso对象来打开指定的文件
Set fil = fso.OpenTextFile("C:\log.txt",ForAppending)
fil.WriteLine now &" "&str
' 关闭这个文件
fil.Close
' 释放这个文件对象
Set fil = Nothing
' 释放这个文件系统对象
Set fso = Nothing
End Function Writelog "hello lxl"

9、读文本文档.txt文件并显示出来。

Option Explicit
Const ForReading=,ForWriting=,ForAppending=
Dim fso,fil,msg
' 创建一个文件系统对象(File System Object)
Set fso = CreateObject("Scripting.FileSystemObject")
' 创建一个文件对象,通过fso对象来打开指定的文件
Set fil = fso.OpenTextFile("C:\f.txt",ForReading)
' 读取文件内容
' MsgBox fil.ReadAll ' 一次性全部读取
' 判断是否到了文件的最后面
Do While Not fil.AtEndOfLine '注意和AtEndOfLine的区别
' 只要没到最后,就读取一行,同时把游标向下移动一行
msg = msg & vbNewLine & fil.ReadLine
Loop
MsgBox msg
' 关闭这个文件
fil.Close
' 释放这个文件对象
Set fil = Nothing
' 释放这个文件系统对象
Set fso = Nothing

4、读取数据库查询的结果

Dim Cnn,Rst,strCnn,Msg, Sqlstr
strCnn="Provider=MSDASQL.1;Persist Security Info=False;Data Source=calc" '数据源字符串
Set Cnn=CreateObject("ADODB.Connection")
Cnn.Open strCnn
Set Rst=CreateObject("ADODB.RecordSet")
Sqlstr="select * from calc order by TestNumber1 asc"
Rst.Open Sqlstr,Cnn
Rst.MoveFirst
Do While Not Rst.EOF
Msg=Msg&vbTab&Rst.Fields("TestNumber1")&vbTab&Rst.Fields("TestNumber2")&vbTab&Rst.Fields("TestResult")&vbNewLine
Rst.MoveNext
Loop
Rst.Close
Cnn.Close
Set Rst=Nothing
Set Cnn=Nothing
MsgBox Msg

5、更新数据库中的数据

Dim Cnn,strCnn,Cmd,Sqlstr
strCnn=" Provider=MSDASQL.1;Persist Security Info=False;Data Source=calc "
Set Cnn=CreateObject("ADODB.Connection")
Cnn.Open strCnn
'Set Rst=CreateObject("ADODB.RecordSet")
Set Cmd=CreateObject("ADODB.Command")
Cmd.ActiveConnection = Cnn
Sqlstr="update calc set TestNumber1= 78901 where TestNumber1= 78900" Cmd.CommandText = Sqlstr
Cmd.Execute
Cnn.Close
Set Rst=Nothing
Set Cnn=Nothing

6、插入数据到数据库中

Sub inputaccess(tn1,tn2,tr)
Dim Cnn,strCnn,Cmd,Sqlstr
strCnn="Provider=MSDASQL.1;Persist Security Info=False;Data Source=lxl"
Set Cnn=CreateObject("ADODB.Connection")
Cnn.Open strCnn
Set Cmd=CreateObject("ADODB.Command")
Cmd.ActiveConnection = Cnn
Sqlstr="insert into calc(TestNumber1,TestNumber2,TestResult) values("&tn1&","&tn2&",'"&tr&"')"
Cmd.CommandText = Sqlstr
Cmd.Execute
Cnn.Close
Set Rst=Nothing
Set Cnn=Nothing
End Sub
inputaccess ,,"yezhaohui"

VBS练习题的更多相关文章

  1. vbs习题

    练习题: 1.输入3个数,输出其中最大的那个值. Option Explicit Dim intA,intB,intC intA=CInt(InputBox("请输入a:")) i ...

  2. Linux基础练习题(二)

    Linux基础练习题(二) 1.复制/etc/skel目录为/home/tuer1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限. [root@www ~]# cp -r ...

  3. shell 脚本之 shell 练习题汇总

    整理了一些 shell 相关的练习题,记录到这里. 1. 请按照这样的日期格式 xxxx-xx-xx 每日生成一个文件,例如:今天生成的文件为 2013-09-23.log, 并且把磁盘的使用情况写到 ...

  4. C#调用vbs脚本实现Windows版Siri

    最近新加入,把自己一些有意思的小东西分享给大家,我是一个学生,代码写得少,哪里不规范,希望大家见谅. 这事我封装好的一个类,可以直接实例化对象之后,调用"对象.Talk()"方法, ...

  5. MySQL练习题

    MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号和平均成 ...

  6. MySQL练习题参考答案

    MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...

  7. mysql练习题-查询同时参加计算机和英语考试的学生的信息-遁地龙卷风

    (-1)写在前面 文章参考http://blog.sina.com.cn/willcaty. 针对其中的一道练习题想出两种其他的答案,希望网友给出更多回答. (0) 基础数据 student表 +-- ...

  8. 在WinCC中通过VBS操作SQL Server2005

    在项目中需要在一定条件满足时,保存一些数据到数据库中,并可根据条件查询.考虑到WinCC6.2以后采用的就是SQL Server2005数据库,所以直接利用该数据库即可,通过SQL Server Ma ...

  9. 使用vbs脚本进行批量编码转换

    使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看分析在Linux系统下开发的项目代码,我们知道Linux系统中文本文件默认编码格式是UTF-8,而Windows中文系统中的默 ...

随机推荐

  1. Hadoop 2.0安装以及不停集群加datanode

    Hadoop2.0是对Hadoop1.0全面升级,针对Namenode单点问题,提出了HDFS Federation,让多个NameNode分管不同的目录进而实现访问隔离和横向扩展.诞生了通用的计算框 ...

  2. ccc 模拟重力

    x=x+v v=v+gr cc.Class({ extends: cc.Component, properties: { velocity:{ default:null }, grivatity:{ ...

  3. Activiti工作流引擎参考资料

    Activiti工作流引擎使用 工作流-Activiti核心API介绍 传智播客Activiti工作流视频教程(企业开发实例讲解) 工作流引擎Activiti演示项目 http://www.kafei ...

  4. Codeforces Round #253 (Div. 2) D. Andrey and Problem

    关于证明可以参考题解http://codeforces.com/blog/entry/12739 就是将概率从大到小排序然后,然后从大到小计算概率 #include <iostream> ...

  5. ACM: HDU 2563 统计问题-DFS+打表

    HDU 2563 统计问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u HDU 2 ...

  6. 【HDU】3516 Tree Construction

    http://acm.hdu.edu.cn/showproblem.php?pid=3516 题意:平面n个点且满足xi<xj, yi>yj, i<j.xi,yi均为整数.求一棵树边 ...

  7. get,post 区别,HTTP通信

    GET & POST GET      1.GET 的本质是"得"      2.从服务器拿数据,效率更高 3.从数学的角度来讲,GET 的结果是"幂等" ...

  8. 使用C语言在windows下一口气打开一批网页

    作者:郝峰波 mail : fengbohello@qq.com 本博客地址:http://www.cnblogs.com/fengbohello/p/4374450.html 1.核心函数说明 核心 ...

  9. iOS 最全面试题

    HTTP/1.0 在HTTP/1.0版本中,并没有官方的标准来规定Keep-Alive如何工作,因此实际上它是被附加到HTTP/1.0协议上,如果客户端浏览器支持Keep-Alive,那么就在HTTP ...

  10. [CareerCup] 18.5 Shortest Distance between Two Words 两单词间的最短距离

    18.5 You have a large text file containing words. Given any two words, find the shortest distance (i ...