VB编程常用代码大全

合集下载

vb代码大全,考试都考

vb代码大全,考试都考

1. 编写程序,单击窗体时在窗体上打印出如下所示的图形。

*****************************************Private Sub Command1_Click()Dim i As Integer, j As Integerj = j + 1For i = -4 To 4Print Tab(20 + Abs(i));For j = 1 To 9 -Abs(2 * i)Print "*";Next jPrintNext iEnd Sub2. 编写程序,输出下列三角形:(要求用循环做,非循环不给分)GFGEFGDEFGCDEFGBCDEFGABCDEFGPrivate Sub Command1_Click()Dim a As String, b As String, i As Integer, j As IntegerDim s As Integer, t As Integer, k As Integer, m As Integera = "ABCDEFG"k = Len(a)For i = 1 To kPrint Right(a, i)Next iEnd Sub3.******* ****** ****** ****** *******Private Sub Form_Load()For i = 4 To 1 Step -1Print Tab(10 - i);For j = 1 To 2 * i - 1Print "*";Next Print Spc(2);For k = 1 To 9 - 2 * iPrint "*";NextPrintNextEnd Sub4. 1222333335555555888888888Private Sub Command1_Click()f1 = 0f2 = 1For i = 1 To 5Print Tab(20 - 3 * i);For j = 1 To 2 * i - 1f3 = f1 + f2Print f3;Nextf1 = f2f2 = f3PrintNextEnd Sub5. 1123123451234567For i = 1 To 4Print Tab(20 - 3 * i);For t = 1 To 2 * i - 1Print t;NextNext6 .1111111222223334n = InputBox("n")x = 0For i = n To 1 Step -1Print Tab(20 - 3 * i);x = x + 1For j = 1 To 2 * i - 1Print x;NextNext7 . 1121123211234321For i = 1 To 4Print Tab(15 - 3 * i);For j = 1 To iPrint j;NextFor k = i - 1 To 1 Step -1Print k;NextPrintNextFor j = 1 To 2 * i - 1Print s;Next8.计算并输出下面数前n项的和1-1/2+1/3-1/4+…..1/n=n = InputBox("输入数字:")For i = 1 To nj = 1 / iIf i Mod 2 = 0 Thens = s - jElses = s + jEnd IfNextPrint s9. 求公式:e=1+1/1!+1/2!+1/3!+……+1/n! 直到n=20时的e值。

VB代码总结

VB代码总结

