Visual Basic
This presentation is the property of its rightful owner.
Sponsored Links
1 / 41

第七章 文件操作 PowerPoint PPT Presentation


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

《Visual Basic 程序设计 》. 第七章 文件操作. 主讲:赵娜 计算机系信息教研室. 本章主要任务: 1. 掌握文件系统的基本概念; 2. 掌握顺序文件、随机文件的特点和使用; 3. 掌握对在应用程序中不同类型文件的打开、关闭和读写操作。. 文件 是存储在外部介质上的以文件名为标识的 数据的集合 。 在Visual Basic中,文件说明的一般格式 设备名: 文件引用名 文件引用名由文件基本名和扩展名组成. 7.1 文件概念. 文件的结构 文件 记录 字段 字符. 表 7-1 居民区人员登记表( jmdjb.dat ).

Download Presentation

第七章 文件操作

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


6088163

Visual Basic


1 2 3

1.

2.

3.


6088163

Visual Basic

\

7.1


6088163

7-1 jmdjb.dat


6088163

ASCII


6088163

1Sequential File

2Random Access File

3Binary file


6088163

6.2.1

1.

Open For As # <>[Len=]

Output

Input

Append

6.2


6088163

Output

21511

FreeFile


6088163

Close

Close [[#]][[#]]

Close #1#2#3

123Close

2.


6 2 2 1

1Print #

Print # <>[,<>]

(2) Write #

Write #<>[,<>]

6.2.21


Print

Open "E:\VB\Exercise.TXT" For Output As #1

Print #1, This is a test

Print #1,

Print #1,Zone 1;Tab;Zone 2

Print #1,Spc(5);5 leading spaces 5

Print #1,Tab(10);Hello 10

Close #1

Print


Write

Private Sub Form_Load()

Dim i As Integer s As String

Dim d As Date b As Boolean

i = 125: s = "programming": d = Date: b = True

Open "d:\vb\example.txt" For Output As #1

Write #1 i s d b

Write #1 "Write"

Close #1

End Sub

Write


Write print

Write Print Write

Write

Write Print


6088163

1LOF

LOFLOF1#10

2EOF

EOFEOFTrueFalseEOFGetTrueFalse

3LOC

LOC


2 line input input input

1.Line Input #

Line Input #

2Line Input # Input # Input


6088163

7-37-1Line Input #

Private Sub Form_Click()

Dim st As String x As String

Open "d:\vb\exercise.txt" For Input As #1

While Not EOF(1)

Line Input #1 x

st = st & vbCrLf & x vbCrLf

Wend

Close #1

Print st

End Sub


2 input input input

9.3

2Input #Input # Input #


3 input

Input <>#<>

9.3

3Input


6088163

7-4Form1Text1C1C2C3DVBin5.txtText1Text1Text1out5.txt


6088163

Private Sub Form_Click()

Dim x As Single,amax As Single,amin As Single

Dim i As Integer

Open "in.txt" 1 As #1

Input #1,x

amax=x

amin=x

i=2

Do While i<=100

Input #1,x

Print x;

If amax<x Then

amax=x

End If

If amin>x Then

amin=x

End If

i=i+1

Loop

Close #1

Print amax,amin

Open "out.txt" 2 As #2

3 amax,amin

close #2

End Sub

in.txt100out.txt

1A) Input B) For Input C) For Output D) Output

B

2A) For Output B) For Input C) Output D) Input

A

3A) Write B) Print C) Write #2 D) Print #2,

D


6088163

DATA.TXT

Private Sub Command12_Click()

Dim StuName As String, StuXb As String, StuScore As Single

Open "d:\vbtest\data.txt" For 1 As #1

Do While 2

3, StuName, StuXb, StuScore

Print StuName, StuXb, StuScore

Loop

Close #1

End Sub

1A) Append B) Input C) Random D) OutPut

B

2A) Not EOF(1) B) EOF(1) C) LOF(1) D) Not LOF(1)

A

3A) Input #1 B) Read #1 C) Get #1 D) Line Input #1

A


6088163

6.3


6 3 1

1

Open For Random As # [Len=]

Open128

DMyDocMyData1.txt100

Open "D:\MyDoc\Mydata1.txt " For Random As #1 Len=100

2

Close

6.3.1


6 3 2

1

Put

Put # <> ,[<>], <>

<>1

<>

Put

6.3.2


6088163

Get

Get # [<>]

Get1

2


6088163

Data.txtStuNoStuNameStuScoreText1Text2Text3StuNoStuNameStuScore

Public Type student

StuNo As String * 6

StuName As String * 6

StuScore As Single

End Type


6088163

Private Sub Command1_Click()

Dim Stud As student

Open "d:\data.txt" For 1As #1 Len = 2

Stud.StuNo = Text1.Text

Stud.StuName = Text2.Text

Stud.StuScore = Val(Text3.Text)

N = Int(LOF(1) / Len(Stud)) + 1

3, N, Stud

Text1 = "": Text2 = "": Text3 = ""

Text1.SetFocus

Close #1

End Sub

1A) Append B) Input

C) Random D) OutPut

C

2A) Len(Student) B) Len(Stud)

C) Stud D) Student

B

3A) Put #1 B) Input #1

C) Get #1 D) Write #1

A


6 4 1

1

Open For Binary As #

2

Close

6.4

6.4.1


6 4 2

1.

Put <>,[<>],<>

Put<><>

2.

Get <>[<>],<>

Get

6.4.2


6088163


6088163

6.5.1

1FileCopy

FileCopy

FileCopy "D:\Myfile\ABC.doc ", "A:\ABC.doc"

DMyfileABC.doc AABC.doc

FileCopy


2 kill

Kill

Private Sub Command1_Click()

answer=MsgBox"",vbYesNo, ""

If answervbYes Then Kill "D\Myfile.dat"

End Sub

Kill

2Kill


6088163

3Name

Name As

Name "D:\Myfile\ABC.doc"As"C:\New\ABC.doc"

DMyfileABC.doc CNewABC.doc

1"*"""

2

3


6088163

4ChDrive

ChDrive

ChDrive "D"ChDrive "D:\ "D

" "


6088163

5ChDir

ChDir

ChDir "D:\Myfile"

ChDir CDC

6MkDir

MkDir

MkDir "D:\Myfile\ABC"

'DMyfileABC

MkDir


6088163

7RmDir

RmDir

RmDir "D:\Myfile\ABC"

'DMyfileABC

RmDirKillRmDir


6 5 2

1. CurDir

CurDir

VariantString

2GetAttr

GetAttr

3FileDateTime

FileDateTime

6.5.2


6088163

4FileLen

FileLen

LongFileLen


6088163

VB


6088163

1OpenForAs[#][Len=]

2Print # <>,[<>] Write # <>,[<>]

3Get # ,[<>] ,

4Close [[#]][[#]]

LOFEOFLoc


6088163

1Open For Random As # [Len=]

2 Put # <> [<>] <>

3 Get # [<>]

4Close [[#]][[#]]


  • Login