主题:这么多年了,才发现VB的读写文件功能实在强大
Private Type SaveEnemy
x0 As Long
y0 As Long
style As Long
picIndex As Long
moveList As String
bulletList As String
End Type
Private Type LoadTimeList
cTime As Long
sIndex As Long
End Type
'''''''''''
Private Type MapContent
headStr As String
myName As String
initPicFile As String
musicFile As String
moveList As String
reservs(10) As String
reserv(10) As Long
timeList() As LoadTimeList
enemy() As SaveEnemy
End Type
'''''''''''''''''''''''''''''''''
Public Function LoadMapTEST(filepath As String)
Dim myReadMap As MapContent
Open filepath For Binary As #1
Get #1, , myReadMap
Close #1
Form1.Text2.Text = myReadMap.enemy(1).bulletList
End Function
Public Function SaveMapTEST(filepath As String)
Dim mySaveMap As MapContent
With mySaveMap
.headStr = "This is a map of PC1945!"
.myName = "1-1"
.initPicFile = "back1-1.bmp"
.musicFile = ""
.moveList = ""
ReDim .timeList(1)
.timeList(1).cTime = 100
.timeList(1).sIndex = 1
ReDim .enemy(1)
.enemy(1).style = 4
.enemy(1).picIndex = 1
.enemy(1).bulletList = Form1.Text1.Text
End With
Open filepath For Binary As #1
Put #1, , mySaveMap
Close #1
End Function
'最近无聊中用D3D写一个PC版的1945,为了简化文件存储,想起前段时间回复的一篇关于读写文件的帖子,结果一测试,
'发现VB读写文件的功能竟然如此强大。
'上面这种不定长字符串和没有指定长度的数组都能随便读写,简直无语了(注:每一组的数据长度完全不一样的啊)。以前每次都用定长字符串加字符长度,
' 还多用一个变量存储数组长度,每组都设置成一样长......结果现在看完全是多余。