自定义一个类型,包括 int string 类型,例如:
Public Type ysjl
n4 As String
zn4long As Integer
End Type
然后定义一个数组 dim zhj(1 to 3) as ysjl
如何一次性的将数组 zhj 写入文本文件,而且,写入后,字符型的加上双引号,integer 类型的不加,并且分割用逗号,
假设数组内容如下:
zhj(1).n4="asd"
zhj(1).zn4long=3
zhj(2).n4="qwer"
zhj(2).zn4long=4
写入文本文件后,是这样
"asd",3
"qwer",4
请指教,要分马上就给
Public Type ysjl
n4 As String
zn4long As Integer
End Type
然后定义一个数组 dim zhj(1 to 3) as ysjl
如何一次性的将数组 zhj 写入文本文件,而且,写入后,字符型的加上双引号,integer 类型的不加,并且分割用逗号,
假设数组内容如下:
zhj(1).n4="asd"
zhj(1).zn4long=3
zhj(2).n4="qwer"
zhj(2).zn4long=4
写入文本文件后,是这样
"asd",3
"qwer",4
请指教,要分马上就给
Private Type ysjl
n4 As String
zn4long As Integer
End TypePrivate Sub Command1_Click()
Dim zhj(1 To 3) As ysjl
zhj(1).n4 = "asd"
zhj(1).zn4long = 3
zhj(2).n4 = "qwer"
zhj(2).zn4long = 4
Open "c:\123.txt" For Output As #1
Write #1, zhj(1).n4, zhj(1).zn4long
Write #1, zhj(2).n4, zhj(2).zn4long
Close #1
End Sub
Private Type HyKcop
bs As String * 10
db_bh As String * 10
cp_name As String * 30
cp_bh As String * 10
cp_bs As String * 10
cp_lb As String * 30
cp_gg As String * 40
cp_dw As String * 10
input_bm As String * 20
output_bm As String * 20
much As Long
next_sum As Double
sum As Double
datet As String * 10
OpName As String * 10
getName As String * 10
jbName As String * 10
kc_bh As String * 10
bmbs As String * 20
lopName As String * 10
pcName As String * 10
note As String * 40
addtime As String * 10
cpdhbs As String * 10
End Type'//将传来的记录集写入临时文件
Public Sub Write2TempFile(rs As ADODB.Recordset) Dim TBool As Boolean
Dim MyDt As HyKcop
With MyDt
.addtime = RNull(rs("addtime"))
.bmbs = RNull(rs("bmbs"))
.bs = RNull(rs("bs"))
.cp_bh = RNull(rs("cp_bh"))
.cp_bs = RNull(rs("cp_bs"))
.cp_dw = RNull(rs("cp_dw"))
.cp_gg = RNull(rs("cp_gg"))
.cp_lb = RNull(rs("cp_lb"))
.cp_name = RNull(rs("cp_name"))
.cpdhbs = RNull(rs("cpdhbs"))
.datet = RNull(rs("datet"))
.db_bh = RNull(rs("db_bh"))
.getName = RNull(rs("getName"))
.input_bm = RNull(rs("input_bm"))
.jbName = RNull(rs("jbName"))
.kc_bh = RNull(rs("kc_bh"))
.lopName = RNull(rs("lopName"))
.much = rs("much")
.next_sum = rs("next_sum")
.note = RNull(rs("note"))
.OpName = RNull(rs("OpName"))
.output_bm = RNull(rs("output_bm"))
.pcName = RNull(rs("pcName"))
.sum = rs("sum")
End With
Dim tepFile As String
FSzie = Len(MyDt)
tepFile = "c:\cdktest.dat"
if dir(tepfile)<>"" then
TBool = false
end if
Fn = FreeFile()
Open tepFile For Random As Fn Len = FSzie
If TBool Then '//要建立新文件
Position = 1
Else '//写旧文件
Lastr = LOF(Fn) / FSzie
Position = Lastr + 1
End If
Put #Fn, Position, MyDt
Close #Fn
End Sub