| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1023 人关注过本帖
标题:[求助]斑主及各位高手请进
只看楼主 加入收藏
headbegger
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-4-30
收藏
 问题点数:0 回复次数:1 
[求助]斑主及各位高手请进

下面是我做的一个简单程序,请各位高手帮我看看我该怎么办。在窗体上添加三个命令按钮,名称及Caption为CmdNewFile,"新建";CmdOpenFile,"打开";CmdAddRecord,"添加"。添加两个CommonDialog控件,名称为Dlg1,Dlg2,添加一个文本框控件Text1,一个组合框控件Combo1。 我的程序是运行后单击CmdNewFile新建(或单击CmdOpenFile打开)一磁盘随机文件,然后可通过单击CmdAddRecord按钮向文件添加记录,并将记录的.part元素与组合框的.Text比较,如果不相同则向组合框添加项目,如果相同则不添加。我的问题是程序运行新建一随机文件后,运行中添加记录,组合框添加项目一切正常,但结束程序后重新运行程序,用单击CmdOpenFile打开刚才创建的文件,组合框添中项目时不论相同与否却全部重复添加,即记录的.part元素与组合框的.Text比较结果都是False。我无法理解,更不明白这是为什么,请各位帮我分析一下。不胜感激! Option Explicit Private Type brakeAtt Name As String * 20 Part As String * 10 End Type

Dim Sbrake As brakeAtt '自定义记录类型变量 Dim Brakefilenum As Integer '文件号 Dim SrecordLen As Long '记录长度 Dim CurrentBrake As Long '当前记录号的变量 Dim LastBrake As Long '最后记录号的变量 Dim PresentfileName As String '现存文件名及路径

Private Sub SaveCurrentBrake() With Sbrake .Name = Text1.Text .Part = Combo1.Text End With '将变量sbrake的内容写入当前记录 Put #Brakefilenum, CurrentBrake, Sbrake End Sub

Private Sub OpenFile() Brakefilenum = FreeFile SrecordLen = Len(Sbrake) Open PresentfileName For Random As Brakefilenum Len = SrecordLen CurrentBrake = 1 LastBrake = LOF(Brakefilenum) / SrecordLen End Sub

Private Sub Showcurrentbrake() Get #Brakefilenum, CurrentBrake, Sbrake '将变量sbrake的值赋给控件显示 Text1.Text = Trim(Sbrake.Name) Combo1.Text = Trim(Sbrake.Part) End Sub

Private Sub ShowCurrentPart() '向组合框添加项目 Dim i As Integer Dim j As Integer For i = 1 To LastBrake Get #Brakefilenum, i, Sbrake For j = 0 To Combo1.ListCount - 1 If Trim(Sbrake.Part) = Trim(Combo1.List(j)) Then Exit For '比较 Next j If j = Combo1.ListCount Then Combo1.AddItem Trim(Sbrake.Part) '添加项目 End If Next i End Sub

Private Sub CmdAddRecord_Click() '文件添加记录 Dim i As Integer Dim k As Integer k = LOF(Brakefilenum) / SrecordLen For i = 1 To k Get Brakefilenum, i, Sbrake If Trim(Sbrake.Name) = Trim(Text1.Text) And Trim(Sbrake.Part) = Trim(Combo1.Text) Then Exit For Next i If i = k + 1 Then LastBrake = LastBrake + 1 '增加一条空白记录 CurrentBrake = LastBrake SaveCurrentBrake '保存当前记录 ElseIf i < k + 1 Then MsgBox "不允许存在同名且位置相同的记录,请重新添加。", vbCritical, "提醍您!" Exit Sub End If

ShowCurrentPart '将输入窗口置空 Text1.Text = "" Combo1.Text = "" Text1.SetFocus End Sub

Private Sub CmdNewFile_Click() On Error GoTo err Dim ans As Integer ans = 0 If Me.Caption <> "记录管理" Then ans = MsgBox("您确定要保存并退出" & PresentfileName & "吗?", vbOKCancel, "提醍您!") If ans = 2 Then Exit Sub ElseIf ans = 1 Then Combo1.Clear Close Me.Caption = "记录管理" End If Dlg2.FileName = "NewRecord" Dlg2.DialogTitle = "选择您要保存的位置" Dlg2.Filter = "记录文件*.hgq|*.hgq" Dlg2.Flags = cdlOFNOverwritePrompt '同名时询问是否替换 Dlg2.ShowSave

PresentfileName = Dlg2.FileName Call OpenFile Me.Caption = Me.Caption & PresentfileName err:

End Sub

Private Sub CmdOpenFile_Click() On Error GoTo err Dim ans As Integer Dim i As Integer, j As Integer ans = 0 If Me.Caption <> "记录管理" Then ans = MsgBox("您确定要保存并退出" & PresentfileName & "吗?", vbOKCancel, "提醍您!") If ans = 2 Then Exit Sub ElseIf ans = 1 Then Combo1.Clear Close Me.Caption = "记录管理" End If

Dlg1.FileName = "" Dlg1.Filter = "记录文件(*.hgq)|*.hgq" Dlg1.DialogTitle = "打开记录文件(.hgq)" Dlg1.Flags = 4096 Dlg1.ShowOpen PresentfileName = Dlg1.FileName

Call OpenFile Me.Caption = Me.Caption & PresentfileName

Showcurrentbrake ShowCurrentPart err: End Sub

Private Sub Form_Load() Me.Caption = "记录管理" End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Text1.Enabled = IIf(Me.Caption = "记录管理", False, True) Combo1.Enabled = Text1.Enabled CmdAddRecord.Enabled = IIf(Text1.Text = "" Or Combo1.Text = "", False, True) End Sub

Private Sub Form_Unload(Cancel As Integer) Close End Sub

搜索更多相关主题的帖子: Combo1 文本框 Text1 记录 
2004-05-26 22:49
firechun
Rank: 1
等 级:新手上路
帖 子:135
专家分:0
注 册:2004-4-13
收藏
得分:0 
不懂你的意思。

本人在编程中国发表的所有文章,除特别说明外均属原创,转载时请注明作者编程中国
2004-05-27 09:26
快速回复:[求助]斑主及各位高手请进
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018906 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved