主题:[讨论]关于random文件,不能正常显示 加分
loongchina
[专家分:90] 发布于 2008-05-18 17:26:00
为什么我用 Open App.Path + "\录入的数据.txt" For Random As #1 Len = Len(didian)
record = LOF(1) / Len(didian) + 1
didian.j = Text10.Text
didian.vsp1 = Text1.Text
didian.ps1 = Text2.Text
didian.qn1 = Text3.Text
didian.vsp2 = Text4.Text
didian.ps2 = Text5.Text
didian.qn2 = Text6.Text
If flag = True Then
didian.vsp3 = Text7.Text
didian.ps3 = Text8.Text
didian.qn3 = Text9.Text
Else
didian.vsp3 = Text4.Text
didian.ps3 = Text5.Text
didian.qn3 = Text6.Text
End If
Put #1, record, didian
If tep < 23 Then
tep = tep + 1
Else
MsgBox "数据录入结束!", vbExclamation, "恭喜"
Close #1
End
End If
Close #1
写完文件后,显示却是乱码?
回复列表 (共10个回复)
沙发
loongchina [专家分:90] 发布于 2008-05-18 17:31:00
具体代码如下:
Public tep As Integer
Private Type data
j As String
vsp1 As String * 6
ps1 As String * 6
qn1 As String * 5
vsp2 As String * 6
ps2 As String * 6
qn2 As String * 5
vsp3 As String * 6
ps3 As String * 6
qn3 As String * 5
End Type
Private Sub Command1_Click()
Dim record As Integer
Dim didian As data
Dim t As Integer
If Command1.Caption = "开 始" Then
Command2.Enabled = f
Command1.Caption = "&确 定"
Command1.Default = True
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
Text7.Enabled = True
Text8.Enabled = True
Text9.Enabled = True
Text10.Text = CStr(tep)
Text1.SetFocus
Else
If Text1.Text = "" And Text2.Text = "" And Text3.Text = "" And Text4.Text = "" And Text5.Text = "" And Text6.Text = "" Then
t = MsgBox("该整点数据缺测吗?", vbYesNo, "提示")
If t = 7 Then
Text1.SetFocus
Exit Sub
End If
End If
Open App.Path + "\录入的数据.txt" For Random As #1 Len = Len(didian)
record = LOF(1) / Len(didian) + 1
didian.j = Text10.Text
didian.vsp1 = Text1.Text
didian.ps1 = Text2.Text
didian.qn1 = Text3.Text
didian.vsp2 = Text4.Text
didian.ps2 = Text5.Text
didian.qn2 = Text6.Text
If flag = True Then
didian.vsp3 = Text7.Text
didian.ps3 = Text8.Text
didian.qn3 = Text9.Text
Else
didian.vsp3 = Text4.Text
didian.ps3 = Text5.Text
didian.qn3 = Text6.Text
End If
Put #1, record, didian
If tep < 23 Then
tep = tep + 1
Else
MsgBox "数据录入结束!", vbExclamation, "恭喜"
Close #1
End
End If
Close #1
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = CStr(tep)
Text1.SetFocus
End If
End Sub
Private Sub Command2_Click()
flag = True
Label7.Visible = True
Text7.Visible = True
Text8.Visible = True
Text9.Visible = True
Command2.Enabled = f
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then
If IsNumeric(Text1.Text) = True Then
Text2.SetFocus
Else
MsgBox "请输入数字!", 48, "警告"
Text1.Text = ""
End If
End If
End Sub
请高人指教一二
板凳
老大徒伤悲 [专家分:29120] 发布于 2008-05-18 17:34:00
didian,是你自定义的数据类型。
其中每个元素你都定义成字符成,就没有这个问题了。
3 楼
老大徒伤悲 [专家分:29120] 发布于 2008-05-18 17:40:00
在一楼你的代码怎么一点注释都没有?
那些文本框都是做什么用的?
4 楼
loongchina [专家分:90] 发布于 2008-05-18 17:44:00
对啊 ,我原定义的都是string型啊,但是不能正常显示啊
5 楼
loongchina [专家分:90] 发布于 2008-05-18 17:46:00
是从键盘接收字符串的啊
6 楼
loongchina [专家分:90] 发布于 2008-05-18 17:47:00
你uc 或QQ 是多少啊?我可以加你吗?共同读讨论VB
7 楼
loongchina [专家分:90] 发布于 2008-05-18 17:48:00
本人是24小时在线的老爷们,呵呵
8 楼
老大徒伤悲 [专家分:29120] 发布于 2008-05-18 17:58:00
在我这里运行, Put #1, record, didian发生记录长度错误!建议去掉指定长度的子句。
这么些按钮为什么不给些好用的名字?
9 楼
guoyong_cy [专家分:3050] 发布于 2008-05-18 22:01:00
又不抓主要问题,老大徒伤悲又想误导人了!!
请问楼主,你是用什么方法查看你写的文件是乱码,不要说是用记事本哈......................
估计你是用的记事本
建议:你最好先明白文件到底是个什么东西,然后再写
10 楼
老大徒伤悲 [专家分:29120] 发布于 2008-05-19 08:31:00
感谢9楼,但没有办法,只能误导阿
不过好在他基本明白了。
你给他在详细说说,用变量写入文件,然后用字节方式读出来,怎么还原?
我也顺便得点益处。嘿嘿
我来回复