.


:




:

































 

 

 

 





Visual Basic

Asc(S) , S. "", , 65

Chr(N) , N, 0 255, . 65, , "" (Chr(13) , Chr(10) )

Hex(N) , N

|Oct(N) , N

CBool(N) Boolean- N

CByte(E) Byte ( 0 255); ,

CCur(E) Currency; E ,

CDate(E) Date. E ( ), 1/1/100 12/31/9999,

CDbl(E) Double; E ,

 

Sub pr()

Dim i, s As Integer

s = 0

For i = 20 To 100 Step 1

If i Mod 2 = 0 Then

s = s + i

End If

Next i

MsgBox s

End Sub


 


13 Visual Basic for Application.

VBA- , Date

Date . . VBA

Time Date. . VBA

Now

Year(D) , Date . 100 9999

Month(D) , Date, . 1 12,

Day(D) , Date . 1 31,

Weekday(D) , Date. 1 7, ; 1 , 2

Hour(D) , , Date. 0 23, . D , Hour 0

Minute(D) , Date. 0 59, . D , Minute 0

Second(D) , Date. 0 59, . D , Second 0

 

Sub pr()

Dim i, s As Integer

s = 0

For i = 30 To 200 Step 1

If i Mod 2 <> 0 Then

s = s + i

End If

Next i

MsgBox s

End Sub


 


14 Visual Basic for Application.

VBA ,

InStr([Nl,] SI, S2[, N2]) S2 S1. N1 ; N2 . N1 N2 . N2 , Option Compare

InStrRev(Sl, S2 [, Nl[, N2]]) S2 S1, ( N1) . N2 . N2 , Option Compare

LCase(S) ( String), S ,

Left(S, N) ; N S, S

Len(S) S,

LTrim(S) S ( )

Mid(S, Nl, N2) ; N2 S, S, N1. N2 ; N2 , Mid S N1

Right(S, N) String; N S, S

RTrim(S) S ( )

Sub pr()

Dim i, p, n As Integer

p = 1

n = CInt(InputBox(" "))

For i = 1 To Step 1

p = p * i

Next i

MsgBox s

End Sub


 


15 Visual Basic for Application.

VBA- IfThen IfThenElse. IfThen VBA . If...Then...Else VBA , True.

IfThen . IfThen: If Condition Then Statements

Condition , a Statements , VBA; . VBA , Condition; True, ( ) Then . VBA , IfThen. , Condition, False, , IfThen, .

VBA , (:), : Statements1: Statements2: : StatementsN

. .

IfThen (block) If. IfThen , : If Condition Then Statements End If

End If VBA, . End If , .

IfThen . . VBA IfThenElse IfThenElseIf.

VBA- IfThenElse : .

 

Sub pr()

Dim i As Integer

Dim f As Single

n = InputBox(" n")

f = 1

For i = 1 To n Step 1

f = f * (1 + 1 / i ^ 2)

Next i

MsgBox f

End Sub


 

 


16 Visual Basic for Application.

For Next

For = To [Step ]

()

Next

Do Loop

Do While ()

()

Loop

Do Until ()

()

Loop

Do

()

Loop While

Do

()

Loop Until

Sub pr()

Dim m(6) As Single

Dim i As Integer

Dim s As Single

For i = 0 To 6 Step 1

m(i) = Val(InputBox("input znach"))

Next i

s = 0

For i = 0 To 6 Step 1

s = s + m(i)

Next i

s = s / 7

MsgBox s

End Sub


 

 


17 Visual Basic for Application.

, .

.

, .

.

:

Dim m1(50) as integer

Dim m2(10,20) as integer

Dim m3(10 to 25, 30 to 40) as integer

:

M1(24)=5

Dim m1()

ReDim

ReDim M1(5)

Preserve

Dim m() as single.

ReDim m(1 to 10, 1 to 20)

ReDim Preserve m(1 to 10, 1 to 50)

Sub pr()

Dim a() As Single

Dim i, n As Integer

n = InputBox(" ")

ReDim a(n)

For i = 0 To n Step 1

a(i) = InputBox(" ")

Next i

For i = 1 To n Step 2

MsgBox a(i)

Next i

End Sub


 


18 Visual Basic for Application.

