重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
如果想繼續編輯之前的文檔,在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")
詳見:“網頁鏈接”?
假設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打開二進制文件用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雖也有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