This presentation is the property of its rightful owner.
Sponsored Links
1 / 162

项目二 Visual Basic 程序设计基础 PowerPoint PPT Presentation


  • 49 Views
  • Uploaded on
  • Presentation posted in: General

项目二 Visual Basic 程序设计基础. 【 教学目的 】1 、掌握常用的基本数据类型 2 、掌握常量和变量的应用 3 、理解 VB 常用内部函数 4 、掌握运算符和表达式的应用 5 、掌握数组的定义和使用 6 、掌握标准函数的使用 7 、掌握过程和函数的应用 【 教学重点 】 变量和常量的定义;函数、运算符、表达式的正确使用;数组的定义和使用。 【 教学难点 】 变量的定义、数组、函数的使用。. 活动一. 2.1 数据类型. 2.2 常量与变量. 2.3 运算符和表达式. 2.4 标准函数. 2.5 基本语句.

Download Presentation

项目二 Visual Basic 程序设计基础

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Visual basic

Visual Basic

1

2

3VB

4

5

6

7


Visual basic

2.1

2.2

2.3

2.4

2.5

2.6

2.7


Visual basic

2.1

8154546.5465@

##January 15,2002##1985-10-1 9:45:00 PM# #3-6-93 13:20#

TrueFalse

abcdef

-123%123%

VariantVB

4-1234&987654&

Ee7-1.234567E6

Dd1516-1.112223334445556D-33


Visual basic

1VB

23.2345

38.6787E+8

A) 86787000 B) 867870000 C) 8678700 D) 8678700000

42.65358979335278E-006

A) 0.0000265358979335278B) 0.00000265358979335278

C) 000265358979335278D) 0.000000265358979335278


Visual basic

VBType

Type

As

As

End Type


Visual basic

Client_Record3 cltName cltPassword cltDeposit

  • Type Client_Record

  • cltName as String*16

  • cltPassword as String*8

  • cltDeposit as Currency

  • End Type

  • 1PublicTypePrivate

  • 2

  • strName As String*


Visual basic

2.2

Visual Basic6.0

1

2

2.2.1

1


Visual basic

  • (1)

  • 65535

  • (2)

  • &H&O

    • 1200 '1200

    • &H333 '333

    • &O555 '555


Visual basic

  • E

  • E1012.345E-678E30.000012 34578 00071516

(3)

FalseTrue

(4)

##2007-9-9##January 15,2002# #3-6-93 13:20#


Visual basic

VB 2345VB2345%&#@$


Visual basic

2

255 VB

Const

Const

Const [As ] =

AS Const c1 As String= ( Const day = #09/30/2003 #

Const pi! = 3.14159


Visual basic

2.2.2

1VB37

2VB255temp#

3VBcaption caption$

4

5strNameintAge


Visual basic

VB

Dim <> As <> [,<> As <> ]

Public <> As <> [,<> As <> ]

Private <> As <> [,<> As <> ]

Static <> As <> [,<> As <> ]

DimPublic Private /Static


Visual basic

VBVB3

VB

VB3(Form)(Module)(Class)

(Declaration)

Form

(General Procedure)

(Even Procedure)

(Module)


Visual basic

1

DimStatic

Dim <> As <> [,<> As <> ] Dim intX As integer (intX) Dim total As Single (total) Dim strName As String*10 (strName10) Dim stra1 As String (stra1)DimDim str1 As String, str2 As String, ff As BooleanDimAsDim str1,str2 As String, ff,var1 As Long


Visual basic

Static <> As <> [,<> As <> ] Dim Static

StaticDim0Static num As Integer

Private Sub Command1_Click()

Static x As String

Dim y As String

x = x + "a"

y = y + "b"

Print "x"; x

Print "y"; y

End Sub

Private Sub Command1_Click()

Static x As Integer

Dim y As Integer

x = x + 1

y = y + 1

Print "x"; x

Print "y"; y

End Sub


Visual basic

Private sub command1_click() Dim num1 As Integer Static ss as String

End Sub

Private sub command2_click() Dim num1 As Integer

Static ss as Integer End Sub

1

3ClickStaticxx=x+1


Visual basic

  • 2()

  • ()Form1Form2PrivateDim

  • Private <> As <> [,<> As <> ] Private x as IntegerForm1Temp.Form1TempDim temp As String

  • Module1temp


Visual basic

  • 3

  • PublicGlobal

  • Public <> As <> [,<> As <> ] Public Public Public intTemp As Integer

  • temp1Form1Form2temp -Public temp As Integer


Visual basic

4Option Explicit

VBVariant)

