VB输出文本及读取文本
急:我做了一个VB程序。。里面有很多TEXT控件。我现在想把这些TEXT控件里面填写的类容用一个按钮控件以1.TEXT的方式放在电脑D盘上。保存后1.TEXT内容如下:第...
急:
我做了一个VB程序。。里面有很多TEXT控件。
我现在想把这些TEXT控件里面填写的类容用一个按钮控件以1.TEXT的方式放在电脑D盘上。保存后1.TEXT内容如下:
第一行:1(为VB中TEXT1.TEXT的数值)
第二行:2(为VB中TEXT2.TEXT的数值)
第三行:3(为VB中TEXT3.TEXT的数值)
第四行:4(为VB中TEXT4.TEXT的数值)
然后向用一个按钮2来读取1.TEXT里的内容
要求一一对应回原来VB中TEXT控件的位置
请问该如何实现啊??请各位高手指教
写一个代码给我好吗??学习中。。谢谢了
你好。。谢谢你回答我问题。。
您可不可以给我做一个关于你下面使用的VB程序。。
我还有些看不懂你这个。。
我的邮箱jljl159159@163.com
给我传一个好不??很急啊。。帮帮忙哈
luomandick同学的能生成文件。。但是不能返回数值啊 展开
我做了一个VB程序。。里面有很多TEXT控件。
我现在想把这些TEXT控件里面填写的类容用一个按钮控件以1.TEXT的方式放在电脑D盘上。保存后1.TEXT内容如下:
第一行:1(为VB中TEXT1.TEXT的数值)
第二行:2(为VB中TEXT2.TEXT的数值)
第三行:3(为VB中TEXT3.TEXT的数值)
第四行:4(为VB中TEXT4.TEXT的数值)
然后向用一个按钮2来读取1.TEXT里的内容
要求一一对应回原来VB中TEXT控件的位置
请问该如何实现啊??请各位高手指教
写一个代码给我好吗??学习中。。谢谢了
你好。。谢谢你回答我问题。。
您可不可以给我做一个关于你下面使用的VB程序。。
我还有些看不懂你这个。。
我的邮箱jljl159159@163.com
给我传一个好不??很急啊。。帮帮忙哈
luomandick同学的能生成文件。。但是不能返回数值啊 展开
3个回答
展开全部
先建一个控件数组:text1
Private Sub Command1_Click()
Open "D:\1.txt" For Output As #1
Print #1, Text1(0).Text
Print #1, Text1(1).Text
Print #1, Text1(2).Text
Print #1, Text1(3).Text
Close #1
End Sub
---------------------------------------------------
Private Sub Command2_Click()
Open "D:\1.txt" For Input As #1
Line Input #1, str0
Line Input #1, str1
Line Input #1, str2
Line Input #1, str3
Text1(0).Text = str0
Text1(1).Text = str1
Text1(2).Text = str2
Text1(3).Text = str3
Close #1
End Sub
Private Sub Command1_Click()
Open "D:\1.txt" For Output As #1
Print #1, Text1(0).Text
Print #1, Text1(1).Text
Print #1, Text1(2).Text
Print #1, Text1(3).Text
Close #1
End Sub
---------------------------------------------------
Private Sub Command2_Click()
Open "D:\1.txt" For Input As #1
Line Input #1, str0
Line Input #1, str1
Line Input #1, str2
Line Input #1, str3
Text1(0).Text = str0
Text1(1).Text = str1
Text1(2).Text = str2
Text1(3).Text = str3
Close #1
End Sub
展开全部
我检验了下发现时拼写错误··最主要当时没有进行验算的··呼呼··不过现在实验过绝对OK了··呵呵··
Private Sub Command1_Click()
Open "D:\result.txt" For Output As #1 '这里写自己要保存的地址
Print #1, "1 " & Text1(1)
Print #1, "2 " & Text1(2)
Print #1, "3 " & Text1(3)
Print #1, "4 " & Text1(4)
Close
End Sub
Private Sub Command2_Click()
Dim temp As String, i As Integer
On Error GoTo hh
Open "D:\result.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, temp
i = i + 1
Text1(i) = Trim(Right(temp, Len(temp) - InStr(temp, " ")))
Loop
Close
Exit Sub
hh:
MsgBox "Error"
End Sub
这个··不用ini文件读写的吧··那个太复杂而且不大好,因为是以键和键值表示的···其实只要写到txt文件中去就好了的么···我这里用控件数组表示你的Text,比较方便···
Private Sub Command1_Click()
Open "D:\result.txt" For Output As #1'这里写自己要保存的地址
Print #1, "1 " & Text1(1)
Print #1, "2 " & Text1(2)
Print #1, "3 " & Text1(3)
Print #1, "4 " & Text1(4)
Close
End Sub
Private Sub Command1_Click()
Dim temp As String, i As Integer
On Error GoTo hh
Open "C:\result.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, temp
i = i + 1
Text1(i) = Trim(Left(temp, Len(temp) - InStr(i, " ")))
Loop
Close
Exit Sub
hh:
MsgBox "Error"
End Sub
多加分啊···呼呼··
Private Sub Command1_Click()
Open "D:\result.txt" For Output As #1 '这里写自己要保存的地址
Print #1, "1 " & Text1(1)
Print #1, "2 " & Text1(2)
Print #1, "3 " & Text1(3)
Print #1, "4 " & Text1(4)
Close
End Sub
Private Sub Command2_Click()
Dim temp As String, i As Integer
On Error GoTo hh
Open "D:\result.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, temp
i = i + 1
Text1(i) = Trim(Right(temp, Len(temp) - InStr(temp, " ")))
Loop
Close
Exit Sub
hh:
MsgBox "Error"
End Sub
这个··不用ini文件读写的吧··那个太复杂而且不大好,因为是以键和键值表示的···其实只要写到txt文件中去就好了的么···我这里用控件数组表示你的Text,比较方便···
Private Sub Command1_Click()
Open "D:\result.txt" For Output As #1'这里写自己要保存的地址
Print #1, "1 " & Text1(1)
Print #1, "2 " & Text1(2)
Print #1, "3 " & Text1(3)
Print #1, "4 " & Text1(4)
Close
End Sub
Private Sub Command1_Click()
Dim temp As String, i As Integer
On Error GoTo hh
Open "C:\result.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, temp
i = i + 1
Text1(i) = Trim(Left(temp, Len(temp) - InStr(i, " ")))
Loop
Close
Exit Sub
hh:
MsgBox "Error"
End Sub
多加分啊···呼呼··
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用存取ini文件方式比较轻松些:
'WritePrivateProfileStringA: 如果成功返回非 0 值,失败返回 0
'lpApplicationName: 要写入的段 (Section) 名称
'lpKeyName: 要写入的的键 (Key) 名称
'lpString: 要写入的值 (Value),以字符串表示
'lpFileName: 指定要写的 INI 文件名
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
'GetPrivateProfileStringA: 返回所读取的字符串值的真实长度
'lpApplicationName: 要读取的段 (Section) 名称
'lpKeyName: 要读取的的键 (Key) 名称
'lpDefault: 指定默认值,如果读取时出错,则返回该值
'lpReturnedString: 指定接收返回值的字符串变量
'nSize: 指定允许字符串值的最大长度
'lpFileName: 指定要读的 INI 文件名
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
Public Sub WriteGoIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Dim buff As String * 128
buff = Value + Chr(0)
WritePrivateProfileString Section, Key, buff, FileName
End Sub
Public Function ReadGoIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As String
Dim i As Long
Dim buff As String * 128
GetPrivateProfileString Section, Key, "", buff, 128, FileName
i = InStr(buff, Chr(0))
ReadGoIni = Trim(Left(buff, i - 1))
End Function
==================
存入格式:
[TXTSTR]
t1=?
t2=?
t3=?
t4=?
==================
使用方法:
写入:WriteGoIni "C:\1.txt", "TXTSTR", "t1", text1.text
WriteGoIni "C:\1.txt", "TXTSTR", "t2", text2.text
读取:text1.text=ReadGoIni("C:\1.txt", "TXTSTR", t1)
text2.text=ReadGoIni("C:\1.txt", "TXTSTR", t2)
'WritePrivateProfileStringA: 如果成功返回非 0 值,失败返回 0
'lpApplicationName: 要写入的段 (Section) 名称
'lpKeyName: 要写入的的键 (Key) 名称
'lpString: 要写入的值 (Value),以字符串表示
'lpFileName: 指定要写的 INI 文件名
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
'GetPrivateProfileStringA: 返回所读取的字符串值的真实长度
'lpApplicationName: 要读取的段 (Section) 名称
'lpKeyName: 要读取的的键 (Key) 名称
'lpDefault: 指定默认值,如果读取时出错,则返回该值
'lpReturnedString: 指定接收返回值的字符串变量
'nSize: 指定允许字符串值的最大长度
'lpFileName: 指定要读的 INI 文件名
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
Public Sub WriteGoIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Dim buff As String * 128
buff = Value + Chr(0)
WritePrivateProfileString Section, Key, buff, FileName
End Sub
Public Function ReadGoIni(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As String
Dim i As Long
Dim buff As String * 128
GetPrivateProfileString Section, Key, "", buff, 128, FileName
i = InStr(buff, Chr(0))
ReadGoIni = Trim(Left(buff, i - 1))
End Function
==================
存入格式:
[TXTSTR]
t1=?
t2=?
t3=?
t4=?
==================
使用方法:
写入:WriteGoIni "C:\1.txt", "TXTSTR", "t1", text1.text
WriteGoIni "C:\1.txt", "TXTSTR", "t2", text2.text
读取:text1.text=ReadGoIni("C:\1.txt", "TXTSTR", t1)
text2.text=ReadGoIni("C:\1.txt", "TXTSTR", t2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询