发 帖  
原厂入驻New

EOS 和 LineSeparator 属性、SkipLine 方法范例 (VB)

2009-1-8 10:19:43  2225
分享
<p><font face="Verdana">EOS 和 LineSeparator 属性、SkipLine 方法范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例演示如何每次操作一行文本流。范例显示了将分行符从默认的回车/换行 (adCRLF) 改成简单的换行 (adLF) 或回车 (adCR) 的效果。</p>
<p>Public Sub SkipLineX()<br/>&nbsp;&nbsp;&nbsp; 'Declare variables<br/>&nbsp;&nbsp;&nbsp; Dim i As Integer<br/>&nbsp;&nbsp;&nbsp; Dim objStream As Stream<br/>&nbsp;&nbsp;&nbsp; Dim strLine, strChar As String<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Instantiate and open stream<br/>&nbsp;&nbsp;&nbsp; Set objStream = New Stream<br/>&nbsp;&nbsp;&nbsp; objStream.Open<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Set line separator to line feed<br/>&nbsp;&nbsp;&nbsp; objStream.LineSeparator = adLF<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Load text content of list box into stream<br/>&nbsp;&nbsp;&nbsp; 'One line at a time<br/>&nbsp;&nbsp;&nbsp; For i = 0 To (List1.ListCount - 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objStream.WriteText List1.List(i), adWriteLine<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'display the entire stream<br/>&nbsp;&nbsp;&nbsp; debug.Print "Whole Stream:"<br/>&nbsp;&nbsp;&nbsp; objStream.Position = 0<br/>&nbsp;&nbsp;&nbsp; Debug.Print objStream.ReadText<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Display the first line<br/>&nbsp;&nbsp;&nbsp; Debug.Print "First Line:"<br/>&nbsp;&nbsp;&nbsp; objStream.Position = 0<br/>&nbsp;&nbsp;&nbsp; strLine = objStream.ReadText(adReadLine)<br/>&nbsp;&nbsp;&nbsp; Debug.Print strLine<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Line length: " + str(Len(strLine))<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Skip a line, then display another line<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Third Line:"<br/>&nbsp;&nbsp;&nbsp; objStream.SkipLine<br/>&nbsp;&nbsp;&nbsp; strLine = objStream.ReadText(adReadLine)<br/>&nbsp;&nbsp;&nbsp; Debug.Print strLine<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Line length: " + str(Len(strLine))<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Switch line separator to carriage return<br/>&nbsp;&nbsp;&nbsp; 'All items from list will be considered one line<br/>&nbsp;&nbsp;&nbsp; 'Assuming no CRs have been loaded into stream<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Whole Stream/First Line:"<br/>&nbsp;&nbsp;&nbsp; objStream.Position = 0<br/>&nbsp;&nbsp;&nbsp; objStream.LineSeparator = adCR<br/>&nbsp;&nbsp;&nbsp; strLine = objStream.ReadText(adReadLine)<br/>&nbsp;&nbsp;&nbsp; Debug.Print strLine<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Line length: " + str(Len(strLine))<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Stream size: " + str(objStream.Size)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'Use EOS to Determine End of Stream<br/>&nbsp;&nbsp;&nbsp; Debug.Print "Character by character:"<br/>&nbsp;&nbsp;&nbsp; objStream.Position = 0<br/>&nbsp;&nbsp;&nbsp; Do Until objStream.EOS<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strChar = objStream.ReadText(1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print strChar<br/>&nbsp;&nbsp;&nbsp; Loop<br/>End Sub</p>
<p></font>&nbsp;</p>
0
2009-1-8 10:19:43   评论 分享淘帖

只有小组成员才能发言,加入小组>>

135个成员聚集在这个小组

加入小组

创建小组步骤

关闭

站长推荐 上一条 /7 下一条

快速回复 返回顶部 返回列表