DimPublic

5


Visual basic

Print

Option Explicit

Dim var1 As Integer

Private var2 As Integer

Private Sub Command1_Click()

var1 = 100

var2 = 300

Print var1, var2

End Sub

Private Sub Command2_Click()

Dim var1 As Integer

var1 = 50

var2 = 200

Print var1, var2

End Sub

Private Sub Command3_Click()

var2 = 400

Print var1, var2

End Sub

Private Sub Command4_Click()

Static var4 As Integer

var4 = var4 + 1

Print var4;

End Sub

Private Sub Command5_Click()

Dim var5 As Integer

var5 = var5 + 1

Print var5;

End Sub


Visual basic

1VB

A) 4*delta B) AlphaC) 4abcD) ab

2VB

A) FilenameB) A(A+B)C) 368DD) Print


Visual basic

11Form1Form2Command1Caption 1AllM1Form1M2Form2L1Form1Command1_Click

2Form1M106ALL123Form2M2VB

3Form1Command1L13.14159Text1AllText2L1Label1M1Form1Command2Form2 4Form2Command1Text1M2Text2AllForm2M1


Visual basic

2.3

  • 2.3.1

1

2

3

4


Visual basic

1.

VB884-6


Visual basic

2.

&+4-7

123 + 456 123456 123 & 456 123456 : + , & : abcdef + 12345 abcdef & 12345 abcdef12345 123 + 456 579 123 & 456 ' " 123456 "


Visual basic

3.

TrueFalseVB-10TrueFalse4-8VB


Visual basic

True FalseNot

4.


2 3 2

2.3.2

1

2

11

2*2x2*x

3[ ]{ }

4

5a<=x<=bVB

a<=x And x<=b

3

>>>


Visual basic

1:

110 \ 2.4; 10 \ 3.6;14 \ 4

28*3+2 Mod 3 / 2

33*3>=8

4 "EFG"<>"efg" & "abc"

5Not 5=4 And 5<4*2

66>3*2 Or 7<>8 And 8=2*4

710>12+3 And True And 2>3

8Not 7>2*4 Or Not 5<>2+3 And 2 Mod 4 =0

2Ayear4100400Bax2+bx+c=0a0b2-4ac0Csexage1820(size)1.6516181.60

Dmarrigerat(age)26workingage5


Visual basic

2\/Mod*4A\B/CModD*3AB00AA*B=0ANDA<>B

BA=0ORB=0ANDA<>BCA=0ANDB<>0ORA<>0ANDB=0DA*B=0ANDA=0ORB=04ABC3AA+B>=COrA+C>=BOrB+C>=A

BNot(A+B<=COrA+C<=BOrB+C<=A)CA+B<COrA+C<BOrB+C<A)

DA+B>CAndA+C>BAndB+C>A


Visual basic

3-3Text1Text2Label1Label34Caption+

1VB(/\Mod)

555(/)(\)(Mod)5(/\Mod)


Visual basic

2.4

2.4.1

2.4.2

2.4.3

2.4.4

2.4.5

2.4.6


2 4 1

2.4.1


Int fix

IntFix

  • IntFix

  • Int(x)

  • Fix(x)

  • IntX

  • FixXInt(-3.6) Fix(-3.6) Int(3.6) Fix(3.6) -4 -3 3 3


Visual basic

  • Hex$(x)

  • Oct$(x)

  • x

  • x


Visual basic

1INT8*SQR36*10^-2*10+0.5/10


2 4 2

2.4.2


Visual basic

  • InStr()

  • N1MC1N1C2N10M0120120


Visual basic

  • Len()

  • Len() Len()

  • Left()Right()

  • Left(,n)Right(,n)

  • n

  • nLeft(,n) nRight(,n) n


Visual basic

  • Mid()

  • Mid(,n1,n2)

  • n1n2

  • n1n2

  • Ltrim()Rtrim()Trim()

  • Ltrim()Rtrim()Trim()

  • Ltrim()Rtrim()Trim()


Visual basic

  • String()

  • String(n,c)

  • n

  • cASCIIn

  • Space()

  • Space(n)

  • n

  • n


