VB如何保存文本框里面的内容?
4个回答
展开全部
保存在注册表里了,不过别存太多东西,注册表累赘了就不好了。
Private Sub Command1_Click()
SaveSetting "regcust", "startup", "backup", Text1.Text
End Sub
Private Sub Form_Load()
Text1.Text = GetSetting("regcust", "startup", "backup", "0")
End Sub
Private Sub Command1_Click()
SaveSetting "regcust", "startup", "backup", Text1.Text
End Sub
Private Sub Form_Load()
Text1.Text = GetSetting("regcust", "startup", "backup", "0")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'保存
private sub command1_click()
open app.path & "\a.txt" for input as #1
print #1,text1.text
close #1
end sub
'读取
private sub command2_click()
dim s as string
open app.path & "\a.txt" for output as #1
while not eof(1)
line input #1,s
text1.text=text1.text & s & vbcrlf
wend
close #1
end sub
private sub command1_click()
open app.path & "\a.txt" for input as #1
print #1,text1.text
close #1
end sub
'读取
private sub command2_click()
dim s as string
open app.path & "\a.txt" for output as #1
while not eof(1)
line input #1,s
text1.text=text1.text & s & vbcrlf
wend
close #1
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果数据有规律的话,不少于一百个这样的规模还是写入数据库更好。
操作.ini文件也可行,就是代码码起来烦。
以下代码放在一个模块中 用于读取和写入ini文件用的
Option Explicit
'以下为读取ini的API
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public inifilename As String '配置文件的名称,在窗体load事件中初始化
'读取INI
Function GetIniS(ByVal inifilename As String, ByVal SectionName As String, ByVal KeyWord As String, Optional ByVal DefString As String) As String
Dim ResultString As String * 128, Temp%
Dim s$, i%
Temp% = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 144, inifilename)
'检索关键词的值
If Temp% > 0 Then '关键词的值不为空
For i = 1 To 128
If Asc(Mid$(ResultString, i, 1)) <> 0 Then
s = s & Mid$(ResultString, i, 1)
End If
Next
Else
Temp% = WritePrivateProfileString(SectionName, KeyWord, DefString, inifilename) '将缺省值写入INI文件
s = DefString
End If
GetIniS = s
End Function
'写入INI
Function PutIniS(ByVal inifilename As String, ByVal SectionName As String, ByVal KeyWord As String, Optional ByVal DefString As String) As String
Dim ResultString As String * 128, Temp%
Dim s$, i%
Temp% = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 144, inifilename)
'检索关键词的值
Temp% = WritePrivateProfileString(SectionName, KeyWord, DefString, inifilename) '将缺省值写入INI文件
End Function
'模块内的内容到此结束
config.ini文件中的行
[File]
InputDir=D:\e.exe
读取的示例
File_in.Text=GetIniS(App.Path & "\config.ini", "File", "InputDir", App.Path)
GetIni函数有4个参数
第一个是从哪个配置文件中获得数据
第二个是从配置文件的那个节点获得信息
第三个是从对应该节点的那个项目上获得信息
第四个是如果信息不存在时,用第四个值为默认值
该处对就上面的config.ini配置文件获取的值是D:\e.exe
保存(写入)的示例
Call PutIniS(App.Path & "\config.ini", "File", "InputDir", File_in.Text)
保存File_in文本框中的内容到config.ini中的对应项
app.path 指的是当前软件所在目录 不懂得的问QQ4037168
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |