田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论



iTextSharp_PDF加文字 VB.net 获取系统空闲时间,系统运行时间,无操作时间
未知 VB6 ComboBox 记录打开文件历史记录   [ 日期:2014-05-13 ]   [ 来自:本站原创 ]  HTML
'文件的读写
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim FSO As Object
Dim FSO_File As Object
Sub SaveFileHistory()
    Dim J As Integer
    Dim Temp As Boolean
    Temp = False '不存在此条记录
    '如果不为空,则判断该记录是否已经存在
    If Combo1.ListCount <> 0 Then
        For J = 0 To Combo1.ListCount - 1
            '如果该记录存在,没有必要再循环下去,直接退出for循环
            If Combo1.Text = Combo1.List(J) Then
                Temp = True ' 存在此条记录
                Exit For
            End If
        Next J
    ElseIf Combo1.ListCount = 0 Then
        Combo1.AddItem Combo1.Text '如果记录为零则直接添加
    End If
    If Temp = False Then
        Set FSO_File = FSO.OpenTextFile(App.Path + "\Path.txt", ForAppending, True)
        FSO_File.WriteLine Combo1.Text
        FSO_File.Close
    End If
End Sub
'打开文件记录
Private Sub Command2_Click()
    CommonDialog1.CancelError = True
    
    On Error GoTo ErrHandler ' 设置标志
    
    CommonDialog1.DialogTitle = "打开JPG文件"  '打开对话框的标题
    CommonDialog1.FileName = ""    '初始化所选文件名
    CommonDialog1.Filter = "可执行文件(.JPG)|*.JPG" '文件过滤器,限制打开文件类型
    CommonDialog1.ShowOpen  '显示打开对话框
    Me.Combo1.Text = CommonDialog1.FileName  '打开选择的可执行文件
    
    SaveFileHistory ' 保存历史记录
    
ErrHandler:      ' 用户按了"取消"按钮
    Exit Sub
End Sub

Private Sub Form_Load()
    '读取历史记录到下拉列表
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set FSO_File = FSO.OpenTextFile(App.Path + "\Path.txt", ForReading, True)
    Do While Not FSO_File.AtEndOfStream
        Combo1.AddItem FSO_File.ReadLine
    Loop
    FSO_File.Close
    Combo1.Text = Combo1.List(0)
End Sub


【VB6 ComboBox 记录打开文件历史记录.zip】点击下载此文件



引用这个评论 tiancao1001 于 2014-05-13 01:48 PM 发表评论: 
使用 Scripting.FileSystemObject 续写文件,不能对历史记录进行清理,记录降越来越多。

发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*6=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©