Visual basic

1Mid("ABCDEFG",2,3)

2InStr(2, "ABCDEFG", "EF")

3Right(abcdefghi,4)

4String(4,abc)

5Len(123.4)

6Ucase(Left(basic,3))


2 4 3

2.4.3

  • IsArray( )

  • IsArray()

  • IsDate( )

  • IsDate()

  • dim aa as string,bb as boolean

  • aa=10-12-2007

  • bb=IsDate(aa)

  • print bb


Visual basic

  • IsEmpty()

  • IsEmpty()

  • dim aa as string,bb as integer,cc as boolean

  • cc=IsEmpty(aa)

  • cc=IsEmpty(bb)

  • aa=kkkk

  • cc=IsEmpty(aa)

  • IsNumeric()

  • IsNumeric()

  • dim a as boolean

  • a=IsNumeric(text1.text)

  • print a


Visual basic

2.4.4

1

  • Str

  • Str(X)

  • X Long

  • X

Str(123) Str(-23.456)


Visual basic

2

  • Val

  • Val(string)

Val(-123.4)

Val( 123.4)

Val(a123.4)

Val(12-3.4)


Visual basic

Asc(a)

Asc(abc)

3ASC

  • Asc ASC

  • Asc(string)

  • string string

    4ASC

  • Chr ASCASC

  • Chr(charcode)

  • charcode Longcharcode 0 255

  • 0 31 ASCII Chr(10) Chr(13)

Chr(65)

Chr(97)


2 4 5

2.4.5


2 4 6

2.4.6

Rnd(x)

10

[]

Int(( -+1*Rnd())+

[50,100]

Int((100-50+1)*Rnd())+50

Private Sub Command1_Click()

Label1.Caption = Chr(Int((Asc("Z") - Asc("A") + 1) * Rnd() + Asc("A")))

End Sub

Private Sub Command2_Click()

Label2.Caption = Chr(Asc(Label1.Caption) + 32)

End Sub


Visual basic

1Int(-3.14159)2Fix(-3.1415926)

3Sgn(25)4Sqr(Sqr(16))

5Abs(98-100)6Str(-456.67)

7Val(16Year)8Year(05-3-20)

9WeekDay(Now)10Asc(ab)

RndA0B1C0.1234D0.00005INT100*RND1A[099]B[1100]C[0100]D[199]


Visual basic

-1*Sgn-100+Int(Rnd*100)A0B1C-1D[1037]VisualBasicAInt(Rnd(1)*27)+10BInt(Rnd(1)*28)+10CInt(Rnd(1)*27)+11DInt(Rnd(1)*28)+11Len(Str(Val(123.4)))A11B5C6D8

1 x=2732.87 y=-658.236 z=3.14159*30/180Int(x),Fix(x),Int(y),Fix(y),Hex(Int(x)),Oct(Fix(x)),Abs(y),Sin(z),Cos(z)


Visual basic


Visual basic

2.5

1VB

CAPTION caption Caption

2

VB(:)

x=10 : y=5 : z=6

32551023

4

_

Private Sub Form_MouseDown(Button As Integer, Shift As _

Integer, X As Single, Y As Single)


Visual basic

1

1[ Let ]= Let

2[ Let ][.]=

2

==

x=10 : Text1.Text=abcd : Text1.Text=Text2.Text

<>

:Caption Texttext1.text=10


Visual basic

2

VBREM<> REM <>

1Rem

2 3

Visual Basic

ADim a(10)As Integer RemVBBVBPrivate Sub Command1_Click() Ca=1:b=2:RemVB:c=3D If Shift = 6 And Button = 2 ThenPrint "BBBB" Rem VBEnd If


2 6 vb

2.6 VB

VB


Visual basic

5x+2 (x0) Y= 0 (x=0)

2.6.1

If x<>0 Then y=5*x+2Else y=0End If

VB

1IF

2Select Case


Visual basic

If

If

1If Then ()

1If Then

2If ThenEnd If

False

If

True

True Then End If


Visual basic

True

False

1

2

2If Then Else ()

If

1If Then <1> Else <2>

2If Then1 Else2 End If

If

True Then Else


Visual basic

Private Sub Command_Click() Dim x as Integer x = val(Text1.Text) If x Mod 2 =0 then MsgBox Str(x) & Else MsgBox Str(x) & Enf ifEnd Sub


Visual basic

False

1

False

2

True

False

n

True

True

1

2

n

n+1

3IfThenElseIf ()

:If 1 Then1ElseIf 2 Then2 ElseIf n Then

n

[Else n+1 ]End If

1True 12True2n


Visual basic

Text1001010

:

0~60~6

Private Sub Command1_Click()

Dim x As Integer

x = Val(Text1.Text)

If x < 0 Then

MsgBox 0"

ElseIf x < =10 Then

MsgBox 010"

Else

MsgBox "10"

End If

End Sub


Visual basic

4If

If Then ElseIf

If <1> Then

End If

If <1> Then

Else

End If

If <11> Then End If

If <11> Then End If

If If End If


Visual basic

5IIfIIf

IIfIIfTrueFalse

If Then Else

x,yTmaxTmax=IIfx > yxy

2x+3 (x<0)

Y =

4-3x (x0)

y=Iif(x<0,2*x+3,4-3*x)


Visual basic

Select Case

Select Case y Case 1,3,5,7,9print 10Case 2,4,6,8print 10Case 10 to 20print 1020Case Elseprint End Select

Select Case <>

Case <1>

<1>

[Case <2>

[<2>]]

[Case <n>

[<n>]]

[Case Else

[<n+1>]]

End Select


Visual basic

1

Case 100+a

2

Case 2,4,6,8

2468

31 To2

Case 1 To 10

1 10

4Is

Case Is > 20

> 20

1,

2

3

4,


Visual basic

strCIf :

If Ucase(strC) >="A" And Ucase (strC) <="Z" Then Print strC & "" ElseIf strC >="0" And strC <="9" Then Print strC & "" Else Print strC & "" End If

If ElseIf Select Case If...Then...Else Select Case

Select Case:

Select Case strCCase "a" To "z,"A" To "Z"Print strC & ""Case "0" To "9"Print strC & ""Case ElsePrint strC & ""End Select


Visual basic

Text1111010 Select Case

Private Sub Command1_Click()

Dim x As Integer

x = Val(Text1.Text)

Select Case x

Case Is < 1

Text2.Text = "1"

Case 1 To 10

Text2.Text = "1....10"

Case Else

Text2.Text = "10"

End Select

End Sub


Visual basic

1.x5"Result"Select Case( )

A) Select Case xCase 10 To 1 Print "Result" End Select