VB总结1、阶乘和Private Function fact(n As Integer) As Long Dim i As Integerfact = 1For i = 1 To nfact = fact * iNext iEnd FunctionPrivate Sub Command1_Click()Dim a As Integer, sum As LongDim i As Integern = Val(Text1.Text)For i = 1 To nsum = sum + fact(i)Next iText2.Text = sumEnd Sub2、逆序Private Sub reverse(s As String, s1 As String) Dim i As IntegerFor i = 1 To Len(s)s1 = Mid(s, i, 1) & s1Next iEnd SubPrivate Sub Command1_Click()Dim m As String, m1 As Stringm = Text1.TextCall reverse(m, m1)Text2.Text = m1End Sub3、最小公倍数Private Sub Command1_Click()Dim s1 As Integer, s2 As Integers1 = Val(Text1.Text)s2 = Val(Text2.Text)Text3.Text = s1 * s2 / gcd(s1, s2)End SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As Integer Dim r As IntegerDor = m Mod nm = nn = rLoop Until r = 0gcd = mEnd Function4、找出100-200之间的升序数Private Function ascnum(n As Integer) As BooleanDim i As IntegerFor i = 2 To Len(CStr(n))If Mid(n, i, 1) <=Mid(n, i - 1, 1) ThenExit FunctionEnd IfNext iascnum = TrueEnd FunctionPrivate Sub Command1_Click()Dim i As IntegerFor i = 100 To 200If ascnum(i) Then List1.AddItem iNext iEnd Sub5、找出100-300素数及求各个位数之和也是素数Private Function nsum(n As Integer) As IntegerDim i As IntegerFor i = 1 To Len(CStr(n))nsum = nsum + Mid(n, i, 1)Next iEnd FunctionPrivate Function prime(n As Integer) As BooleanDim i As Integerprime = FalseFor i = 2 To Sqr(n)If n Mod i = 0 Then Exit FunctionNext iprime = TrueEnd FunctionPrivate Sub Command1_Click()Dim i As IntegerFor i = 100 To 300If prime(i) And prime(nsum(i)) ThenList1.AddItem iEnd IfNext iEnd Sub6、质因子Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)Text2.Text = n & "=" & zyz(n)End SubPrivate Function zyz(ByVal n As Integer) As String Dim k As Integerzyz = " "k = 2Do Until n = 1If n Mod k = o Thenzyz = zyz & k & "*"n = n / kElsek = k + 1End IfLoopzyz = Left(zyz, Len(zyz) - 1)End Function因子和Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)Text2.Text = yz(n)End SubPrivate Function yz(ByVal n As Integer) As Integer Dim i As IntegerFor i = 1 To nIf n Mod i = o Then yz = yz + iNext iEnd Function7、生成由个位数组成的四行五列的数组Option Base 1 Private Sub Command1_Click()Dim a(4, 5) As Integer, i As Integer, j As IntegerFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 10)Print a(i, j);Next jPrintNext iEnd Sub8、由个位数组成的五行五列的矩阵,并显示下面一个三角形Option Base 1Dim a(5, 5) As Integer Private Sub Command1_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd Sub Private Sub Command2_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To iPicture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub9、由个位数组成的五行五列的矩阵,并沿主对角线对折Option Base 1Dim a(5, 5) As Integer Private Sub Command1_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd Sub Private Sub Command2_Click()Dim i As Integer, j As Integer, tmp As IntegerFor i = 1 To 5For j = 1 To itmp = a(i, j)a(i, j) = a(j, i)a(j, i) = tmpNext jNext iFor i = 1 To 5For j = 1 To 5Picture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub10、生成12个二位数,并打印出最小元素和最大元素Option Base 1 Private Sub Command1_Click()Dim com(12) As Integer, i As IntegerDim max As Integer, min As Integermin = 100For i = 1 To 12com(i) = 10+Int(Rnd * 90)Print com(i);If com(i) > max Then max = com(i)If com(i) < min Then min = com(i)Next iPrintPrint "最大元素:" & maxPrint "最小元素:" & minEnd Sub11、实验教程P56Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 90) + 10Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, sum As IntegerFor i = 1 To 5sum = 0For j = 1 To 5sum = sum + a(i, j)Next jText1.Text = Text1.Text & sum & vbCrLf Next iEnd SubPrivate Sub Command3_Click()Dim i As Integer, j As Integer, sum As IntegerFor j = 1 To 5sum = 0For i = 1 To 5sum = sum + a(i, j)Next iText2.Text = Text2.Text & sum & " "Next jEnd SubPrivate Sub Command4_Click()Dim i As Integer, j As Integer, sum As IntegerFor i = 1 To 5For j = 1 To 5If i = j Or i + j = 6 Then sum = sum + a(i, j) Next jNext iText3.Text = sumEnd Sub12、求任意一维数组元素之和Private Function tim(a() As Integer)Dim t As Double, i As Integert = 0For i = LBound(a) To UBound(a)t = t + a(i)Next itim = tEnd Function13、排序(升序)Option Base 1Private Sub Command1_Click()Dim i As Integer, b(10) As IntegerFor i = 1 To 10b(i) = 10 + Int(Rnd * 90)Print b(i)Next iPrintCall ascsort(b)For i = 1 To 10Print b(i)Next iEnd Sub冒泡法Private Sub ascsort(a() As Integer)Dim i As Integer, j As Integer, temp As IntegerFor i = 1 To UBound(a) - 1For j = 1 To UBound(a) - iIf a(j) > a(j + 1) Thentemp = a(j)a(j) = a(j + 1)a(j + 1) = tempEnd IfNext jNext iEnd Sub选择法Private Sub ascsort(a() As Integer)Dim i As Integer, j As Integer, temp As IntegerFor i = 1 To UBound(a)For j = i + 1 To UBound(a)If a(i) > a(j) Thentemp = a(i)a(i) = a(j)a(j) = tempEnd IfNext jNext iEnd Sub直接排序Private Sub ascsort(a() As Integer)Dim i As Integer, j As Integer, temp As Integer, pointer As Integer For i = 1 To UBound(a) - 1pointer = iFor j = i + 1 To UBound(a)If a(pointer) > a(j) Then pointer = jNext jIf i <> pointer Thentemp = a(i)a(i) = a(pointer)a(pointer) = tempEnd IfNext iEnd Sub1、I递归法阶乘:Private Function Fact(ByVal n As Integer) As LongDim i As IntegerFact = 1For i = 1 To nFact = Fact * iNext iEnd FunctionPrivate Sub Command1_Click()Dim a As Integera = Text1.TextText2.Text = Fact(a)End SubII非递归法阶乘Private Function Fact(ByVal n As Integer) As Long If n = 0 Or n = 1 ThenFact = 1ElseFact = n * Fact(n - 1)End IfEnd FunctionPrivate Sub Command1_Click()Dim a As Integera = Text1.TextText2.Text = Fact(a)End Sub2、最大公约数:Private Sub Command1_Click()Dim x As Integer, y As Integer, z As Integerx = Val(Text1.Text)y = Val(Text2.Text)z = gcd(x, y)Text3.Text = zEnd SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As IntegerDim r As IntegerDor = m Mod nm = nn = rLoop Until r = 0gcd = mEnd Function3、最小公倍数:Private Sub Command1_Click()Dim x As Integer, y As Integer, z As Integerx = Val(Text1.Text)y = Val(Text2.Text)z = gcd(x, y)Text3.Text = zEnd SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As IntegerDim r As Integer, s As Integers = m * nDor = m Mod nm = nn = rLoop Until r = 0gcd = s / mEnd Function4、逆序:Private Sub Command1_Click()Dim i As Integer, st As Stringi = Val(Text1.Text)Call prime(i, st)Text2.Text = stEnd SubPrivate Sub prime(ByVal n As Integer, st As String) Dim i As Integer, s As Strings = CStr(n)For i = 1 To Len(s)st = Mid(s, i, 1) & stNext iEnd Sub5、素数(判断素数):Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)If ptm(n) ThenText2.Text = "该数是素数"ElseText2.Text = "该数不是素数"End IfEnd SubPrivate Function ptm(n As Integer) As Boolean Dim i As IntegerFor i = 2 To Sqr(n)If n Mod i = 0 Then Exit ForNext iIf i > Sqr(n) Thenptm = TrueEnd IfEnd Function6、素数(求素数):Private Sub Command1_Click()Dim i As IntegerFor i = 100 To 999If Prime(i) = True Then List1.AddItem iNext iEnd SubPrivate Function Prime(n As Integer) As Boolean Dim i As IntegerFor i = 2 To n - 1If n Mod i = 0 Then Exit FunctionNext iPrime = TrueEnd Function7、数组求和Option ExplicitOption Base 1Dim a () As IntegerPrivate Sub Command1_Click()Dim i As Integer ,n As IntegerN=Val (inputBox(“请输入n的值:”))ReDim a(n)For i=1 To NA(i) =Int (Rnd*90)+10Picture 1.Print a(i)Next iEnd SubPrivate Sub total (a() As Integer,sum As Integer) Dim i As IntegerFor i =1 To UBound(a)sum=sum+a(i)Next iEnd SubPrivate Sub Command 2_Click()Dim k As Integercall total (a,k)Text1.Text=CStr(k)End Sub8、升(降)序Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)If ascnum(n) ThenText2.Text = "该数是升(降)序数"ElseText2.Text = "该数不是升(降)序数"End IfEnd SubPrivate Function ascnum(n As Integer) As Boolean Dim s As Integer, i As Integers = CStr(n)For i = 1 To Len(s) - 1If Mid(s, i, 1) >(<)= Mid(s, i + 1, 1) Then Exit For Next iIf i > Len(s) - 1 Then ascnum = TrueEnd Function9、因子和:Option ExplicitPrivate Sub Command1_Click()Dim n As Integern = Val (Text1)Text2 = cstr (yzh(n))End SubPrivate Function yzh (ByVal n As Integer) As Integer Dim i As IntegerFor i = 1 To nIf n mod i = 0 Then yzh=yzh+iNext iEnd Function。

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。

