streamreader()的使用

霜与寒雪 2006-03-30 09:12:35
我用下面这段代码:使用时报出输入的字符格式不正确,请大虾帮我看看问题出在哪个地方的?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strPath As String
Dim myfilestream As FileStream
Dim mystreamreader As StreamReader
Dim intread As Integer = 0
Dim readchr() As Char
Dim strread As String = ""
Try
OpenFileDialog1.ShowDialog()
strPath = OpenFileDialog1.FileName
' MsgBox(strPath)
myfilestream = New FileStream(strPath, FileMode.Open, FileAccess.Read)
mystreamreader = New StreamReader(myfilestream)

intread = mystreamreader.BaseStream.Length
ReDim readchr(intread)
intread = mystreamreader.Read(readchr, 0, intread)
strread = Convert.ToSingle(readchr)
txt.Text = strread
myfilestream.Close()
mystreamreader.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
...全文
94 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenger 2006-03-30
  • 打赏
  • 举报
回复
strread 是string 类型
Convert.ToSingle(readchr) 是单精度

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