编程论坛
400万+工程师在用
400万+工程师在用

电子发烧友网工程师

17年用户 16436经验值
擅长:可编程逻辑 MEMS/传感技术 测量仪表 模拟技术 控制/MCU RF/无线
私信 关注

CopyRecord、CopyTo 和 SaveToFile 方法范例 (VB)

2009-1-8 10:18

<p><font face="Verdana">CopyRecord、CopyTo 和 SaveToFile 方法范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例演示如何使用 Stream 或 Record 对象来创建文件副本。有一个副本创建到 Web 文件夹以用于 Internet 发布。显示的其他属性和方法包括 Stream Type、Open、LoadFromFile 和 Record Open。</p>
<p>Public Sub CopyRecordX()<br/>&nbsp;&nbsp;&nbsp; ' Declare variables<br/>&nbsp;&nbsp;&nbsp; Dim strPicturePath, strStreamPath, strStream2Path, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strRecordPath, strStreamURL, strRecordURL As String<br/>&nbsp;&nbsp;&nbsp; Dim objStream, objStream2 As Stream<br/>&nbsp;&nbsp;&nbsp; Dim objRecord As Record<br/>&nbsp;&nbsp;&nbsp; Dim objField As Field<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Instantiate objects<br/>&nbsp;&nbsp;&nbsp; Set objStream = New Stream<br/>&nbsp;&nbsp;&nbsp; Set objStream2 = New Stream<br/>&nbsp;&nbsp;&nbsp; Set objRecord = New Record<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Initialize path and URL strings<br/>&nbsp;&nbsp;&nbsp; strPicturePath = _<br/>&nbsp;&nbsp;&nbsp; "C:\Program Files\microsoft Office\Clipart\Popular\Checkmrk.wmf"<br/>&nbsp;&nbsp;&nbsp; strStreamPath = "\\websrv\folder\mywmf.wmf"<br/>&nbsp;&nbsp;&nbsp; strStreamURL = "URL=http://websrv/folder/mywmf.wmf"<br/>&nbsp;&nbsp;&nbsp; strStream2Path = "D:\samples\check2.wmf"<br/>&nbsp;&nbsp;&nbsp; strRecordPath = "\\websrv\folder\mywmf.wmf"<br/>&nbsp;&nbsp;&nbsp; strRecordURL = "http://websrv/folder/mywmf.wmf"<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Load the file into the stream<br/>&nbsp;&nbsp;&nbsp; objStream.Open<br/>&nbsp;&nbsp;&nbsp; objStream.Type = adTypeBinary<br/>&nbsp;&nbsp;&nbsp; objStream.LoadFromFile (strPicturePath)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Save the stream to a new path and filename<br/>&nbsp;&nbsp;&nbsp; objStream.SaveToFile strStreamPath, adSaveCreateOverWrite<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Copy the contents of the first stream to a second stream<br/>&nbsp;&nbsp;&nbsp; objStream2.Open<br/>&nbsp;&nbsp;&nbsp; objStream2.Type = adTypeBinary<br/>&nbsp;&nbsp;&nbsp; objStream.CopyTo objStream2<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Save the second stream to a dIFferent path<br/>&nbsp;&nbsp;&nbsp; objStream2.SaveToFile strStream2Path, adSaveCreateOverWrite<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Because strStreamPath is a Web Folder, open a Record on the URL<br/>&nbsp;&nbsp;&nbsp; objRecord.Open "", strStreamURL<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' display the Fields of the record<br/>&nbsp;&nbsp;&nbsp; For Each objField In objRecord.Fields<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; debug.Print objField.Name &amp; ": " &amp; objField.Value<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Copy the record to a new URL<br/>&nbsp;&nbsp;&nbsp; objRecord.CopyRecord "", strRecordURL, , , adCopyOverWrite<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Load each copy of the graphic into Image controls for viewing<br/>&nbsp;&nbsp;&nbsp; Image1.Picture = LoadPicture(strPicturePath)<br/>&nbsp;&nbsp;&nbsp; Image2.Picture = LoadPicture(strStreamPath)<br/>&nbsp;&nbsp;&nbsp; Image3.Picture = LoadPicture(strStream2Path)<br/>&nbsp;&nbsp;&nbsp; Image4.Picture = LoadPicture(strRecordPath)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Clean up<br/>&nbsp;&nbsp;&nbsp; objStream.Close<br/>&nbsp;&nbsp;&nbsp; objStream2.Close<br/>&nbsp;&nbsp;&nbsp; objRecord.Close<br/>End Sub</p>
<p></font>&nbsp;</p>

更多回帖

打开APP