a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 77|回复: 0

[Visual Basic] 2012年计算机等级考试二级VB考点及习题(8)

[复制链接]
发表于 2012-7-31 22:10:12 | 显示全部楼层 |阅读模式
2012年计算机等级考试二级VB考点及习题(8)8 x) R. }8 U- n6 i
(2)static变量, F9 y4 V. f. D3 I" v9 k
  Private Sub Command1_Click()
+ u7 Y. J- ^1 s# w: O, _  Dim n As Integer, i As Integer; m% J& T7 i+ d2 _3 E
  n = 20 A7 H9 r: ~6 D# [5 ?
  For i = 9 To 1 Step -1
; e, `5 w7 Y' ]4 |6 c- H) Z) [8 h  Call sub2(i, n)
1 ^7 l$ P- i( }1 k7 s8 f# J  Print i, n" s( O$ z" y* S% `3 C2 [
  Next i
7 H: u4 j7 a6 r# s# ^# o  End Sub
' z& F9 |9 k8 d1 z) l' v  Private Sub sub2(x As Integer, y As Integer)
1 J3 y, W, M2 ~3 H7 L9 i6 m  Static n As Integer  d1 {0 l6 g2 p) x
  Dim i As Integer- _; u/ b( J! w1 Z# f8 Z
  For i = 3 To 1 Step -1
+ o; O: c2 B! s/ }* d. M5 a5 h0 a  n = n + x
& d% E5 j, B# C& _* O  x = x - 10 L( ^+ }/ j- N4 d  t) M
  Next i8 j1 O/ y! B7 ~9 s
  y = y + n/ D; |0 x' {+ ?: Z2 @: n* O4 @
  End Sub1 c( X" J- U/ v
  (3) 递归  m% T* K6 J5 s# i8 Q
  Private Sub Command1_Click()
) a1 ]  V+ ^+ n" ]  l7 D  Dim a As Integer; r+ C* E- h8 ]: K5 z+ ]0 }/ Z
  a = 2. C: E' u# Y4 Z! w; a
  Call sub1(a)
$ ~0 R, G$ D% T8 p+ y* e  `5 x1 [  End Sub
4 A: `/ [- z% O% h6 G  Private Sub sub1(x As Integer)1 a' a8 G8 C$ L: j5 _
  x = x * 2 + 1. |" h  ^2 [* E9 f. d0 G- b& i5 }
  If x < 10 Then
# M) G$ A5 h% p8 \& R  h  Call sub1(x)
2 |) q, _  Q  F: Q7 o- K  End If
9 J/ i7 P$ Q/ x0 a  x = x * 2 + 1
( q" Q6 N) T+ F# f  Print x. z" h( Q1 {! e5 A) O& H
  End Sub
9 N* M/ y$ S9 b) X- x+ t  (4)递归
6 `1 N0 c2 F" P4 J( E# V% ^  Private Sub test(x As Integer)7 q. O! i. Q% A( i+ W2 l
  Dim i As Integer
5 w' _" N" W+ ^3 }* `  If x  0 Then
6 `0 {( ^, K4 x1 ~& \  Call test(x - 1)( G. _4 j6 L' n6 O8 f5 |0 w8 p
  For i = 1 To x2 \! B5 E$ q& X) h. q: {
  Print x;$ j- m8 N2 q- D% O8 g) ?9 W
  Next i0 z$ t% o& j. \
  Print1 P- S2 g0 q4 e9 ]
  End If6 N1 i, q" e. ^. {$ w+ Y9 P+ l: O
  End Sub
) ^7 {8 I* }+ J3 I: v  Private Sub Form_Click()/ `8 a) [. u8 J$ |1 p: `* U
  test 3
7 n0 y) R1 I- Z! [  End Sub" e. A( c5 g1 |3 U# Y9 I7 U
  (5)同名变量
. C2 L+ R+ O" P+ S9 x$ E& i- q7 J  Dim y As Integer
* Q2 \- n* \1 U  Private Sub Form_Click()
3 J, z( y; J2 g8 k# i  Dim x As Integer,y as integer
) C: r2 v3 o1 Y% m  V  x=1 : y=13 N# I' w& N! d; c2 n
  Print "x1=";x, "y1=";y
/ c: U: K; R- i* i% Z8 M1 L  Test
9 C' ]3 j/ R$ P$ w* C7 a& {$ U& ^  Print "x4=";x, "y4=";y
0 @5 f; a, T7 g; Y# G4 I9 |, i  End Sub
9 w; d' M) _8 C* L  Private Sub Test()
" R& c& ?+ n/ M' t! d5 z$ q$ f  Dim x As Integer  v7 d1 l' ?* J" _( s" r3 L  T
  Print "x2=";x, "y2=";y/ ]* Y1 U: u; m, m% k8 i0 S
  x=2 : y=3
) e1 G# j* J; D  Print "x3=";x,"y3=";y
: \- D# Y1 {3 c' r4 [  End Sub
! D& z8 w. L% f  特例:! N( ^( z. H+ E7 L4 @4 B
  1、运行程序在窗体显示的结果是:
* G, e1 L, L; c; E* d# @3 V  Private Sub Form_Click()
  ~9 r/ C/ t' r6 J- ?! f+ f4 R  Dim a As Integer, b As Integer. _- I& C( e7 f9 Y# y! X
  a = 3: b = 4% d# N/ |1 ~- I4 H
  Call sub1(a, a)
9 [. k/ u8 g2 w6 w/ S4 P  Print a, b
- ~9 E& Z' B( W! J3 a; c  Call sub1(b, b)! z& P& Z& \$ s! v3 r( D4 n
  Print a, b
5 g, ^5 b5 f5 @8 E0 V) n9 X  End Sub( h! R5 m% e$ w' H* Z8 ~* n$ j6 K
  Private Sub sub1(x As Integer, y As Integer)
% Q* t% n1 \- ~! x6 e* ^  x = x + 23 w' q" _- z! P" s: w  w8 U
  y = x + y+ B# j$ ^' n. S; d# P! g
  End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-4 02:33 , Processed in 0.220933 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表