B) Select Case xCase Is 5, Is 5Print "Result"End Select

C) Select Case x Case Is 5, 1, 3 To 10 Print "Result" End Select

D) Select Case xCase 1, 3, Is 5Print "Result"End Select


Visual basic

3.

r =1 x0

2 x=0

( )

AIf x0 Then r = 1

ElseIf x=0 Then

r=2

End If

BIf x 0 Then r = 1

ElseIf (x = 0) Then r=2 Else r = 1

End If

Cprint(IIf(x0,1,2))

Dr = IIf(x0,1,2)


Visual basic

0~60~6


Visual basic

:

,

1200

2200~4002003%

34004004%

4500050005%


Visual basic

  • Visual Basic

  • ForNext

  • DoLoopDo

Do


Visual basic

For-Next

For-Next

=

For to [Step ][Exit For]Next

True

?

False

Exit For

For I=1 to 10 step 1 Print I Next i


Visual basic

1=Int((-)/)+1

2

l

l

l

>0 <<0 >=0 =1

()

3

4


Visual basic

: s=0

For I=2 To 13 Step 3 s=s+i Next I

Print s=; s

Print i=; i

Int((13-2)/3)+1

: I=14


Visual basic

ForN !N

Private Sub Form_Click() Dim I%, f&, n% n = InputBox(, ) f = 1 For i = 1 To n f = f * I Next I Print n; "! ="; fEnd Sub


Visual basic

S=1+1/2+1/3++1/nn

