vb×÷Òµ¼¯ - 2014 -

End Sub

Private Sub Form_Click()

Dim s1 As String, s2 As String s1 = \ sub1 s1, s2 Print s2 End Sub

³ÌÐòÔËÐк󣬵¥»÷´°Ì壬Ôò´°ÌåÉÏÏÔʾµÄÄÚÈÝÊÇ ¡£ A£®rehcaet B£®teacher C£®therace 10. ³ÌÐòÔËÐк󣬵¥»÷ÃüÁî°´Å¥£¬Êä³ö½á¹ûΪ ¡£

Private Sub Command1_Click() Call Cop (2) Call Cop (4) End Sub

Sub Cop (a As Integer) Static x As Integer x = x + a Print x; End Sub

D£®certhea

A£®2 4 B£®2 6 C£® 3 6 D£®2 3

Èý¡¢ÔĶÁÌâ

1. ÔÚ´°ÌåÉÏ»­Ò»¸öÃüÁî°´Å¥£¬Ãû³ÆÎªCommand1,È»ºó±àдÈçϳÌÐò¡£

Function Func(ByVal x As Integer, y As Integer) y = y * x

½á¹û£º If y > 0 Then Func = x Else

Func = y End If

End Function

Private Sub Command1_Click() Dim a As Integer, b As Integer a = 3 b = 4

c = Func(a, b) Print a;b;c End Sub

2. ÒÀ´Îд³öÏÂÁгÌÐòÔËÐÐʱËĴε¥»÷ÃüÁî°´Å¥Command1ºó´°ÌåÉϵÄÊä³ö½áÊø¡£

Dim x As Integer, y As Integer

29

VBÍøÂç¿ÎÌãºinfo.zjfc.edu.cn/vbweb

Private Sub f1(a As Integer) a=a/2 End Sub

Private Sub f2(ByVal b As Integer) b=b/2 End Sub

Private Sub Command1_Click() Call f1(x) Call f2(y) Print x, y End Sub

Private Sub Form_Load() x= 64:y =64 End Sub

½á¹û£º 3. д³öÔËÐÐʱÁ½´Îµ¥»÷´°ÌåºóÆÁÄ»ÉϵÄÏÔʾ½á¹û¡£

½á¹û£º Dim x As Byte

Private Static Sub Form_Click() Dim y As Byte, z As Byte Call Init(y, z) Call OP(x, y, z) Print x, y, z End Sub

Private Sub Init(a As Byte, b As Byte) a = a + 1: b = b + 2: x = a + b End Sub

Private Sub OP(ByVal u As Byte, v As Byte)

ByRef w As Byte)

u = u + 1: v = v + u: w = u + v + w End Sub

4. ÔÚ´°ÌåÖл­Ò»¸öÃû³ÆÎªcommand1µÄÃüÁî°´Å¥£¬²¢±àдÈçϹý³Ì£º Private Sub Command1_Click() Dim a as integer Static b as integer a=5

call func(a,b) print a,b End Sub

Private Sub func(byval x As Integer, y as integer) x=x+x y=y+1 End Sub

ÔËÐÐÒÔÉϳÌÐò£¬¶þ´Îµ¥»÷command1µÃµ½µÄ½á¹ûÊÇ

½á¹û£º µÚÒ»´Îµ¥»÷ºó½á¹û£º µÚ¶þ´Îµ¥»÷ºó½á¹û£º 30 VBÍøÂç¿ÎÌãºinfo.zjfc.edu.cn/vbweb

ËÄ¡¢³ÌÐòÌî¿ÕÌâ

1£®[³ÌÐò˵Ã÷] ÓÐSummary¹ý³ÌÊÇÓÃÓÚ¼ÆËã1!+2!+...+20!£¬²¢´òÓ¡³ö¼ÆËã½á¹û£¬µ«²»ÍêÕû£¬ÇëÔÚºáÏßÉÏÌîÈë±ØÒªµÄÄÚÈÝ£¬Ê¹ÆäÍêÕû¡£nFactorº¯Êý¹ý³ÌÓÃÓÚ¼ÆËãn!¡£ ³ÌÐòÈçÏ£º

Public Function nFactor(ByVal n As Integer) As Double Dim i As Integer Dim temp As Double £¨1£©

For i = 1 To n

temp = temp * i Next i

nFactor = £¨2£© End Function

Public Sub summary() Dim sum As Double Dim i As Integer Dim n As Integer n = 20

For i = 1 To n

sum = sum + £¨3£© Next i

