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

📄 32.htm

📁 vb功能实例介绍。详细、很好的实例说明。
💻 HTM
字号:
<p>发送电子邮件附件</p>
<p></p>
<p></p>
<p></p>
<p>第二个标签页中有一个ListView控件,用来显示文件列表,以及一个按钮,用来保存附件。如下图所示:</p>
<p></p>
<p>在本示例程序中,我们对CMessage类的CreateFromText方法作了更新:</p>
<p></p>
<p>Dim strFileName    As String</p>
<p>Dim strAttachment  As String</p>
<p>Dim lngFileSize    As Long</p>
<p>Dim lngFirstBegin  As Long</p>
<p>Dim lngFullStrings As Long</p>
<p></p>
<p>Const ENCODED_LINE_LENGTH = 61</p>
<p>'</p>
<p>intPosA = 1</p>
<p>Do</p>
<p>   'Looking for the start marker - "begin "</p>
<p>   intPosA = InStr(intPosA, strMessage, vbCrLf & "begin ") + 2</p>
<p>   'Exit from the loop if it hasn't found</p>
<p>   If intPosA = 2 Then Exit Do</p>
<p>   'remember the position of the first marker</p>
<p>   If lngFirstBegin = 0 Then lngFirstBegin = intPosA - 2</p>
<p>   'looking for the end of string the marker belongs to</p>
<p>   intPosB = InStr(intPosA + 1, strMessage, vbCrLf)</p>
<p>   If intPosB > 0 Then</p>
<p>      'check whether it is real marker or just </p>
<p>      'an ordinal word "begin"</p>
<p>      If Mid$(strMessage, intPosA, _</p>
<p>         intPosB - intPosA) Like "begin ### *" Then</p>
<p>         'exctract the name of the file</p>
<p>         strFileName = Mid$(strMessage, intPosA + _</p>
<p>                       10, intPosB - intPosA - 10)</p>
<p>         '</p>
<p>         'further - the code for figuring out the size of the file</p>
<p>         'extract encoded data of the file</p>
<p>         strAttachment = Mid$(strMessage, intPosB + 2, _ </p>
<p>                         InStr(intPosB + 2, strMessage, _</p>
<p>                         vbCrLf & "'" & vbCrLf & "end") _</p>
<p>                         - (intPosB + 2))</p>
<p>         'remove additional symbols vbCrlf</p>
<p>         strAttachment = Replace(strAttachment, vbCrLf, "")</p>
<p>         '"temporary" size of the file</p>
<p>         lngFileSize = CLng(Len(strAttachment))</p>
<p>         'get the number of full strings</p>
<p>         lngFullStrings = lngFileSize \ ENCODED_LINE_LENGTH</p>
<p>         If lngFileSize Mod ENCODED_LINE_LENGTH > 0 Then</p>
<p>            'The size of the file is equal to</p>
<p>            'the sum of the two meanings</p>
<p>            'The first one multiplies to the number of _</p>
<p>            'decoded characters (45)</p>
<p>            'The second one is the number of the bytes _</p>
<p>            'in the last string. It equals</p>
<p>            'to the difference between the ASCII meaning _</p>
<p>            'of the fist character and 32</p>
<p>            lngFileSize = lngFullStrings * 45 + _</p>
<p>                          (Asc(Mid$(strAttachment, _</p>
<p>                          lngFullStrings * _</p>
<p>                          ENCODED_LINE_LENGTH + 1, 1)) - 32)</p>
<p>         Else</p>
<p>            'This code runs in very rare cases when _</p>
<p>            'the size of the file is multiple</p>
<p>            'to 45 and we don't need to process _</p>
<p>            'non-standard last string of the encoded data</p>
<p>            lngFileSize = (lngFileSize - _</p>
<p>                          lngFileSize / ENCODED_LINE_LENGTH) * 0.75</p>
<p>         End If</p>
<p>         'add new item into the mvarAttachments collection</p>
<p>         mvarAttachments.Add lngFileSize, strFileName</p>
<p>      End If</p>
<p>   End If</p>
<p>Loop</p>
<p>'separate the text of the message</p>
<p>If mvarAttachments.Count > 0 Then</p>
<p>   m_strMessageBody = Left$(lngFirstBegin - 1)</p>
<p>End If </p>
<p></p>
<p>上面的代码定义了文件名及其大小。这些信息保存在CAttachment对象中,当添中新的项目到mvarAttchments集合时,该对象即被创建。该集合是CMessage类的一个新的属性-Attachments。</p>
<p></p>
<p>下面是ListView控件的ItemClick事件中的代码:</p>
<p></p>
<p>Dim oAttachment As CAttachment</p>
<p>Dim lvItem As ListItem</p>
<p></p>
<p>lvAttachments.ListItems.Clear</p>
<p></p>
<p>For Each oAttachment In m_colMessages(Item.Key).Attachments</p>
<p>    Set lvItem = lvAttachments.ListItems.Add _</p>
<p>                 (, oAttachment.FileName, oAttachment.FileName)</p>
<p>    lvItem.SubItems(1) = oAttachment.Size</p>
<p>Next</p>
<p></p>
<p>txtBody = m_colMessages(Item.Key).MessageBody</p>
<p></p>
<p>End Sub</p>
<p></p>

⌨️ 快捷键说明

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