VB编程代码

VB编程代码

VB编程代码1、输出较大数:Private Sub Command1_Click()Dim a As Double a = Val(Text1.Text) If Val(Text1.Text) <Val(Text2.Text) Then a = Val(Text2.Text)Label3.Caption = "较大的数为:" + Str(a)End Sub2、商品打折:Private Sub Command1_Click()Dim x As Single Dim y As Single x = Val(Text1.Text) If x < 1000 Then y = xElseIf x < 2000 Then y = 0.95 * xElseIf x < 3000 Then y = 0.9 * xElseIf x < 5000 Then y = 0.85 * xElsey = 0.8 * xEnd IfEnd IfEnd IfEnd IfLabel2.Caption = "折扣后价格为:" + Str(y)End Sub3、划分成绩等级:Private Sub Command1_Click()Dim x As Single Dim y As String x = Val(Text1.Text) If x < 80 Then If x < 70 ThenIf x < 60 Theny = "<不及格>"Elsey = "<及格>"End IfElsey = "<中等>"End IfElseIf x < 90 Then y = "<良好>"Elsey = "<优秀>"End IfLabel2.Caption = "该成绩等级为:" + y End Sub4、求N~:Private Sub Command1_Click()Dim s As SingleDim i, n As Integer s = 1n = Val(Text1.Text) For i = 1 To ns = s * iNextLabel2.Caption = Str(n) + "的阶乘为:" + Str(s)End Sub5、随机数组:Private Sub Command1_Click()Dim k, a, b, cArray(100) As IntegerFor k = 1 To 100cArray(k) = Int(Rnd() * 100)Print cArray(k);If k Mod 10 = o Then PrintEnd IfNextb = Val(Text1.Text) a = oFor k = 1 To 100If b = cArray(k) Then a = kExit ForEnd IfNextIf a = 0 ThenLabel2.Caption = "对不起,数组中没有该数~"ElseLabel2.Caption = "您找的是数组中的第" + Str(a) + "个数。