n =val(InputBox(n"))S = 0For i = 1 To n S = S + 1/iNext iPrint S

10-27382-76-124321-2589-20


Visual basic

  • ForNext

  • For i=e1 To e2 [Step e3]

    • For j=d1 to d2 [Step d3]

    • ..

    • Next j

    • Next i

(1)(2)(3)


Visual basic

Private Sub Form_Click()

Dim i As Integer, j As Integer

For i = 1 To 9

For j = 1 To i

Print i; "*"; j; "="; i * j;

Next j

Print

Next i

End Sub

Print Tab((j - 1) * 13);


Visual basic

For j = 1 To 5

Print Tab(j); j

For i = 1 To 6

Print "*";

Next i

Print

Next j


Visual basic

Private Sub Form_Click()

Dim a As Integer, i As Integer, j As Integer

a = 0

For i = 1 To 2

For j = -2 To 2

a = a + i + j

Next j

Print a;

Next i

Print

Print i, j, a

End Sub


Visual basic

(2)For i=1 to 2 s=1 For j=0 to i-1 s=s+s*i Next j Print s;Next IEnd

(1)X$=a : y$=b : z$=cFor i=1 to 2 x$=y$ : y$=z$ : z$=x$next IPrint x$+y$+z$End

(3)For I=1 to 3 step 1 Print spc(5-I); For j=1 to 2*I-1 Print * Next j PrintNext i

For m=1 to 3 For n=0 to m-1 Next nNext mEnd


Visual basic

Do Loop

Do

1Do Loop While

2Do Loop Until

3Do While Loop

4Do Until Loop

<>1

Do Loop While Do While Loop True Do Loop Until Do Until Loop True


Visual basic

No

Yes

Yes

No

x=1Do Whilex<5Printxx=x+1Loop

Do While [Exit Do] Loop

Do[Exit Do]Loop While

2

1


Visual basic

Yes

No

No

Yes

x=1Do Printxx=x+1Loop Until x>=5

Do[Exit Do]Loop Until

Do Until [Exit Do ]Loop

3

4


Visual basic

50 ~ 1003Do4

Private Sub Form_Click() x=50 do until x>100 if x mod 3 <>0 then print x, end if x=x+1 LoopEnd Sub


Visual basic

1

Do Until

Loop

A0

B0

C0

D

2

x=1

y=4

Do Until y>4

x=x*y

y=y+1

Loop

Print x

A) 1B) 4C) 8D) 20


Visual basic

3

Private Sub Command1_Click()

x=0

Do Until x=-1

a=InputBox(a)

a=Val(a)

b=InputBox (b)

b=Val(b)

x=InputBox (x)

x=Val(x)

a=a+b+x

Loop

Print a

End Sub

54321-1

A2B3C14D15


Visual basic

4nametext1text2namecommand1

Private Sub Command1_click()

x=0

do while x<50

x=(x+2)*(x+3)

n=n+1

loop

text1.text=str(n)

text2.text=str(x)

end sub

A10B272C350D4168


Visual basic


Visual basic

1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1

For I=1 to 9 print spc(30-3*I) for j=1 to I Print j; next j for k=I-1 to 1 step 1 Print k; next k printnext i


Visual basic

2.7

  • VB ()()


Visual basic

  • :Dim | Static | public(1[,2]) [As ]60: [ To ] 0 , : +1: Dim kk(1 to 100) As Integer

Dim A( 0 To 2 0 To 3) As Long

A 34

: Dim A(2 3) As Long

3

4


Visual basic

(1) 0 ,1Option Base 1(2)

