module.vb从textfile获取信息 [英] module.vb get info from textfile
本文介绍了module.vb从textfile获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有module.vb文件,我想从文本文件中获取数据...
Dim FILE_NAME As String = Application.StartupPath& \ textfile.txt
Dim objReader As 新 System.IO.StreamReader(FILE_NAME)
Dim cons1 作为 字符串 = objReader.ReadLine ' 错误声明预期
objReader.Close()
Dim cons()作为 字符串
cons = cons1。拆分( )' 错误声明预期
我有错误预期声明。感谢您的帮助!
解决方案
没有上下文,很难确定,但......是方法中的任何代码吗?因为如果不是,那么当您尝试使用不声明变量的代码时会导致错误,例如:
objReader.Close( )
或
cons = cons1.Split( )
删除语法错误,我做了以下更改。
1.添加了对 System.Windows.Forms 的引用。
2.添加了导入System.Windows.Forms
。
3.添加导入System.IO
。
4.添加CChar( )
到.Split
将参数强制转换为Char
数据类型的方法参数。
5.将代码放在名为Test
的方法中。
Imports System.Windows.Forms
Imports System.IO
模块 Module1
Sub Test()
Dim FILE_NAME As String = Application.StartupPath& \ textfile.txt
Dim objReader As 新 System.IO.StreamReader(FILE_NAME)
Dim cons1 作为 字符串 = objReader.ReadLine '
objReader.Close()
Dim cons() As String
cons = cons1.Split( CChar ( ))
< span class =code-keyword>结束 Sub
结束 模块跨度>
i have module.vb file and i want to get data from textfile...
Dim FILE_NAME As String = Application.StartupPath & "\textfile.txt"
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim cons1 As String = objReader.ReadLine 'error "declaration expected"
objReader.Close()
Dim cons() As String
cons = cons1.Split(" ") 'error "declaration expected"
Im having an error "Declaration expected". Thanks for the help!
解决方案
Without the context it's difficult to be sure, but...is any of this code inside a method? Because if it isn't, then that would cause the errors when you try to use code which doesn't declare a variable, such as:
objReader.Close()
Or
cons = cons1.Split(" ")
To remove syntax errors, I made the following changes.
1. Added a reference to System.Windows.Forms.
2. Added anImport System.Windows.Forms
.
3. Added anImport System.IO
.
4. AddedCChar(" ")
to.Split
method parameter to cast the parameter to theChar
data type.
5. Put the code inside a method namedTest
.
Imports System.Windows.Forms Imports System.IO Module Module1 Sub Test() Dim FILE_NAME As String = Application.StartupPath & "\textfile.txt" Dim objReader As New System.IO.StreamReader(FILE_NAME) Dim cons1 As String = objReader.ReadLine ' objReader.Close() Dim cons() As String cons = cons1.Split(CChar(" ")) End Sub End Module
这篇关于module.vb从textfile获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文