
正文
vb.net做小说阅读器 vb怎么写小说
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net创建一个txt文本,在debug文件夹里
设计一个窗口,添加一个名为textBox1的System.Windows.Forms.TextBox,
添加一个名为button1的System.Windows.Forms.Button。
为button1的单击事件添加如下处理函数:
Sub Button1Click(sender As Object, e As EventArgs)
'f是你的文本文件的文件名
Const f As String="t.txt"
Dim sw As System.IO.StreamWriter=Nothing
Try
If Not System.IO.File.Exists(f) Then
sw=System.IO.File.CreateText(f)
Else
sw=New System.IO.StreamWriter(f,True)
End If
sw.WriteLine(textBox1.Text)
Finally
If sw IsNot Nothing Then
sw.close()
End If
End Try
End Sub
相关问答
Q1: 请教在VB.net中如何将数据写入txt文件、再从txt文件读出?
软糖来告诉你吧。
VB.net中读写文件主要使用System.IO命名空间。
① 使用 File.ReadAllText 读取
Dim s As String = System.IO.File.ReadAllText("C:\a.txt")
② 使用 StreamReader 读取,注意编码格式和写入的编码保持一致。
Dim sr As StreamReader = New StreamReader("C:\a.txt", System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd()
sr.Close()
③ 使用 File.WriteAllText 写入,会覆盖同名的文件。
Dim 要写的内容 As String = ""
File.WriteAllText(文件路径, 要写的内容, System.Text.Encoding.UTF8)
④ 使用 StreamWriter 写入。
Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("C:\a.txt", False, System.Text.Encoding.UTF8)
sw.WriteLine(TextTB.Text)
sw.Close()
⑤ 使用 StreamWriter 追加写入。
将上面代码的第二个参数False改为True。
◆ 满意请采纳,谢谢 ◆
Q2: vb.net 如何打开txt文件?
说明:以下代码在Microsoft Visual Basic 2005 (简体中文版)中通过。
创建新项目:
在窗体上添加文本框2个:TextBox1,TextBox2
TextBox1 -- 用来编辑要写入的文本文件的内容,或显示打开的文本文件的内容
TextBox2 -- 用来输入要打开或要写入的文件名(包括盘符,路径)(例如:c:\123.txt)
在窗体上添加2个按钮:Button1,Button2
Button1 -- 写入文件
Button2 -- 打开文件
代码如下:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim w As New StreamWriter(TextBox2.Text)
w.Write(TextBox1.Text)
w.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim r As New StreamReader(TextBox2.Text)
Dim s As String
TextBox1.Text = ""
Do While r.Peek -1 '是否到文件尾
s = r.ReadLine
' MessageBox.Show(r.Peek)
TextBox1.Text = TextBox1.Text s vbCrLf
Loop
r.Close()
End Sub
End Class
补充:你要把读出的数据赋值给一个变量,只要:声明一个变量为数值类型,然后只要读取一行就可以了,把这行数据经过转换成数值后赋给这个变量.
Q3: 如何用vb.net编写读取txt内容的代码?
窗体上添加2个文本框,设置成多行,2个按钮,在文本框1里随便输入若干文字,可以多行,单击按钮1,保存到文件。然后单击按钮2,把刚才写入的文件读到文本框2里。
代码如下:
'写文本文件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'创建(写入)一个文本文件
Dim MyStream As New System.IO.FileStream(Application.StartupPath "\Ssk.txt", System.IO.FileMode.Create)
Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.Default)
MyWriter.WriteLine(TextBox1.Text)
MyWriter.Flush()
MyWriter.Close()
MyStream.Close()
End Sub
'读文本文件
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'读取一个文本文件
Dim MyReader As New System.IO.StreamReader(Application.StartupPath "\Ssk.txt", System.Text.Encoding.UTF8)
TextBox2.Text = MyReader.ReadToEnd()
MyReader.Close()
End Sub
气斜射入水或其他介质,折射光线与入射光线法线在
Q4: vb.net图书借阅管理系统
看了一圈回来,发现期末了都是一些不读书的人再找枪手,
希望,别做,才200分,为什么做?害人吗?
不过这样也行,我给你做,给我2000元吧,放点血,让你知道一下不读书的痛,而且我还会教你好多知识
Q5: 请教VB.NET文本框自动滚动的问题
你好很高兴回答你的问题,但是又很遗憾,对于你的问题又无能为力。也许你自己已经找到答案明天就是新的一年了,在这里祝你在新的一年里,心想事成。谢谢!
vb.net做小说阅读器的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb怎么写小说、vb.net做小说阅读器的信息别忘了在本站进行查找喔。