Form1.Print \ £¨4£© End Sub

2£®¡¾³ÌÐò˵Ã÷¡¿±à³ÌÐòÇó±í´ïʽ s=1+x+x/2!+x/3!+?+x/n!+?µÄÖµ£¬Ö±ÖÁÄ©ÏîСÓÚ10-5

Ϊֹ£¬²¢ÔÚ´°ÌåÉÏÊä³ö¡£

Private Function f( (5) ) As Single Dim i As Integer f = 1

For i = 1 To m f = f * i Next i

End Function

Private Sub Command1_Click() Dim i As Integer, s As Single x = val(InputBox(\ÊäÈëx\ i = 1: t = x

(6) Do until t < 10 ^ (-5) t= (7) (8) i=i+1 loop Pirnt s End Sub

2

3

n

31 VBÍøÂç¿ÎÌãºinfo.zjfc.edu.cn/vbweb

(5) A¡¢m As Single B¡¢n As Single

C¡¢m As Integer D¡¢n As Integer

£¨6£©A¡¢s=1 B¡¢s=0 C¡¢s=s+t D¡¢s=t £¨7£©A¡¢x^i/f(i) B¡¢x^i/f C¡¢x^(i+1)/f(i+1) D¡¢x/f

£¨8£©A¡¢s=t B¡¢s=s+t C¡¢s=s+ x^i/f(i) D¡¢s=s+ x^i/f 3£®¹ý³ÌfµÄ¹¦ÄÜÊÇ£º·µ»ØSingleÀàÐÍÊý×én¸öÔªËØµÄƽ¾ùÖµ£¬²éÕÒÊý×éÖÐ×î´óÖµ¡¢×îСֵ²¢Í¨¹ýÏàÓ¦µÄʵ²Î·µ»Øµ½µ÷Óô¦¡£¸Ã¹ý³Ì¿ÉÒÔ±»ÆäËûÄ£¿éÖеĹý³ÌËùµ÷Óá£

(9) f(a() As Single, n As Integer, (10) ) As Single Dim i As Integer

max = a(1): min=a(1) For i = 2 To n

If a(i)>max Then max=a(i) If a(i)

(12) ¡¾¹©Ñ¡ÔñµÄ´ð°¸¡¿

(9) A¡¢Function B¡¢Sub C¡¢Private Sub D¡¢Private Function (10) A¡¢max As Single,min As Single B¡¢max As Integer,min As Integer C¡¢Byval max As Single (12) A¡¢find = max

D¡¢Byval max As Single,Byval min As Single

D¡¢f=a(i)/n

(11) A¡¢f=f+a(i) B¡¢f=f+a(i)/n C¡¢f=a(i)

B¡¢End Sub C¡¢find = min D¡¢End Function

Îå¡¢ÉÏ»úµ÷ÊÔÌ⣺³ÌÐòÉè¼Æ

£±£®±àÖÆÅжÏÊÇ·ñͬʱ±»17Óë37Õû³ýµÄFunction¹ý³Ì¡£ÔÚË«»÷´°ÌåʼþÖУ¬µ÷ÓÃÕâ¸öFunction¹ý³Ì£¬ÔÚ´°ÌåÉÏÊä³ö100~10000Ö®¼äËùÓÐÄÜͬʱ±»17Óë37Õû³ýµÄÊý¡£

2£® ±àÖÆÍ¨Óú¯Êý¹ý³Ìfsum£¬ÓÃÓÚ¼ÆËã1¸öÈýλÕûÊýµÄ¸÷λÊý×ÖÖ®ºÍ¡££¨ÈçÒýÓÃfsum(132)µÄ½á¹ûÊÇ6µÈµÈ£©

3£®°´ÒªÇó±àд³ÌÐò£º

£¨1£©¶¨ÒåFunctionº¯Êý£º¼ÆËãһάÕûÐÍÊý×éËùÓÐÔªËØµÄƽ¾ùÖµ¡£

£¨2£©´Ó¼üÅÌÊäÈëÊäÈë10¸öÕûÊý±£´æÔÚÊý×éÖУ¬µ÷ÓÃFunctionº¯Êý£¬¼ÆËãÊý×éÔªËØµÄƽ¾ùÖµ£¬²¢ÔÚ´°ÌåµÄÎı¾¿òText1ÖÐÊä³ö½á¹û¡£

´úÂë±àд£º

1¡¢ 2¡¢

32

VBÍøÂç¿ÎÌãºinfo.zjfc.edu.cn/vbweb

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ìæ»»Îª@)