vb编程代码大全

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编程程序代码

VB编程程序代码

VB编程程序代码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 For Next 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 Then MsgBox (y & "年是闰年")ElseMsgBox (y & "年是平年")End IfEnd Sub5、已知x,y,z 3个变量中存放了3个不同的数,比较它们的大小并进行调整,使得x<y<z。

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 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常用程序代码

vb常用程序代码

1、求半径为r的圆的面积,要求用户从键盘输入半r。

程序代码:Private Sub Form_click()Const PI = 3.14Dim r%Dim s!r = InputBox("请输入半径r的值:", "求圆的面积") s = PI * r * rForm1.FontSize = 16Print "半径是" + Str(r) + "的圆的面积是" + Str(s) End Sub2、输入三个整数,从小到大顺序输出。

程序代码:Private Sub Form_click()a = InputBox("a")b = InputBox("b")c = InputBox("c")Print "排序前:"; a, b, cIf a > b Then t = a: a = b: b = tIf a > c Then t = a: a = c: c = tIf b > c Then t = b: b = c: c = tPrint "排序后:"; a, b, cEnd Sub3、输入三个整数,从大到小顺序输出。

程序代码:Private Sub Form_click()a = InputBox("a")b = InputBox("b")c = InputBox("c")Print "排序前:"; a, b, cIf a <b Then t = a: a = b: b = tIf a < c Then t = a: a = c: c = tIf b < c Then t = b: b = c: c = tPrint "排序后:"; a, b, cEnd Sub4、输入x的值,输出对应的值。

VB常用代码大全

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编程常用代码大全讲解学习

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编程代码大全

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编程代码大全

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编程代码大全

v b编程代码大全(总5页) --本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--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^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编程常用代码大全(精品)

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常用代码大全

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代码大全

最为常用的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常用代码大全

移动无标题栏的窗体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 nP osition As Long, ByVal wFlags As Long) 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.hwnd , 0)c = GetMenuItemCount(hwndMenu) DeleteMenu hwndMenu, c - 1, MF_BYPO SITION c = GetMenuItemCount(hwndMenu) DeleteMenu hwndMenu, c - 1, MF_BYPO SITIONEnd Sub启动控制面板大全'打开控制面板Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL", 9)'辅助选项属性-键盘Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL access.cpl,,1", 9)'辅助选项属性-声音Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL access.cpl,,2", 9)'辅助选项属性-显示Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL access.cpl,,3", 9)'辅助选项属性-鼠标Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL access.cpl,,4", 9)'辅助选项属性-常规Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL access.cpl,,5", 9)'添加/删除程序属性-安装/卸载Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Appwiz.cpl,,1", 9)'添加/删除程序属性-Windows安装程序Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Appwiz.cpl,,2", 9)'添加/删除程序属性-启动盘Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Appwiz.cpl,,3", 9)'显示属性-背景Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL desk.cpl,,0", 9)'显示属性-屏幕保护程序Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL desk.cpl,,1", 9)'显示属性-外观Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL desk.cpl,,2", 9)'显示属性-设置Call Shell("rundll32.exe shell32.dll,ControVB常用代码l_RunDLL desk.cpl,,3", 9)'Internet 属性-常规Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Inetcpl.cpl,,0", 9)'Internet 属性-安全Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Inetcpl.cpl,,1", 9)'Internet 属性-内容Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Inetcpl.cpl,,2", 9)'Internet 属性-连接Call Shell("rundll32.exe shell32.dll,Contro l_RunDLL Inetcpl.cpl,,3", 9)********************************* **********怎样关闭一个程序你可以使用API函数FindWindow和PostMessage来寻找一个窗口并且关闭它。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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>0
int(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.2
log(num): 取以e为底的对数 num>0
exp(n): 取e的n次幂通常用 num^n
sin(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;反之 False
Cdate(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],..) 引用函数
欢迎您的下载,
资料仅供参考!
致力为企业和个人提供合同协议,策划案计划书,学习资料等等
打造全网一站式需求。

相关文档
最新文档