n =Inputbox(nDim x(n) As Single(3),Dim x(10) As Integer' x11x(10)=100 ' x(10)


Visual basic

(4)

(5)AsVariant

Dim a(1 to 5) as integer Dim a(5) as integer Dim a(5, 1 to 5) as integer

Option base 1dim b(3,2) as integer


Visual basic

(6)Lbound([,]) Ubound([,])

Private Sub Form_Click()Dim a(34) As IntegerPrint LBound(a,1); UBound(a,1)Print LBound(a,2); UBound(a,2)End Sub


Visual basic

  • ()ReDim

  • ReDim ([2]) [As ] Sub Form_Click( )Dim s( ) As Single ReDim s(43 to 8)End Sub

  • (1) DimPublicReDim(2) ReDim(3) ReDim


Visual basic

(4) ReDimReDimPreserve

Private Sub Form_Click()Dim a() As Integern = 3ReDim a(n)a(1) = 4Print a(1)n = 5ReDim a(n) ReDim preserve a(n)Print a(1)End Sub


Visual basic

dim s(5) as string s(1)=aa s(2)=s(1) & bb a=s(2) print s(1);s(2);a


Visual basic

ForInputBox dim a(5) as stringfor I=0 to 5 b=inputbox() a(I)=bnext idim a(4) as string a(0)=a : a(1)=b : a(2)=c : a(3)=d : a(4)=e

30


Visual basic

(1)For(InputboxFor i = 1 To 10 iA(i)=iNext i (2) Array

=Array(Dim ib As Variant Dim ib() as Variant

ib = Array("abc", "def", "67")For i = 0 To UBound(ib)Print ib(i); " ";Next i

(1)ArrayVariant(2)ArrayUbound


Visual basic

ForPrint

1ForPrinta(5)a(5) For I=0 to 5 print a(I); next I print

2For Print a(3,4) a(3,4)45

For I=0 to 3 For j=0 to 4print a(I,j); next j print next i


Visual basic

1

dim a(3),b(2,3) a(0)=0:a(1)=1:a(2)=2:a(3)=3 b(1,3)=a(3) a(0)=b(1,3)

2For dim a as variant,b() as varianta=array(1,2,3,4,5,6) redim b(ubound(a))For i = 0 To ubound(a) b(i) = a(i) Print b(i); Next i


Visual basic

For Each Next

for each In [ Exit For ] Next []

vaa,

dim a,va a=array(1,2,3,4,5) for each va in a print va; Next va


Visual basic

110PrivateSubCommand1_ClickDima(10)Asinteger,iAsInteger Fori=1To10a(i)=InputBox() Nexti

Fori=10To1step-1 Printa(i) NextI

EndSub

Dim Max As Integer,iMax As IntegerMax=A(1)n=1For i = 2 To 10If A(i)>Max ThenMax=A(i)n=iEnd IfNext I

For i =1 To 10\2t=A(i)A(i)=A(11-i)A(11-i)=tNext I


Visual basic

1(NameCommand1)Private Sub Command1_Click()Dim Arr1(10), arr2(10) As Integern=3For i = 1 To 5Arr1(i) = iarr2(n) = 2 * n + iNext iPrint arr2(n); Arr1(n) End Sub ( )

A.11 3B.3 11 C.13 3 D.3 13


Visual basic

2(NameCommand1)Option Base 1Private Sub Command1_Click()Dim a = Array(1, 2, 3, 4)j=1For i = 4 To 1 Step -1s = s + a(i)*jj =j * 10Next iPrint sEnd Sub ( )

A.4321 B.12 C.34 D.1234


Visual basic

3

Option base 1

Dim a as variant, max as integer, m as integer, sum as integer

Sum=0:max=0:m=0

A=array(21,15,20,19,3,17)

For i=1 to 6

sum=sum+a(i)

if a(i)>max then

max=a(i)

m=I

end if

Next I

Print max=;max, m=;m, sum=;sum


Visual basic

n

For i = 1 To n-1

m = i

For j = i + 1 To n

If a(j) < a(m) Then

m = j

End If

Next j

t = a(i)

a(i) = a(m)

a(m) = t

Next i

Print ""

For i = 1 To n

Print a(i);

Next i

Print

End Sub

Private Sub Command1_Click()

Dim a(1 to 10) As Integer

n=10

For i = 1 To n

a(i) = InputBox("10")

Print a(i);

Next i

Print


Visual basic

(Index) Private Sub cmdName _Click(Index As Integer)If Index=3 then

End IfEnd Sub


Visual basic

110551102956

2

A28764287025

B7927324157667880

2+798+2725+803

3n m

410X1010


Visual basic

510100207 14.5077 15.1156 14.2 231 14.7453 15.2 276 13.9096 15.7 122 13.7339 14.9 302 14.5 1 2 3

10


Visual basic

Dim a As Variant, b As Variant

a = Array("207", "156", "453", "096", "339", "077", "231", "276", "122", "302")

b = Array(14.5, 14.2, 15.2, 15.7, 14.9, 15.1, 14.7, 13.9, 13.7, 14.5)

For i = 0 To 8

Min = b(i)

n = i

For j = i + 1 To 9

If Min > b(j) Then

Min = b(j)

n = j

End If

Next j

t = b(i)

b(i) = b(n)

b(n) = t

t = a(i)

a(i) = a(n)

a(n) = t

Next i

Print ; Tab(8); ; Tab(20); "

For i = 0 To UBound(a)

Print i + 1; Tab(8); a(i); Tab(20); b(i)

Next i


Visual basic

2.8

VB

1VB

2

VBSubFunctionFunction


Visual basic

Sub

1Sub

  • Sub

    [Private|Public] [Static] Sub ([<>])

    [<>]

    [Exit Sub]

    [<>]

    End Sub

Sub

Private Sub sumx as integery as integer

dim s as integer

s = x + y

print ;s

End Sub


Visual basic

  • 1[Private|Public] Private

    2Static

    3SubFunction

    4Exit SubExit Sub


Visual basic

5<>

<>

6


Visual basic

2Sub

  • 1

    2

    3

  • End Sub


Visual basic

3Sub

SubEnd Sub

1CallSub

Call []

Call sumab

2

[]

Call

sum ab

<>


Visual basic

Sub

Private Sub Swap(x%,y%)

Dim temp%

Temp=X

X=Y

Y=Temp

End Sub

Private Sub CmdOK()

Call Swap(a,b)

Swap a,b

End Sub


Visual basic

P55

12


Visual basic

n!7+11-10

    • Sub jchn%p&

    • Dim i%

    • p = 1

    • For i = 1 To n

    • p = p * i

    • Next i

    • End Sub

Private Sub Form_Click

Dim a&b&c&d&

Call jch7a

jch 11b

Call jch10c

d = a + bc

Print "7!+11!-10!="d

End Sub


Visual basic

4

Visual Basic

1

SubFunction

2

SubFunctionSubFunction

A()


Visual basic

  • 3

  • ByVal

  • 4

  • ByRef


Visual basic

Sub Swap1(ByVal x%, ByVal y%)

Dim Temp%

Temp = x: x = y: y = Temp

End Sub

Sub Swap2(x%, y%)

Dim Temp%

Temp = x: x = y: y = Temp End Sub

Private Sub Command1_Click()

a% = 10: b% = 20: Swap1 a, b '

Print "A1="; a, "B1="; b

a = 10: b = 20: Swap2 a, b '

Print "A2="; a, "B2="; b

End Sub


Visual basic


Visual basic

Visual BasicStr( )val( )Function


Visual basic

1

[Private|Public] [Static] Function ( [] ) [As ]

[<>]

[<>=<>]

[Exit Function]

[<>]

End Function

1As<>As<>Variant

2=


Visual basic

myAbs

Public Function myAbs(a) as Single

If a >= 0 Then '

myAbs = a ' 0

Else

myAbs = -a '

End If

End Function

2

([])

Sub

Private Sub Command1_Click()

Dim sr As Single

sr = InputBox("")

Print "", myAbs(sr)

End Sub


Visual basic

n!7+11-10

Function jch(n%) as long

Dim i%,f%

f = 1

For i = 1 To n

f = f * i

Next I

jch=f

End Function

Private Sub Form_Click

Dim d as long

d = jch(7)+ jch(11)jch(10)

Print "7!+11!10!="d

End Sub


Visual basic

Text1Command1

Private Sub Command1_Click()

n = Val(Text1.Text)

If n\2 = n/2 Then

f = f1(n)

Else

f = f2(n)

End If

Print f; n

End Sub

Public Function f1(ByRef x)

x=x*x

f1=x+x

End Function

Public Function f2(ByVal x)

x=x*x

f2=x+x+x

End Function

6

A) 7236 B) 10836 C) 726 D) 1086


