vb代码集合
vb经典代码
1.求三角形的面积代码:Option ExplicitDim a!,b!,c!r,!,s!Private Sub Command1_Click()a = InputBox("a=", "请输入a的数值")b = InputBox("b=", "请输入b的数值")c = InputBox("c=", "请输入c的数值")If a + b > c And a + c > b And b + c > a And a > 0 And b > 0 And c > 0 Thenr = 1 / 2 * (a + b + c)s = Sqr(r * (r - a) * (r - b) * (r - c))Label1.Caption = "三角形的面积为" & sElseLabel2.Caption = "输入的数据不能构成三角形"End IfEnd Sub2.三个数排列代码:Option ExplicitDim x!, y!, z!, t!Private Sub Command1_Click()x = InputBox("输入第一个数 x")y = InputBox("输入第二个数 y")z = InputBox("输入第三个数 z")Print "排序前"; x & " " & y & " " & zIf x < y Then t = x: x = y: y = tIf y < z Thent = y: y = z: z = tIf x < y Thent = x: x = y: y = tEnd IfEnd IfPrint "排序后"; z & " " & y & " " & xEnd Sub3.计算一元二次方程的代码:Option ExplicitDim a!,b!,c!,d!,x1!,x2!Private Sub Command1_Click()a = InputBox("a=", "请输入一元二次方程的系数a")b = InputBox("b=", "请输入一元二次方程的系数b")c = InputBox("c=", "请输入一元二次方程的系数c")If a = 0 ThenPrint "因为a≠0,你输入的a=0,请重新输入系数a"End Ifd = b ^ 2 - 4 * a * cIf d >= 0 Thenx1 = (-b + Sqr(d)) / (2 * a)x2 = (-b - Sqr(d)) / (2 * a)Print "系数为" & a; b; c & "的一元二次方程的根分别为" & "x1=" & x1 & " " & "x2=" & x2ElsePrint "此方程在实数范围内无解"End IfEnd Sub4.利用Select Case语句输入年份计算属相代码:Option ExplicitPrivate Sub Command1_Click()Dim i As Integer, x As String, Y As IntegerY = InputBox("输入你的出生年份Y")i = Y Mod 12 Select Case i Case Is = 0 x = "猴" Case Is = 1 x = "鸡" Case Is = 2 x = "狗" Case Is = 3 x = "猪" Case Is = 4 x = "鼠" Case Is = 5 x = "牛" Case Is = 6 x = "虎" Case Is = 7 x = "兔" Case Is = 8 x = "龙" Case Is = 9 x = "蛇" Case Is = 10 x = "马" Case Is = 11 x = "羊" End SelectPrint xEnd Sub5.闰年两种判断方法的代码; 方法一:Option ExplicitDim y As IntegerPrivate Sub Command1_Click()y = InputBox("y=", "输入年份")If y Mod 4 = 0 ThenIf y Mod 100 = 0 ThenIf y Mod 400 = 0 ThenPrint "这年为闰年"ElsePrint "这年为平年"End IfElsePrint "这年为闰年"End IfElsePrint "这年为平年"End IfEnd Sub方法二:Private Sub Command2_Click()y = InputBox("y=", "输入年份")If y Mod 4 = 0 And y Mod 100 = 0 Then Print "这年为闰年"ElseIf y Mod 400 = 0 ThenPrint "这年为闰年"ElsePrint "这年为平年"End IfEnd Sub法一:Option ExplicitDim x!,y!Private Sub Command1_Click()x = InputBox("x=", "输入x的值")If x <> 0 ThenIf x >= 1 Or x <= -1 Theny = (1 + Sin(x) * Sin(x) - Sqr(x ^ 2 - 1)) / x Print "y="; Format(y, "0.0000")ElsePrint "所输入的x不在定义域"End IfElsePrint "除数不能为零"End IfEnd Sub法二:Private Sub Command2_Click()x = InputBox("x=", "输入x的值")Select Case xCase Is = 0Print "除数不能为零"Case Is >= 1, Is <= -1y = (1 + Sin(x) * Sin(x) - Sqr(x ^ 2 - 1)) / x Print "y="; Format(y, "0.0000")Case Is <> 0, Is < 1, Is > -1Print "所输入的x不在定义域"End SelectEnd Sub法三:Private Sub Command3_Click()x = InputBox("x=", "输入x的值")If x >= 1 Theny = (1 + Sin(x) * Sin(x) - Sqr(x ^ 2 - 1)) / x Print "y="; Format(y, "0.0000")ElseIf x < 1 And x > 0 ThenPrint "所输入的x不在定义域"ElseIf x = 0 ThenPrint "除数不能为零"ElseIf x >= -1 And x < 0 ThenPrint "所输入的x不在定义域"ElseIf x <= -1 Theny = (1 + Sin(x) * Sin(x) - Sqr(x ^ 2 - 1)) / x Print "y="; Format(y, "0.0000")End IfEnd Sub流程图:伪代码:step1:输入x的值;step2:判断x是否为零;step3:若x=0,输出“除数不能为零”;若x不为零,则继续判断x的绝对值是否大于1;step4:若x的绝对值是否大于1,输出y的值;否则x的值不在函数的定义域里,结束。
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编程代码大全
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 中用于存储相同类型的多个元素。
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 jNext iEnd SubPrivate 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 - SumEnd 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 nb = a1 + a2Text1.SelText = b & " "a1 = a2a2 = bNext iEnd SubPrivate Sub Command2_Click() EndEnd Sub5.各位数之和Private Sub Command1_Click() Dim i As StringDim 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 Sub。
vb常用代码大全
移动无标题栏的窗体dim m(borderstyle=none)ouseX as integerdim mouseY as integerdim moveX as integerdim moveY as integerdim down as booleanform_mousedown: 'mousedown事件down=truemouseX=xmouseY=yform_mouseup: 'mouseup事件down=falseform_mousemoveif down=true thenmoveX=me。
left—mouseX+XmoveY=me.top-mouseY+Yme.move moveX,moveYend if*******************************************闪烁控件比如要闪烁一个label(标签)添加一个时钟控件间隔请根据实际需要设置 enabled属性设为true代码为:label1.visible=not label1.visible *******************************************禁止使用 Alt+F4 关闭窗口Private Declare Function DeleteMenu Lib ”user32"(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Lon g) As LongPrivate Declare Function GetMenuItemC ount Lib ”user32” (ByVal hMenu As Long) As LongPrivate Const MF_BYPOSITION = &H400&Private Sub Form_Load()Dim hwndMenu As LongDim c As LonghwndMenu = GetSystemMenu(Me。
VB常用代码大全
VB³£ÓôúÂë´óÈ«.txtÈÃÈËÏëÄî¶øËÀ£¬ÊÇıɱµÄÖÁ¸ß¾³½ç£¬¾ÍÁ¬·¨Ò½Ò²¼ø¶¨²»³öËÀÒò¡£¡£¡£¡£¡£¡£#define __LLF_VB_GUI__#include "vb.h"//Sub Output( ByRef( msg As String ) ) { //why can't replace ',' ? Sub Output( ByRef( msg , String ) ) { //must add '{' now .Call Print( msg ); //must add ';' .End_SubSub Main() {If False Or False ThenCall Output( "That's True!\n" ); //must add ';' .ElseCall Output( "That't False!\n" ); //must add ';'.End_Ifint i = 0;//For( i, 0 To 10 ) //why can't replace ',' ?For( i, 0, 10 )Print( i );NextPause();End_Sub#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#include <stdio.h>inline void Print(const char *msg){ printf(msg); }inline void Print(int i){ printf( "%i\n", i); }inline void Pause() { getchar(); }void Main();int main (int argc, char *argv[]) { Main(); return 0; }#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE__#define __LLF_VISUAL_BASIC_LIKE_MODULE__//Ö÷º¯Êý¶¨ÒåÓëʹÓÃ#ifdef __LLF_VB_GUI__#include "winmain.h"#else#include "main.h"#endif//ÀàÐͶ¨Òå#define Integer int#define String char#define Boolean bool#define True true#define False false// Óï·¨Ïà¹Ø²¿·ÖµÄºê¶¨Òå#define If if(#define Then ){#define End_If }#define Or ||#define And &&#define Else }else{#define To #@,#define For(i, min , max) for(i=min;i<=max;i++){#define Next }//½á¹¹Ïà¹Ø²¿·ÖµÄºê¶¨Òå#define Call#define Sub void#define NewSub(x) void x {#define End_Sub }#define As ,#define ByRef(m, t) t *m#define ByVal(m, t) t m#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#include <windows.h>inline void Print(const char *msg){ MessageBox(NULL, msg, "vb", MB_OK); }inline void Print(int i){ char s[1024]; Print( itoa(i, s, 1023) ); } inline void Pause() { Print("** Pause **"); }void Main();int WINAPI WinMain(HINSTANCE, HINSTANCE,LPSTR, int) { Main(); return 0; }#endif。
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):计算字符串长度中文字符长度也计为一!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编程代码大全
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; int=100fix(num): 取整fix=99; fix=99round(num,n): 四舍五入取小数位round,3)= 中点数值四舍五入为近偶取整round,1)=log(num): 取以e 为底的num>0exp(n):取e的n次幕通常用num A nsin(num):,以为值计算(角度*Pai)/180=弧度con(num); tan(num); atn(num) 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,字符串[,次数][,比较方法]):以分割字符串为分割标志将字符串转为字符可选参数需同时选转换函数: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[, 维数]):取得数组相应维数的下界一般为0Ran dmize 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编程常用代码大全
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: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[,维数]):取得数组相应维数的下界一般为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代码大全
隐藏form1:form1.hide显示form1:form1.show--------------------------------------------------------------------------------------------- 退出程序时,弹出窗口提示是否要退出:Private Sub Form_Unload(Cancel As Integer)Dim iAnswer As IntegeriAnswer = MsgBox("真要退出吗?", vbYesNo)If iAnswer = vbNo ThenCancel = TrueElseEndEnd IfEnd Sub---------------------------------------------------------------------------------------------- 只能用任务管理器关闭程序的代码:Private Sub From_Unload(Cancel As Integer)Cancel = trueEnd Sub------------------------------------------------------------------------------------------------ 点击command1打开33IQ网:Dim strURLPrivate Sub Command1_Click()strURL = ""Shell "explorer.exe " & strURL, 1End Sub------------------------------------------------------------------------------------------------ 运行c:\1.exeshell "c:\1.exe"执行c:\1.batshell "c:\1.bat"注:只适用于大部分exe和全部bat。
VB编程常用代码大全(精品)
VB编程常用代码大全VB编程常用代码大全1.数值型函数:abs(num):返回绝对值sgn(num): num>01; 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)=100 fix(num): 取整fix(99.8)=99; fix(-99.2)=99 round(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系列代码
求阶乘
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
VB常用代码大全
VB常用代码大全#define __LLF_VB_GUI__#include "vb.h"//Sub Output( ByRef( msg As String ) ) { //why can't replace ',' ? Sub Output( ByRef( msg , String ) ) { //must add '{' now .Call Print( msg ); //must add ';' .End_SubSub Main() {If False Or False ThenCall Output( "That's True!\n" ); //must add ';' .ElseCall Output( "That't False!\n" ); //must add ';'.End_Ifint i = 0;//For( i, 0 To 10 ) //why can't replace ',' ?For( i, 0, 10 )Print( i );NextPause();End_Sub#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#includeinline void Print(const char *msg){ printf(msg); }inline void Print(int i){ printf( "%i\n", i); }inline void Pause() { getchar(); }void Main();int main (int argc, char *argv[]) { Main(); return 0; }#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE__#define __LLF_VISUAL_BASIC_LIKE_MODULE__ //主函数定义与使用#ifdef __LLF_VB_GUI__#include "winmain.h"#else#include "main.h"#endif//类型定义#define Integer int#define String char#define Boolean bool#define True true#define False false// 语法相关部分的宏定义#define If if(#define Then ){#define End_If }#define Or ||#define And &&#define Else }else{#define T o #@,#define For(i, min , max) for(i=min;i<=max;i++){ #define Next }//结构相关部分的宏定义#define Call#define Sub void#define NewSub(x) void x {#define End_Sub }#define As ,#define ByRef(m, t) t *m#define ByVal(m, t) t m#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#includeinline void Print(const char *msg){ MessageBox(NULL, msg, "vb", MB_OK); } inline void Print(int i){ char s[1024]; Print( itoa(i, s, 1023) ); } inline void Pause() { Print("** Pause **"); }void Main();int WINAPI WinMain(HINSTANCE, HINSTANCE,LPSTR, int) { Main(); return 0; } #endif。
VB代码全集
隐藏form1: h7Nb17gSLform1.hide ^Xjf@ 6Q:+~\ 5o显示form1: ~TVc9zform1.show RO*l`G}i53G"k?4o--------------------------------------------------------------------------------------------- f#a]'P|V\Dc+,'eAZ`退出程序时,弹出窗口提示是否要退出: 3#R%z=q1[24FwCPrivate Sub Form_Unload(Cancel As Integer) w5L#Hu1;Dim iAnswer As Integer CA'.k<(o}iAnswer = MsgBox("真要退出吗?", vbYesNo) ^h n3YH54SIf iAnswer = vbNo Then On`,H_Ol^Cancel = True J.^'GDDJElse |qU%\XRuEnd w4NAgCnEEnd If CQT"BEnd Sub "Xws@s(u4p>3,vPBK---------------------------------------------------------------------------------------------- 9DS3|R}K >(T%?只能用任务管理器关闭程序的代码: i.ncUFM8`Private Sub From_Unload(Cancel As Integer) NO.ihCancel = true ?,|b6m,u/End Sub SSm(b\31cZLm`mT------------------------------------------------------------------------------------------------ c?e"7"#Ei\<Ywb}点击command1打开33IQ网: X-y9`(|tj.M8j5YKDim strURL ?0\Zz4e7d/EQUPrivate Sub Command1_Click() 9E=@97<strURL = "" nagc6;Shell "explorer.exe " & strURL, 1 77|t9~p9End Sub 3 lQfC!-+ 4@vT^------------------------------------------------------------------------------------------------ icxTon7BGcGu--tY运行c:\1.exe .h ;P 'shell "c:\1.exe" V57A_gvj{n执行c:\1.bat _muh3| Sshell "c:\1.bat" L+ URz2(8s L2j1kZ注:只适用于大部分exe和全部bat。
vb常用代码大全
#define __LLF_VB_GUI__#include "vb.h"//Sub Output( ByRef( msg As String ) ) { //why can't replace ',' ? Sub Output( ByRef( msg , String ) ) { //must add '{' now .Call Print( msg ); //must add ';' .End_SubSub Main() {If False Or False ThenCall Output( "That's True!\n" ); //must add ';' .ElseCall Output( "That't False!\n" ); //must add ';'.End_Ifint i = 0;//For( i, 0 To 10 ) //why can't replace ',' ?For( i, 0, 10 )Print( i );NextPause();End_Sub#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#include <stdio.h>inline void Print(const char *msg){ printf(msg); }inline void Print(int i){ printf( "%i\n", i); }inline void Pause() { getchar(); }void Main();int main (int argc, char *argv[]) { Main(); return 0; }#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE__#define __LLF_VISUAL_BASIC_LIKE_MODULE__//Ö÷º¯Êý¶¨ÒåÓëʹÓÃ#ifdef __LLF_VB_GUI__#include "winmain.h"#else#include "main.h"#endif//ÀàÐͶ¨Òå#define Integer int#define String char#define Boolean bool#define True true#define False false// Óï·¨Ïà¹Ø²¿·ÖµÄºê¶¨Òå#define If if(#define Then ){#define End_If }#define Or ||#define And &&#define Else }else{#define To #@,#define For(i, min , max) for(i=min;i<=max;i++){#define Next }//½á¹¹Ïà¹Ø²¿·ÖµÄºê¶¨Òå#define Call#define Sub void#define NewSub(x) void x {#define End_Sub }#define As ,#define ByRef(m, t) t *m#define ByVal(m, t) t m#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#include <windows.h>inline void Print(const char *msg){ MessageBox(NULL, msg, "vb", MB_OK); }inline void Print(int i){ char s[1024]; Print( itoa(i, s, 1023) ); } inline void Pause() { Print("** Pause **"); }void Main();int WINAPI WinMain(HINSTANCE, HINSTANCE,LPSTR, int) { Main(); return 0; }#endif--------下面红色部分是赠送的工作总结,不需要的朋友可以编辑删除!谢谢行政管理干部个人总结20XX年上半年,在公司的正确领导下,在各科室部门的大力支持下,我按照公司的工作部署和工作要求,严格执行公司的工作方针,围绕中心,突出重点,狠抓落实,注重实效,在自身工作岗位上认真履行职责,做好各项行政管理工作,较好地完成了工作任务,取得了一定的成绩。
VB编程常用代码大全讲解学习
VB编程常用代码大全讲解学习V B编程常用代码大全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:ss。
VB代码集
关闭指定的程序要做到像Task Manager 一样,可以关闭指定的程序,方法如下:在声明区中放入以下声明:(16位改成win31 API)Declare Function FindWindow Lib “user32″ Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As LongDeclare Function PostMessage Lib “user32″ Alias“PostMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Const WM_CLOSE = &H10以下之范例示范如何关闭一个视窗标题(Caption) 为【小算盘】的程序:Dim winHwnd As LongDim RetVal As LongwinHwnd = FindWindow(vbNullString, “小算盘”)Debug.Print winHwndIf winHwnd <> 0 ThenRetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)If RetVal = 0 ThenMsgBox “Error posting message.”End IfElseMsgBox “并未开启小算盘程序.”End If////////////////////////////////////////////////////////////////////////////////////如何隐藏及再显示鼠标很简单,只用到了一个ShowCursor API,参数也很简单,只有一个bShow,设定值如下:True:显示鼠标/ False:隐藏鼠标Declare Function ShowCursor Lib “user32″ Alias “ShowCursor” (ByVal bShow As Long) As Long////////////////////////////////////////////////////////////////////////////////////如何从您的应程序中结束Windows 重开机?很多软件在Setup 完之后都会自动关机重开机,以便让某些设定值可以生效,其实这个功能很简单,只要几行指令就可以做到了!关键就是要使用ExitWindowsEx 这个API,这个API 只有二个参数,第一个参数是一个Flag,目的是要告诉Windows 要以什么方式关机,在下面的声明中会列出可用的Flag 常数值,至于第二个参数则是一个保留值,只要设定成0 就可以了。
VB常用代码大全
#define __LLF_VB_GUI__#include "vb.h"//Sub Output( ByRef( msg As String ) ) { //why can't replace ',' ? Sub Output( ByRef( msg , String ) ) { //must add '{' now .Call Print( msg ); //must add ';' .End_SubSub Main() {If False Or False ThenCall Output( "That's True!\n" ); //must add ';' .ElseCall Output( "That't False!\n" ); //must add ';'.End_Ifint i = 0;//For( i, 0 To 10 ) //why can't replace ',' ?For( i, 0, 10 )Print( i );NextPause();End_Sub#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#include <stdio.h>inline void Print(const char *msg){ printf(msg); }inline void Print(int i){ printf( "%i\n", i); }inline void Pause() { getchar(); }void Main();int main (int argc, char *argv[]) { Main(); return 0; }#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE__#define __LLF_VISUAL_BASIC_LIKE_MODULE__//Ö÷º¯Êý¶¨ÒåÓëʹÓÃ#ifdef __LLF_VB_GUI__#include "winmain.h"#else#include "main.h"#endif//ÀàÐͶ¨Òå#define Integer int#define String char#define Boolean bool#define True true#define False false// Óï·¨Ïà¹Ø²¿·ÖµÄºê¶¨Òå#define If if(#define Then ){#define End_If }#define Or ||#define And &&#define Else }else{#define To #@,#define For(i, min , max) for(i=min;i<=max;i++){#define Next }//½á¹¹Ïà¹Ø²¿·ÖµÄºê¶¨Òå#define Call#define Sub void#define NewSub(x) void x {#define End_Sub }#define As ,#define ByRef(m, t) t *m#define ByVal(m, t) t m#endif#ifndef __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#define __LLF_VISUAL_BASIC_LIKE_MODULE_MAIN__#include <windows.h>inline void Print(const char *msg){ MessageBox(NULL, msg, "vb", MB_OK); }inline void Print(int i){ char s[1024]; Print( itoa(i, s, 1023) ); } inline void Pause() { Print("** Pause **"); }void Main();int WINAPI WinMain(HINSTANCE, HINSTANCE,LPSTR, int) { Main(); return 0; }#endif。
vb实验代码大全
vb实验代码大全实验31Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.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 SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton2.ClickDim a(10) As Integeri As Integer DimDim x As IntegerDim y As Integerx = 0y = 0For i = 1 To 10a(i) = InputBox("请输入第" & i & "个数")If i Mod 2 = 0 Thenx = x + a(i)Elsey = y + a(i)End IfNextMsgBox("下标为奇数的元素和为" & y & "下标为偶数的元素和为" & x) End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton3.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 SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton4.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) HandlesButton5.ClickEnd SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton6.ClickDim a(19) As IntegerDim 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万元以上的业务人数为" & x & ",10万元以下的业务人数为" & y)End SubSub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrivateButton7.ClickDim a(19) As IntegerDim t As IntegerDim i As IntegerDim j As IntegerDim x As StringDim y As Stringx = ""y = ""For i = 0 To 19a(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) HandlesButton8.ClickDim a As IntegerDim b(9) As IntegerDim s As Integeru As String DimDim 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 & ")" & 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) HandlesButton9.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 SubPrivate Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton10.ClickDim i As IntegerDim t As SingleDim s As Singlei = 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) HandlesButton11.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) HandlesButton14.ClickDim a() As IntegerDim i As Integern As Integer DimDim 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("下标为奇数的元素和为" & y & "下标为偶数的元素和为" & x)End SubPrivate Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton15.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) HandlesButton16.ClickDim n As IntegerDim i As Integerj As Integer DimDim 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 Then i = 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 & vbCrLfNextMsgBox(s)End SubEnd Class实验30Public 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", "输入数据Y", , 500, 500)b = InputBox("输入B", "输入数据Y", , 500, 500)c = InputBox("输入C", "输入数据Y", , 500, 500)x1 = -b + Math.Sqrt(b ^ 2 - 4 * a * c) / 2 / a2 = -b - Math.Sqrt(b ^ 2 - 4 * a * c) / 2 / a xMsgBox("x1=" & Format(x1, "###.###") & " x2=" & Format(x2,"###.###"))End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickDim x As IntegerDim y As IntegerDim z As Singlex = 5y = 9z = (x ^ 3 + x * y + y ^ 3) / (2 * x * y)MsgBox("(x ^ 3 + x * y + y ^ 3) / (2 * x * y)=" & z)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 SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickDim x As SingleDim y As Singlex = InputBox("输入x")y = 0.231 * x + 1.36MsgBox("0.231 * x + 1.36=" & y)End SubPrivate 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 ClassPublic 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 SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton2.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 > x Thenx = cElseIf c < y Theny = cIf EndEnd IfMsgBox("最大数" & x & " 最小数" & y)End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton3.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 SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton4.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 & "等级为" & y)End SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton5.ClickDim x As Single, y As Singlex = InputBox("请输入x")Case x SelectCase Is <= -1y = x - 1Case Is <= 2y = 2 * xCase Is <= 10y = x * (x + 2)Case Elsey = 0End SelectMsgBox("y=" & y)End SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton6.ClickDim a As String, b As String, c As StringDim x1 As Single, x2 As Single, x As Singlea = InputBox("输入A", "输入数据Y", , 500, 500)b = InputBox("输入B", "输入数据Y", , 500, 500)c = InputBox("输入C", "输入数据Y", , 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 SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.ClickDim x As Single, y As Singlex = InputBox("请输入x")If x <= -1 Theny = x - 1ElseIf x <= 2 Theny = 2 * xElseIf x <= 10 Theny = x * (x + 2)End IfMsgBox("y=" & y)End SubEnd Class实验32Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim n As Integern = InputBox("请输入需求阶乘之和的任意整数n")If n Mod 2 = 0 ThenMsgBox("偶数序列" & Str(n) & " 的阶乘之和:" & Str(factorial(n))) ElseMsgBox("请输入偶数")End IfEnd SubPublic Function factorial(ByVal x) As IntegerDim s As IntegerDim t As IntegerDim i As IntegerDim j As Integers = 0For i = 1 To x Step 2t = 1For j = 1 To it = t * jNexts = s + tNextReturn sEnd FunctionPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton2.ClickDim r As SingleDim h As Singler = InputBox("请输入半径:")h = InputBox("请输入高度:")Formula(r, h)End SubPublic Sub Formula(ByVal r As Single, ByVal h As Single)Dim x As SingleDim y As SingleDim z As Singlex = Math.PI * r ^ 2y = 2 * Math.PI * rz = Math.PI * r ^ 2 * hMsgBox("圆面积:" & x & ",圆周长:" & y & ",圆柱体积:" & z)End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton3.ClickDim s As Strings = InputBox("请输入一个字符串")MsgBox("" & Inverse(s))End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton4.ClickDim m As IntegerDim n As IntegerDim s As Integerm = InputBox("请输入一个数m")n = InputBox("请输入一个数n")s = cmn(m, n)MsgBox("该组合数为" & s)End Subcmn(ByVal m As Integer, ByVal n As Integer) As Integer Public FunctionIf n = 0 ThenReturn 1ElseIf n = 1 ThenReturn mElseIf n > m / 2 ThenReturn cmn(m, m - n)ElseReturn cmn(m - 1, n) + cmn(m - 1, n - 1)End IfEnd FunctionPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton5.ClickDim n As Integern = InputBox("请输入要计算兔子的月数:")MsgBox(n & "个月后有:" & f(n) & "个兔子。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
t = t & Str(i) & Chr(13) & Chr(10)
End If
Next i
Text1.Text = t
Label1.Caption = Str(s)
End Sub
<PIXTEL_MMI_EBOOK_2005>12 </PIXTEL_MMI_EBOOK_2005>
a(i) = Int(Rnd * 90) + 10
p = p & Str(a(i)) & ","
Next i
Text1.Text = p
End Sub
6.两数相乘,显示于文本框
3个text且属性为空 1个command
Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Private sub command1_click()
Dim I as integer,s as long,t as string
For I = 1 to 100
If I mod 3=0 then
s=s + i
text1.text=text1.text & str(i) &chr(13) & chr(10)
For x = 8 To 1 Step -1
Label2.Caption = Label2.Caption & a(x)
Next x
End Sub
别忘了设置label1,label2的caption属性为:“正序、逆序”
10.100内4倍数列表框中求和
2个label(1个属性为“100以内4的倍数”,1个为空) 1个list 1个command(caption 为 求和)
end if
next i
label2.caption=str(s)
end sub
4.任意输入10个数,求和
2个label(1个caption为“请输入十个数”,另一个为空)1个command(求和)
Private Sub Command1_Click()
s = 0
For I = 1 To 10
Private Sub Command1_Click()
Dim i As Integer, s As Long, t As String
s = 0: t = 0
For i = 1 To 100
If i Mod 4 = 0 Then
s = s + i
t = t & Str(i) & Chr(13) & Chr(10)
text1.text=text1.text & str(i) & chr(13) & chr(10)
s=s*i
next i
label1.caption="0_20之间的奇数和为:" & str(s)
end sub
(Label1~label2 text1 command1)
8.文本框中100以内7的倍数,求和
Private Sub Command1_Click()
Dim i As Integer, s As Long, t As String
s = 0: t = 0
For i = 1 To 100
If i Mod 7 = 0 Then
s = s + i
将20个数倒置
Dim a(1 To 20) As Integer
Private Sub Command1_Click()
For i = 1 To 20
a(i) = InputBox("数组的元素")
Next i
j = 20
For i = 1 To 10
t = a(i): a(i) = a(j): a(j) = t
1.求1到100的累加
s=0
For I=1 to 100 step 1
s=s+I
Next I
print “s=”;s
2.求1到20中所有奇数的乘积
private sub form_load()
dim s as integer,a as integer
s=0
for i=1 to 20 step 2
t = t & Str(i) & Chr(13) & Chr(10)
End If
Next i
Text1.Text = t
Text2.Text = Str(s)
End Sub
9.将字符放到数组中,正序、倒叙打印出来
Private Sub Command1_Click()
Dim x As Integer, a(1 To 8) As String
End Sub
7.随机数组.找最大,最小
Private Sub Command1_Click()
Dim a(1 To 8) As Integer
Dim i As Integer
For i = 1 To 8
a(i) = Int(Rnd * (100 - 1 + 1) + 1)
Next i
12,99表
Private sub form_load()
Show
Fontsize=12
Print tab(25);”九九表”
Print “*”
For I = 1 to 9
Print tab(i*6);I;
Next i
For j = 1 to 9
a(1) = "a": a(2) = "b": a(3) = "q": a(4) = "r": a(5) = "s": a(6) = "t": a(7) = "w": a(8) = "x"
For x = 1 To 8
Label1.Caption = Label1.Caption & a(x)
Next x
End If
Next i
Label1.Caption = s
Label2.Caption = Str(s)
End Sub
Private Sub Form_Load()
List1.Clear
For n = 1 To 100
If n Mod 4 = 0 Then List1.AddItem n
x = InputBox("输入数值")
s = s + x
Next I
Label2.Caption = s
End Sub
5。随机产生8个元素数组
Private Sub Command1_Click()
Dim a(1 To 8), p As String
Randomize
For i = 1 To 8
Next n
End Sub
11.10个数 排序
Private Sub Command1_Click()
Dim a(1 To 10) As Integer
For i = 1 To 10
a(i) = InputBox("输入数组元素值")
Next i
For i = 1 To 9
For j = i + 1 To 10
For i = 1 To 7
For j = i + 1 To 8
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
label1.caption=a(1)
LABEL2.caption=a(8)
End Sub
13.200以内被5整除 求和
设置:L1(200以内能被???)L2,T1(mul设为True.Scro设为2垂直),C1
Private Sub Command1_Click()
Dim i As Integer, s As Long, t As String
For i = 1 To 200
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
For i = 1 To 10
Print a(i)
Next i
<PIXTEL_MMI_EBOOK_2005>10 </PIXTEL_MMI_EBOOK_2005>
Print j;””;
For k = 1 to 9
M = j*k
Print tab(k*6);m;””;
Next k
Next j
End sub
<PIXTEL_MMI_EBOOK_2005>8 </PIXTEL_MMI_EBOOK_2005>
j = j - 1
Next i
Print i
End Sub