Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
在太白等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站制作 网站设计制作按需网站开发,公司网站建设,企业网站建设,成都品牌网站建设,网络营销推广,外贸网站制作,太白网站建设费用合理。
FileOpen(1, "c:\34.txt", OpenMode.Output, OpenAccess.Write)
PrintLine(1, TextBox1.Text)
FileClose(1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
FileOpen(1, "c:\34.txt", OpenMode.Input, OpenAccess.Read)
Dim text As String = ""
Do Until EOF(1)
text += LineInput(1) vbCrLf
Loop
TextBox2.Text = text
FileClose(1)
End Sub
还是有点不同,vb6的print等同于这里printLine, print 类似于vb6的write,而且不换行。
至于你错在哪里我不知道了,反正我的代码测试了一下没问题。
窗体上有两个多行文本框,两个按钮(写入和读取)
补充:我想出一个原因,可能你没有关闭文件吧。写入的部分内容还在内存缓冲区,还没完全写入磁盘。
Public Sub abc() Dim filename, inputstring As String Dim i As Integer Dim data i = 1 filename = "d:\WYKS.txt" '本列TXT文件放在D盘中 Open filename For Input Access Read As #1 Do While Not EOF(1) Line Input #1, inputstring '读TXT文件一行 data = inputstring If i 1 Then Cells(i - 1, 1) = Mid(data, 11, 6) '截取从第11个字符后6个字符 Cells(i - 1, 2) = Mid(data, 19, 8) '截取从第19个字符后8个字符 Cells(i - 1, 3) = Mid(data, 29, 6) '截取从第29个字符后6个字符 Cells(i - 1, 4) = Mid(data, 37, 8) '截取从第37个字符后8个字符 End If i = i + 1 Loop Close #1 End Sub
Dim i As Integer
Dim j As Integer
Dim myFile As New System.IO.StreamWriter("c:\Test.txt")
Dim strTemp As String = ""
For j = 0 To frmQuery.DataGridView1.RowCount - 1
strTemp = ""
For i = 0 To frmQuery.DataGridView1.Columns.Count - 1
strTemp = "'" frmQuery.DataGridView1(i, j).Value "'" ","
Next
myFile.WriteLine(strTemp)
Next
myFile.Close()
格式为表格每行保存为文本文件的一行,字段之间以逗号分隔。