⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbtips08.htm

📁 所有我收藏的VB技巧
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>vbtips08</title>
</head>

<body>

<h1 align="center"><a name="home"></a>VB技巧(8)</h1>

<blockquote>
    <p><strong>1、</strong><a href="#tips00"><strong>从全路径名中提取文件名</strong></a><strong><br>
    2、</strong><a href="#tips01"><strong>把文件置入到Text或RichText中</strong></a><strong><br>
    3、</strong><a href="#tips02"><strong>目录所占的字节数</strong></a><strong><br>
    4、</strong><a href="#tips03"><strong>打开 Win95
    的创建快捷方式窗口</strong></a><strong><br>
    5、</strong><a href="#tips04"><strong>显示盘中所有的目录</strong></a><strong><br>
    6、</strong><a href="#tips05"><strong>取得长文件名</strong></a></p>
    <div align="center"><center><table border="0" cellspacing="1"
    width="88%">
        <tr>
            <td width="80%"><p align="left"><a
            href="vbtips.htm#Return">[1]</a> <a
            href="vbtips1.htm">[2]</a> <a href="vbtips2.htm">[3]</a>
            <a href="vbtips3.htm">[4]</a> <a href="vbtips4.htm">[5]</a>
            <a href="vbtips5.htm">[6]</a> <a href="vbtips7.htm">[7]</a>
            [8] <a href="vbtips9.htm">[9]</a> <a
            href="vbtips10.htm">[10]</a></p>
            </td>
            <td><p align="right"><font size="2">第八页(共十页)</font></p>
            </td>
        </tr>
    </table>
    </center></div>
</blockquote>

<hr>
<div align="center"><center>