Visual basic

(1)

(2)

(3)


Visual basic

1A) Sub Proc1ByVal nByVal m B) Sub Proc1nByVal mC) Sub Proc1nm D) Sub Proc1ByVal nm

2

Private Sub Commandl_Click ( ) Dim a As Single Dim b As Single a =5:b =4 S a,b Print a,b

End Sub

Sub Sx As Single,y As Singlet = x

x=t/y y=t Mod yEnd Sub

A) 5 4 B) 1 1 C) 1.25 4 D) 1.25 1


Visual basic

Private Sub Command1_Click()

Dim a As Integer

A=4

For I=1 To 3

Print F(a)

Next I

End Sub

3Function F(a As Integer) b = 0 Static c b = b+1 : c = c+1 f = a+b+cEnd Function A) 6 B) 4 C) 4 D) 6 6 5 6 7 6 6 8 8


Visual basic

4

Public Sub Proc1(n As Integer,Byval m As Integer) n=n Mod 10

m=m\10End Sub

A) 12 34 B) 2 34 C) 2 3 D) 12 3

Private Sub Command1_Click() Dim x As Integer,y As Integer x=12:y=34 Call Proc1(x,y) Print x,yEnd Sub


Visual basic

11Function


Visual basic

2.9

  • 1

  • 2

  • 3

  • 4

  • 5


