:






16. , ,






, , .

String 4.7. ? - . (, ) , , , . . .

" ", . Visual Basic . :

" " +" " + . Visual Basic
" " & " " & " " & . +,
Len(" ")   ,
Mid(" ", 3, 4) 4, 3-
Mid(" ", 5, 1) 5-

Mid . " ":

s = " "

For i = 1 To Len(s)

Debug.Print Mid(s, i, 1) ' i-

Next

 

:

InStr(" ", " ")   ( ), " " " "
InStr (" ", " ")   " " " "
Left(" ", 2) 2
Right(" ", 3) 3
Ucase(" ")
Lcase(" ")

 

2.5 () Val, , 4.10 () - Str, . :

Val(" 20 8 ")   , ,
Val (" - 1 0") -10
3 * Val(" 2" & " 0")   " 2" & " 0" " 20", Val (" 20") 20
Str(5 * 5)   25 " 25". , , Visual Basic , , .

 

, , , , , , . , . ? , . " " " " . , , . . :

" " & LTrim(" ") & " " LTrim
" " & RTrim(" ") & " " RTrim
" " & Trim(" ") & " " Trim

ASCII

, , ASCII. . Asc. Chr - :

Asc(" ")   ASCII 219
Chr(219) 219 ASCII

ASCII 256 , 0 255. , , 32-:

For i = 32 To 255

Debug.Print Chr(i);

Next

:

! " #$%& '()*+, -./0123456789:; < =>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz

{|}~

 

124: , Debug.Print Chr(Asc(" ") + 1)?

125: " ". , - , , . . , 6 , . , .

126: . . , . . , ( ASCII). . , , . , , . .

: , , 1, , , . : Dim s(20) As String * 1. . . , " ". , .

, . , ? , , . , ? ? - ( 1). , , . , , . , , . , .

, . . . , . , , , , , .

, 2. , , - , , .

Visual Basic . - . , , . , - , , , - . , , , , , , . , " " , . , , .

, .

.

 

1: " " 1998 c: Filimon.txt, VB.

: , . . Filimon.txt , . 1.

, . . , :

 

: Open " C: \VB\Filimon.txt" For Output As #1
: " C: \VB\Filimon.txt" 1

 

, . , . , , - , . :

Private Sub Command1_Click()

Open " C: \VB\Filimon.txt" For Output As #1 ' Filimon.txt VB C 1

Write #1, " " ' 1 " "

Write #1, 1998 ' 1 1998

Close #1 ' 1

End Sub

, Write. Close.

, . Visual Basic Windows, , Filimon.txt. , , Notepad , :

" "

Write :

Write #1, " ", 1998

:

" ", 1998

, - , Output Open Append.

 

, , , . - , . Open . Visual Basic . Open , . :

Open App.Path & " \Filimon.txt" For

App.Path - , .

 

, . - , , . , .

 

2: Filantrop.txt :

" "

" ", 2000

.

.

:

Private Sub Command3_Click()

Dim a1 As Integer ' ,

Dim a2 As String '

Dim a3 As String '

Dim a4 As Integer '

Open App.Path & " \Filantrop.txt" For Input As #1 ' 1 Filantrop.txt

Input #1, a1 ' 1-

Input #1, a2 ' 2-

Input #1, a3, a4 ' 3-

Close #1 ' 1

Debug.Print a3, a4

End Sub

Immediate:

2000

, Input. Close. , , , " " .

 

3: , Filantrop.txt. , , . , , , . , , . , , , String. , Filantrop.txt:

Private Sub Command4_Click()

Dim s1 As String ' ,

Dim s2 As String '

Dim s3 As String '

Open App.Path & " \Filantrop.txt" For Input As #1 ' 1 Filantrop.txt

Line Input #1, s1 '

Debug.Print s1

Line Input #1, s2 '

Debug.Print s2

Line Input #1, s3 '

Debug.Print s3

Close #1 ' 1

End Sub

String Line Input. Immediate:

" "

" ", 2000

, , 2. , Line Input , . . , , s3 " ", 2000, .

 

- , , , , , , .

4: f 10 . .

:

Dim s(1 To 10) As String

Private Sub Command1_Click()

' :

Open App.Path & " \f.txt" For Input As #1 ' 1 f.txt

For i = 1 To 10

Line Input #1, s(i) '

Next

Close #1 ' 1

' :

For i = 1 To 10

s(i) = s(i) & "! " '

Next

' :

Open App.Path & " \f.txt" For Output As #1 ' 1 f.txt

For i = 1 To 10

Print #1, s(i) '

Next

Close #1 ' 1

End Sub

, Print, Write. , 2.

, Print , .

 

5: , .

: For , . : " , ". . EOF (End of File), " ", , , True, - False.

:

Do While Not EOF(1) ', 1

Line Input #1, s(i)

i = i + 1

Loop

 

, , :

6: .txt 10. , , . . , . , 10, , .

:

1. , .

2. , . .

. 1 .

:

Dim As Integer

 

Private Sub Form_Load()

Open App.Path & " \.txt" For Input As #1 ' 1 .txt

Input #1, ' ,

Close #1 ' 1

End Sub

 

Private Sub Timer1_Timer() ' ,

Debug.Print '

= + 1 '

End Sub

 

Private Sub Form_Unload(Cancel As Integer)

Open App.Path & " \.txt" For Output As #1 ' 1 .txt

Write #1, ' ,

Close #1 ' 1

End Sub

Form_Unload. , Form_Terminate, . .

 

. , . .

 

127: " ". 1 . . . , , , - " " " ".

, . , . , , - , , .

Visual Basic , Windows, : , , .

c temp 222, 333, 666, 999 1.txt.

:

FileCopy" c: \temp\1.txt", " c: \temp\2.txt" FileCopy . : - , - , . 1.txt 2.txt
FileCopy " c: \temp\1.txt", " c: \temp\222\4.txt" 1.txt c: \temp\222 4.txt
Name" c: \temp\222\4.txt" As " c: \temp\222\5.txt" Name As . , FileCopy. 4.txt 5.txt .
Name " c: \temp\222\5.txt" As " c: \temp\5.txt" 5.txt temp.
Kill" c: \temp\5.txt" Kill .

:

Name " c: \temp\333" As " c: \temp\444" 333 444.
Name " c: \temp\666" As " c: \temp\222\666" 666 222.
MkDir" c: \temp\888" 888.
RmDir" c: \temp\888" 888.

. . , , . , c: \temp\999, ,

FileCopy " c: \temp\999\22.txt", " c: \temp\999\44.txt"

, :

ChDir " c: \temp\999"

:

FileCopy " 22.txt", " 44.txt"

CurDir , . Debug.Print CurDir.


:

mylektsii.su - - 2015-2024 . (0.027 .)