当前位置:编程学习 > VB >>

vb保存代码怎么写

补充:我要编辑一个类似于记事本的文本,要有保存的功能

答案:Private Sub XPButton1_Click()
If Text1.Text = "" Then
MsgBox "请输入卡号", 32, "提示"
Else
If DataCombo1.Text = "" Then
MsgBox "请输入分类", 32, "提示"

Else

If Text2.Text = "" Then
MsgBox "请输入姓名", 32, "提示"

Else

If Combo2.Text = "" Then
MsgBox "请输入性别", 32, "提示"
Else

Call OpenConn
Adodc2.RecordSource = "select * from card_user where 卡号='" + Text1.Text + "'"
Adodc2.Refresh
If Adodc2.Recordset.RecordCount > 0 Then
MsgBox "此卡号已经存在", 32, "提示"
Else
'添加读者类别信息
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields("卡号") = Text1.Text
Adodc2.Recordset.Fields("分类") = DataCombo1.Text
Adodc2.Recordset.Fields("姓名") = Text2.Text
Adodc2.Recordset.Fields("性别") = Combo2.Text
Adodc2.Recordset.Fields("年龄") = Text3.Text
Adodc2.Recordset.Fields("住址") = Text4.Text
Adodc2.Recordset.Fields("邮编") = Text5.Text

Adodc2.Recordset.Update '更新数据库
MsgBox "数据保存成功!", 32, "提示"
End If
End If
End If
End If
End If
End Sub

这是我的保存代码可以复制进去用,不过自已要看一下代码在修改下

你可以采用+记事本相结合的方法来实现保存

1、采用控件RichTextBox1,添加部件Microsoft Rich textbox Control 6.0

2、代码:

'读取txt文件中的内容到RichTextBox1

Private Sub Form_Load()
Dim s, y As String
    Open "D:\8319.txt" For Binary As #1
        s = Input(LOF(1), #1)
        RichTextBox1.Text = s
    Close #1
End Sub

'将RichTextBox1中的内容写到txt文件中,没有则自动创建一个8319的TXT文件

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Open "D:\8319.txt" For Output As #1
Print #1, RichTextBox1.Text
Close #1
End Sub

3、在D盘创建一个名字为8319.txt的TXT文件,示例:

保存什么啊
以下代码主要是针对文本文档和word文档的文字的   方式为顺序存取     先拿去试试,不好就不要给分    我是新手


Private Sub Mensave_Click()
If Form1.Caption = "无标题" Then
      mnu_resave_Click       1
Else
num = FreeFile
Open Form1.Caption For Output As #num
Print #num, Text1
 
Close (num)
End If


1
mnu_resave_Click

CommonDialog1.Filter = "(txt 文档)|*.txt|(doc 文档)|*.doc"
CommonDialog1.ShowSave
f2 = CommonDialog1.FileName
num = FreeFile
Open f2 For Output As #num
Print #num, Text1
Close (num)
  Form1.Caption = f2

在部件里建立一个CommandDailogue !

用CommandDailogue . showSave 命令

 

或者建立一个Command

输入如下代码

 

open app.path & "\ 文件名.txt" for output as # 1

print # 1, Text1.text

close # 1

上一个:VB二维数组编程
下一个:vb是不是很难学?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,