国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

開(kāi)發(fā)手記(九)——在文件菜單中記錄最近使用過(guò)的文件

2024-07-21 02:24:06
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
word的“文件”菜單最下面列出了最近使用過(guò)的文件名及路徑,文件名及路徑會(huì)隨著用戶(hù)的使用不斷地發(fā)生變化,這符合統(tǒng)計(jì)學(xué)中“最近使用”最大可能是“經(jīng)常使用”的原則,方便了用戶(hù),提高了效率。它的實(shí)現(xiàn)方法有很多,我舉一例,供大家參考。

      一、在工作目錄下創(chuàng)建一個(gè)lastfile.ini文件,其中第一行為歷史文件的總數(shù),以下行是歷史文件的全路徑。當(dāng)然您也可以使用數(shù)據(jù)表存儲(chǔ),那樣編程時(shí)也許更方便一些。

       lastfile.ini文件內(nèi)容如:4

"d:/程序?qū)嵗?slzj/slzj源代碼/2004.11.18水利造價(jià)/示例.mdb"

"c:/windows/desktop/111/111.mdb"

"d:/程序?qū)嵗?slzj/slzj源代碼/2004.11.18水利造價(jià)/示例.mdb"

"d:/程序?qū)嵗?slzj/slzj源代碼/2004.11.3/2004.11.3/2004.11.3/2004.11.3/示例(審查).mdb"

    二、在form_load中編寫(xiě)如下代碼,達(dá)到在文件菜單中顯示歷史文件的效果

'**************顯示以往打開(kāi)的文件記錄***************************

    '對(duì)配置文件不存在的情況下,作出操作。

    if dir(app.path & "/lastfile.ini") = "" then

        open app.path & "/lastfile.ini" for output as #1

        write #1, 0

        close #1

end if

'打開(kāi)lastfile.ini文件

    open app.path & "/lastfile.ini" for input as #1

    dim strlastfile2 as string

    '獲取歷史文件的數(shù)目

    line input #1, strlastfile2

    imaxlastfile = int(strlastfile2)

    dim i as integer

    '添加歷史文件到activebar菜單,先在activebar中預(yù)設(shè)4各command和一個(gè)分割線。并把他們的visible=false

    for i = 1 to imaxlastfile

        line input #1, strlastfile2

        strlastfile(i - 1) = mid(strlastfile2, 2, len(strlastfile2) - 2)‘去引號(hào)

        aabar.bands("menufile").tools.item(i + 10).caption = strlastfile(i - 1)

        aabar.bands("menufile").tools.item(i + 10).visible = true

    next

    '關(guān)閉文件

    close #1

    '設(shè)置分隔條

    if imaxlastfile <> 0 then

        aabar.bands("menufile").tools.item(15).visible = true

end if

三、在form_unload中添加如下代碼,將打開(kāi)文件記錄寫(xiě)入配置文件。

    open app.path & "/lastfile.ini" for output as #1

    dim i as integer

    write #1, imaxlastfile‘寫(xiě)入歷史文件總數(shù)

    for i = 0 to imaxlastfile - 1

        write #1, strlastfile(i)‘寫(xiě)入歷史文件路徑

    next

    close #1

四、在需要更新菜單中文件歷史記錄的地方使用下面函數(shù)(如:打開(kāi)一個(gè)文件,新建并打開(kāi)一個(gè)文件等)

private sub updatelastfile(byval strpath as string)

    on error goto saveerr:

    dim strduan as string

    strduan = strpath

    '判斷要添加的文件是否時(shí)列表中的第一個(gè)文件

    if strduan <> aabar.bands("menufile").tools.item(11).caption then

        '將列表中的文件依次下移一位,空出第一位

        dim i as integer

        for i = 3 to 1 step -1

            strlastfile(i) = strlastfile(i - 1)

            aabar.bands("menufile").tools.item(11 + i).caption = aabar.bands("menufile").tools.item(10 + i).caption

        next

        '將頭一位設(shè)置為當(dāng)前操作的文件路徑

        strlastfile(0) = strduan

        aabar.bands("menufile").tools.item(11).caption = strduan

        '如果列表文件數(shù)小于最大文件數(shù)則加一

        if imaxlastfile < 4 then

            imaxlastfile = imaxlastfile + 1

        end if

        '設(shè)置新移動(dòng)的列表項(xiàng)可見(jiàn)

        aabar.bands("menufile").tools.item(imaxlastfile + 10).visible = true

    end if

    '如果列表不為空則下方的分隔條可見(jiàn)

    if imaxlastfile <> 0 then

        aabar.bands("menufile").tools.item(15).visible = true

    else

        aabar.bands("menufile").tools.item(15).visible = false

    end if

    exit sub

saveerr:

    dbencrypt.saveerror "mdiform1-updatelastfile"

end sub

五、單擊文件歷史記錄時(shí)調(diào)用如下函數(shù)。

private sub menulastfile(byval strname as string, index as integer)

    on error goto saveerr:

    '如果文件已不存在則提示

    if dir(strname) = "" then

        msgbox "文件不存在,請(qǐng)確認(rèn)后再次打開(kāi)!", vbokonly + vbinformation, "打開(kāi)文件"

        exit sub

    end if

    '設(shè)置當(dāng)前打開(kāi)文件為列表中的選擇文件

    strconnection = strname

    '**************重新設(shè)置歷史文件列表順序*****************

    dim i as integer

    for i = index to 12 step –1 '把列表中選擇文件的位置之上的文件依次下移

        strlastfile(i - 11) = strlastfile(i - 12)

     aabar.bands("menufile").tools.item(i).caption= aabar.bands("menufile").tools.item(i - 1).caption

    next

    strlastfile(0) = strname

    '將選擇的文件的放在列表中的首位

    aabar.bands("menufile").tools.item(11).caption = strconnection

    closewnd‘自定義過(guò)程,用于關(guān)閉系統(tǒng)中打開(kāi)的除mdi窗口外的所有窗口

  

    strconnection = strname

    me.caption = "水利造價(jià)管理系統(tǒng)" & "-" & strconnection

    showmenu

    exit sub

saveerr:

    dbencrypt.saveerror "mdiform1-menulastfile"

end sub

private sub closewnd()

    on error goto saveerr:

    dim i as integer

    for i = forms.count - 1 to 1 step -1

        if forms(i).name <> "frmdaohang1" and forms(i).name <> "frmdaohang2" and forms(i).name <> "frmtoolsearch" then

            unload forms(i) '關(guān)閉到倒數(shù)第二個(gè)窗體

        end if

    next

    exit sub

saveerr:

    dbencrypt.saveerror "mdiform1-closewnd"

end sub

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 扶余县| 楚雄市| 天等县| 闵行区| 舞钢市| 伊春市| 舞阳县| 康乐县| 博客| 泰和县| 云安县| 云阳县| 宝坻区| 锡林浩特市| 隆德县| 文登市| 盐边县| 北宁市| 建德市| 乌兰浩特市| 万山特区| 那曲县| 蕉岭县| 鲜城| 肥乡县| 年辖:市辖区| 文成县| 方山县| 乡宁县| 昌乐县| 黔东| 甘泉县| 武胜县| 德州市| 正宁县| 寿宁县| 博野县| 汉阴县| 汉阴县| 保康县| 汝州市|