Visual basic

CommandButton

[]1

DefaultTrueCancelTrue


Visual basic

2Click

MouseDownMouseUpKeyDownKeyUp

3

SetFocus

<>.SetFocus


Visual basic

()

1

NameHeightWidthTopLeftEnabledVisibleFontForeColorBackColor

2

1Caption

Caption

2Alignment

0

1

2


Visual basic

3AutoSize

TrueFalse

4BorderStyle

01

5BackStyle

01

3

ClickDblClickChangCaption


Visual basic

1

1Text

TextText

Caption

2Maxlength , 0

3 MultiLine ,. False

4ScrollBars MultiLineTrue,,

0-None1-Horizontal

2-Vertical3-Both


Visual basic

5Locked False

6PassWordChar

PasswordChar

MultiLine False

7SelStartSelLengthSelText

SelStart 0SelStartSelStart

SelLength

SelText


Visual basic

0123456789 SelStart=5,SelLength=4,SelText="5678"

Private Sub Command1_Click()

Text1.SelStart = 0

Text1.SelLength = Len(Text1.Text)

Print Text1.SelText

End Sub

2

SetFocus


Visual basic

3

1ChangeTextTextChange

Private Sub Text1_Change() Static x As Integer x = x + 1 Text2.Text = Str(x) End Sub

2GotFocusTabSetFocus

Text

Private Sub Text1_GotFocus() Text1.SelStart=0 Text1.SelLength=Len(Text1.Text) End Sub


Visual basic

3KeyPress

ANSIKeyAsciiAscii

Private Sub Text1_KeyPress(KeyAscii As Integer)

Print KeyAscii, Chr(KeyAscii)

End Sub

ABCD

4LostFocusTab

LostFocus

Private Sub Text1_LostFocus()

If Text1.Text = Then MsgBox Text1.SetFocus End If End Sub


Visual basic

TabText1_ LostFocus :Tab,IsNumeric(Text1) : .Text1.SetFocus :


Visual basic

ScrollBarHScrollbarVscrollBar


Visual basic

1.

(1) Value

(2) Max

-32,768~32,767

(3) Min

-32,768~32,767

(4) SmallChange

(5) LargeChange


Visual basic

2

1Change

ChangeValueChange

2Scroll

ScrollScroll

ScrollChangeScrollChange


Visual basic

P34


Visual basic

10 ~ 100


Visual basic

2.10

2.11


Visual basic

2.8

ListBox List1List2List3

  • 1List

    • List00

      • List1.List(0)="

      • List1.List(1)="

      • List1.List(2)="

      • List1.List(3)="

      • List1.List(4)="


Visual basic

  • (2)ListIndex

    • ListIndexListIndex-1

  • (3)ListCount

    • ListCountListCount-1

      • 0~ListCount-1List

  • (4)Sorted

    • Sorted

      • True

      • False


Visual basic

  • (5)Text

    • Text

    • List1.TextList1.ListIndex

  • (6)MultiSelect

MultiSelect


Visual basic

7Selected

List

List1.Selected0=TrueList1ListIndex0

List1.selected(0)=true

List1.selected(1)=false

List1.selected(2)=true

List1.selected(3)=false

List1.SelCount=2

8SelCount

SelCount SelCount 0


Visual basic

  • (9)Style

      • 0

      • 1

List1.List(0)=

List1.List(1)= List1.ListIndex = 3 (0)List1. ListCount = 5List1. Selected(3) = TrueFalseList1. Sorted = FalseList1. Text List1. List(List1. ListIndex)


Visual basic

ClickDblClick

List

AddItemRemoveItem

Clear

(1)AddItem

  • .AddItem ,

  • AddItem

  • 0ListCount-1


Visual basic

  • (2)RemoveItem

    • .RemoveItem

    • List1Command1Command2

      • Private Sub Command1_Click

      • List1.AddItem "One"0

      • End Sub

      • Private Sub Command2_Click

      • List1.RemoveItem 0

      • End Sub

  • (3)Clear

    • .Clear

    • ClearListCount0


  • Login