VBA , , . , , , . VBA . Type End Type

Type

as Integer as String as String as String as String End Type

, . , Dim.

Dim As

(1 to 10) as

, , , , .

.=

.=

.=

With End With.

With .=.=.= End With

Sub pr()

Dim m(1, 1) As Single

Dim i, j As Integer

Dim s As Single

For i = 0 To 1 Step 1

For j = 0 To 1 Step 1

m(i, j) = Val(InputBox("input znach"))

Next j

Next i

s = 0

For i = 0 To 1 Step 1

For j = 0 To 1 Step 1

s = s + m(i, j)

Next j

Next i

MsgBox s

EndSub


 


19 Visual Basic for Application.

VBA :

1. ;

2. ;

3. .

VBA :

1. , . .

2. .

3. .

Open:

Open For as [#] _

.

.

Append . . , .

Input . .

Output . . , , .

Random . .

Binary . .

_ 1 511, .

Write #

Write #_, [_]

Input #

Input # _, _

Print #

Print #_, [_]

Line Input # .

Line Input #_,

Sub pr()

Dim a(1, 1) As Single

Dim i, j As Integer

Dim s As Single

For i = 0 To 1 Step 1

For j = 0 To 1 Step 1

a(i, j) = InputBox(" ")

Next j

Next i

s = 0

For i = 0 To 1 Step 1

For j = 0 To 1 Step 1

If i = j Then

s = s + a(i, j)

End If

Next j

Next i

MsgBox s

End Sub


 


20 Visual Basic for Application.

VBA , UserForm. , . , , VBA.

VBA Insert UserForm VBA. . Toolbox , , . . , . .

:

1. UserForm , , , , .

2. Toolbox, , Controls, , , .

3. . , Properties . , : Alphabetic ( ) , Categorized . , . , , .

4. Project View Code View Object. View Code , , .. . View Object .

:

1. ;

2. .

Show, Hide.

Sub pr()

Dim a() As Single

Dim i, n, s As Integer

n = InputBox(" ")

ReDim a(n)

s = 0

For i = 0 To n Step 1

a(i) = InputBox(" ")

Next i

For i = 0 To n Step 1

If a(i) Mod 2 = 0 Then

s = s + a(i)

End If

Next i

MsgBox s

End Sub


 


21 Visual Basic for Application.

UserForm , Excel Windows. (controls) , . -, , , .

1. (Select Object) , .

2. (Label) .

3. (TextBox) .

4. (ComboBox) .

5. (ListBox)

6. (CheckBox)

7. (OptionButton)

8. (ToggleButton) .

9. (Frame)

10. (CommandButton)

11. (TabStrip)

12. (MultiPage)

13. (ScrollBar)

14. (SpinButton)

15. (Image) , .

Type Sotr

Fam As String

Name As String

Namber As String

Adr As String

End Type

Sub pr()

Dim inf(1 To 10) As Sotr

Dim i, n, n1 As Integer

n = Val(InputBox(" "))

For i = 1 To n Step 1

With inf(i)

.fam = InputBox(" ")

.name = InputBox(" ")

.namber = Val(InputBox(" "))

.adr = InputBox(" ")

End With

Next i

n1 = Val(InputBox(" "))

MsgBox inf(n1).fam & Chr(13) & _

inf(n1).name & Chr(13) & _

inf(n1).namber & Chr(13) & _

Inf(n1).adr

End Sub




 


22 . Visual Basic for Application.

, , . , , :

:

Visual Basic for Applications (VBA) Basic Pascal, , , Microsoft Office, , , , , Word; , Excel. VBA, , , , . Microsoft Office , . ( Application - , ), , . VBA ? (Objects) VBA (, , , Word, , , Excel, Office). VBA , , , , . , , , , , . , . ? Office , , , . , . , . , . , , .

VBA, . Office , . " ", Microsoft. Excel .

Office "-" - , "" . , , , . , .

Type Abonent

Fam As String

Name As String

Namber As String

Adr As String

End Type

Sub pr()





:


: 2016-12-06; !; : 613 |


:

:

, - , ; , - .
==> ...

1479 - | 1493 -


© 2015-2024 lektsii.org - -

: 0.143 .