<table border="0" cellspacing="1" width="88%">
    <tr>
        <td width="100%"><a name="tips00"></a><strong>从全路径名中提取文件名</strong><br>
        Function StripPath(T$) As String<br>
        Dim x%, ct%<br>
        StripPath$ = T$<br>
        x% = InStr(T$, &quot;\&quot;)<br>
        Do While x%<br>
        ct% = x%<br>
        x% = InStr(ct% + 1, T$, &quot;\&quot;)<br>
        Loop<br>
        If ct% &gt; 0 Then StripPath$ = Mid$(T$, ct% + 1)<br>
        End Function<br>
        例子:<br>
        File = StripPath(&quot;c:\windows\hello.txt&quot;)<br>
        <a href="#home">返回</a><p><a name="tips01"></a><strong>把文件置入到Text或RichText中</strong><br>
        dim sFile as string<br>
        'Set sFile equal to your filename<br>
        dim i as long<br>
        <br>
        i = freefile()<br>
        <br>
        open sFile for input as #i<br>
        txtMain.text = input$(i,LOF(i))<br>
        close #1<br>
        <a href="#home">返回</a></p>
        <p><a name="tips02"></a><strong>目录所占的字节数</strong><br>
        该函数返回目录使用的字节数:<br>
        <br>
        Function DirUsedBytes(ByVal dirName As String) As Long<br>
        Dim FileName As String<br>
        Dim FileSize As Currency<br>
        If Right$(dirName, 1) &lt;&gt; &quot;\&quot; Then<br>
        &nbsp;&nbsp;&nbsp; dirName = dirName &amp; &quot;\&quot; <br>
        Endif<br>
        FileSize = 0<br>
        FileName = Dir$(dirName &amp; &quot;*.*&quot;)<br>
        Do While FileName &lt;&gt; &quot;&quot;<br>
        &nbsp;&nbsp;&nbsp; FileSize = FileSize + _<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        FileLen(dirName &amp; FileName)<br>
        &nbsp;&nbsp;&nbsp; FileName = Dir$<br>
        Loop<br>
        DirUsedBytes = FileSize<br>
        使用:<br>
        MsgBox DirUsedBytes(<code>&quot;C:\Windows&quot;</code>)<br>
        <a href="#home">返回</a></p>
        <p><a name="tips03"></a><strong>打开 Win95
        的创建快捷方式窗口</strong><br>
        以下的代码演示了如何利用 Win95 的 Wizard
        在指定的目录中建立快捷方式。<br>
        <br>
        Dim X As Integer<br>
        X = Shell(&quot;C:\WINDOWS\rundll32.exe
        AppWiz.Cpl,NewLinkHere &quot; &amp; App.Path &amp;
        &quot;\&quot;, 1)<br>
        <a href="#home">返回</a></p>
        <p><a name="tips04"></a><strong>显示盘中所有的目录</strong><br>
        以下的代码把盘中所有的目录都显示在DriveListBox
        和一个Listbox&nbsp;中。需要一个 如果
        DirListBox 隐藏的话,处理可以快一些。<br>
        <br>
        Dim iLevel As Integer, iMaxSize As Integer<br>
        Dim i As Integer, j As Integer<br>
        ReDim&nbsp; iDirCount(22) As Integer <br>
        '最大 22 级目录<br>
        ReDim sdirs(22, 1) As String<br>
        'drive1 是 DriveListBox 控件<br>
        'dir1 是 DirListBox 控件<br>
        iLevel = 1<br>
        iDirCount(iLevel) = 1<br>
        iMaxSize = 1<br>
        sdirs(iLevel, iDirCount(iLevel)) =&nbsp;
        Left$(drive1.Drive, 2) &amp; &quot;\&quot;<br>
        Do&nbsp;&nbsp;&nbsp; <br>
        iLevel = iLevel + 1<br>
        iDirCount(iLevel) = 0<br>
        For j = 1 To iDirCount(iLevel - 1)<br>
        &nbsp;&nbsp;&nbsp; dir1.Path = sdirs(iLevel - 1, j)<br>
        &nbsp;&nbsp;&nbsp; dir1.Refresh<br>
        &nbsp;&nbsp;&nbsp; If iMaxSize &lt; (iDirCount(iLevel) +
        dir1.ListCount) Then<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve
        sdirs(22, iMaxSize + dir1.ListCount + 1) As String<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iMaxSize =
        dir1.ListCount + iDirCount(iLevel) + 1<br>
        &nbsp;&nbsp;&nbsp; End If<br>
        &nbsp;&nbsp;&nbsp; For i = 0 To dir1.ListCount - 1<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        iDirCount(iLevel) = _<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        iDirCount(iLevel) + 1 &nbsp;&nbsp;&nbsp; '子目录记数<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdirs(iLevel,
        iDirCount(iLevel)) = dir1.List(i)<br>
        &nbsp;&nbsp;&nbsp; Next i<br>
        Next j<br>
        '所有名称放到 List1 中<br>
        list1.Clear<br>
        If iDirCount(iLevel) = 0 Then<br>
        '如果无自目录<br>
        &nbsp;&nbsp;&nbsp; For i = 1 To iLevel<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For j = 1 To
        iDirCount(i)<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        list1.AddItem sdirs(i, j)<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next j<br>
        &nbsp;&nbsp;&nbsp; Next i<br>
        &nbsp;&nbsp;&nbsp; Exit Do<br>
        End If<br>
        Loop <br>
        <a href="#home">返回</a></p>
        <p><a name="tips05"></a><strong>取得长文件名</strong><br>
        Public Function GetLongFilename (ByVal sShortName As
        String) As String<br>
        <br>
        Dim sLongName As String<br>
        Dim sTemp As String<br>
        Dim iSlashPos As Integer<br>
        <br>
        'Add \ to short name to prevent Instr from failing<br>
        sShortName = sShortName &amp; &quot;\&quot;<br>
        <br>
        'Start from 4 to ignore the &quot;[Drive Letter]:\&quot;
        characters<br>
        iSlashPos = InStr(4, sShortName, &quot;\&quot;)<br>
        <br>
        'Pull out each string between \ character for conversion<br>
        While iSlashPos<br>
        sTemp = Dir(Left$(sShortName, iSlashPos - 1), _<br>
        vbNormal + vbHidden + vbSystem + vbDirectory)<br>
        If sTemp = &quot;&quot; Then<br>
        'Error 52 - Bad File Name or Number<br>
        GetLongFilename = &quot;&quot;<br>
        Exit Function<br>
        End If<br>
        sLongName = sLongName &amp; &quot;\&quot; &amp; sTemp<br>
        iSlashPos = InStr(iSlashPos + 1, sShortName,
        &quot;\&quot;)<br>
        Wend<br>
        <br>
        'Prefix with the drive letter<br>
        GetLongFilename = Left$(sShortName, 2) &amp; sLongName<br>
        <br>
        End Function<br>
        <a href="#home">返回</a></p>
        </td>
    </tr>
</table>
</center></div>

<hr>
<div align="center"><center>

<table border="0" cellspacing="1" width="88%">
    <tr>
        <td width="80%"><p align="left"><a
        href="vbtips.htm#Return">[1]</a> <a href="vbtips1.htm">[2]</a>
        <a href="vbtips2.htm">[3]</a> <a href="vbtips3.htm">[4]</a>
        <a href="vbtips4.htm">[5]</a> <a href="vbtips5.htm">[6]</a>
        <a href="vbtips7.htm">[7]</a> [8] <a href="vbtips9.htm">[9]</a>
        <a href="vbtips10.htm">[10]</a></p>
        </td>
        <td><p align="right"><font size="2">第八页(共十页)</font></p>
        </td>
    </tr>
</table>
</center></div>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -