vb.net读取dat vb60读取excel
vb.net怎么往已经建立好的dat文件里写东西,还不覆盖原本的数据?
如果想继续编辑之前的文档,在TXT文件尾部继续添加文本,那么还需要在函数后边加个参数。
创新互联网站建设公司,提供网站设计制作、做网站,网页设计,建网站,PHP网站建设等专业做网站服务;可快速的进行网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,是专业的做网站团队,希望更多企业前来合作!
VB 代码
方法1:
Dim sw As StreamWriter = New StreamWriter("C:\temp\test.txt")
sw.Write("abc" vbCrLf)
sw.Close()
Dim sw2 As StreamWriter = New StreamWriter("C:\temp\test.txt", True)
sw2.Write("456" vbCrLf)
sw2.Close()
方法2:
My.Computer.FileSystem.WriteAllText("test.txt", "This is test Text", True)
方法3:
System.IO.File.AppendAllText("c:\temp\test.txt", "this is extra test file")
详见:“网页链接”
vb.net读取dataset
假设cn是你打开的数据,table1中A、B、C值对应的字段为field1,A1、B1、C1对应的字段为field2;table2中A1、B1、C1值对应的字段为field3,输入框分别为text1
set rs=cn.execute("select field3 from table2 where field3 in (select field2 from table1 where field1='" text1 "'")
if not rs.eof then
msgbox "存在" text1 "和“ rs(0) "的关系"
else
msgbox "不存在" text1 ""的对应关系"
endif
set rs=nothing
vb.net 二进制读取文件
VB.NET打开二进制文件用fileopen完成,打开二进制文件的形式为:openmode.binary
读取二进制文件用的是fileget方法,写入二进制文件用的是fileput方法。
应用示例:将一批随机数保存在一个dat文件中,然后再将其提取到文本框中。
二进制文件的读写一批随机数的存取,程序为:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, i, fn As Integer
Dim s As String = ""
fn = FreeFile()
FileOpen(fn, "d:\data.dat", OpenMode.Binary)
For i = 1 To 8
x = Int(Rnd() * 100)
s = s + Str(x)
FilePut(fn, x)
Next
FileClose(fn)
TextBox1.Text = s
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim x, fn As Integer
Dim s As String = ""
fn = FreeFile()
FileOpen(fn, "d:\data.dat", OpenMode.Binary)
Do While Not EOF(fn)
FileGet(fn, x)
s = s + Str(x) + " "
Loop
FileClose(fn)
TextBox1.Text = s
End Sub
VB.net 如果读取txt数据(或十进制dat数据)
vb.net虽也有input语句,但一次只能读取到一个变量中,可以用TextFieldParser类代替,但似乎没以前的方便。不过比以前的更灵活。写入文件Write还是可以用,在Microsoft.VisualBasic.FileIO中。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fileName As String = "E:\User Documents\Master\My Documents\电子阅读\股票\table2.csv"
Using Recrods As New Microsoft.VisualBasic.FileIO.TextFieldParser(fileName) '建立TextFieldParser对象
'MyReader.TextFieldType = FieldType.Delimited
Recrods.SetDelimiters(",") '把字段分隔符设置为","
Dim curRow() As String
Do Until Recrods.EndOfData
curRow = Recrods.ReadFields() '读取记录行,返回字符串数组,所以不同字段类型需要自己转换。
Debug.Print(Join(curRow, vbTab))
Loop
End Using
End Sub
网站标题:vb.net读取dat vb60读取excel
文章链接:http://scyanting.com/article/dddhoid.html