读书人

该怎么把从文件中读取的一行赋值到一个

发布时间: 2012-03-02 14:40:28 作者: rapoo

该如何把从文件中读取的一行赋值到一个数组
Dim enword() as byte
Open "MYFILE.TXT " For Input As #1
Randomize
rand = Int(7 * Rnd)
Do While Not EOF(1)
Line Input #1, strdata

enword() = strdata;这句报错

cnt = cnt + 1

If cnt > rand Then
Exit Do
End If
Loop
我想把得到的随机字符串读取到数组中进行操作,该如何写,如果我的数组是二维数组,想存取多个字符串,又该如何操作


[解决办法]
应该是循环吧

Dim enword() as string
dim i as integer
Open "MYFILE.TXT " For Input As #1
Randomize
rand = Int(7 * Rnd)
i=0
redim enword(0 to 0)
Do While Not EOF(1)

Line Input #1, strdata
redim preserve enword(0 to i)
enword(i)=strdata
i=i+1

cnt = cnt + 1

If cnt > rand Then
Exit Do
End If
Loop

[解决办法]
Dim enword() as byte
Open "MYFILE.TXT " For Input As #1
Randomize
rand = Int(7 * Rnd)
Do While Not EOF(1)
Line Input #1, strdata

enword = strconv(strdata,vbunicode);这句这么改
cnt = cnt + 1

If cnt > rand Then
Exit Do
End If
Loop

读书人网 >VB

热点推荐