2014-04-16 2 views
1

파일을 읽고 내용을 표시하는 스크립트를 가져 오려고합니다. 그러나 창당 5 줄만 표시해야합니다. 파일 표시를 어떻게 제한 할 수 있습니까?Writeline/Readline

Set MyFile = fso.OpenTextFile(FileName, ForReading) 

Do While MyFile.AtEndOfStream <> True 
    TextLine = MyFile.ReadLine 
    MsgBox TextLine,0, "Student Information" 
Loop 
MyFile.Close  

해결책 :

나는 해결책을 가지고! 여기에는 다음과 같은 내용이 포함됩니다 :

Set MyFile = fso.OpenTextFile(FileName, ForReading) 

Do While MyFile.AtEndOfStream <> True 
     TextLine = textline & MyFile.ReadLine & VBCR 
     counter = counter + 1 
     if (counter mod 5 = 0) then 
     MsgBox TextLine,0, "Petar Moraliev" 
     textline = "" 
     end if 
    Loop 
    MsgBox TextLine,0, "Petar Moraliev" 
    MyFile.Close 

답변

0

파일의 각 행 범위를 저장하려면 cnLines (예 : 5) 요소의 배열이 필요합니다. 버퍼가 가득 찬 경우 출력 (예 : MsgBox)을 실행합니다. 마지막에 조심하십시오 : 버퍼에 여전히 라인이 있습니까? 코드에서

: (11 개 라인의 파일)

Option Explicit 

Const cnLines = 5 

Dim nUB : nUB  = cnLines - 1 
Dim tsIn : Set tsIn = CreateObject("Scripting.FileSystemObject").OpenTextFile(".\23117849.txt") 
Dim nIdx : nIdx  = nUB 
ReDim aLines(nUB) 

Do Until tsIn.AtEndOfStream 
    nIdx = (tsIn.Line - 1) Mod cnLines 
    aLines(nIdx) = tsIn.ReadLine() 
    If nIdx = nUB Then 
     WScript.Echo Join(aLines, " * ") ' MsgBox Join(aLines, vbCrLf) 
    End If 
Loop 
tsIn.Close 
If Not nIdx = nUB Then 
    ReDim Preserve aLines(nIdx) 
    WScript.Echo Join(aLines, " * ") ' MsgBox Join(aLines, vbCrLf) 
End If 

출력 :

cscript 23117849.vbs 
1 * 2 * 3 * 4 * 5 
6 * 7 * 8 * 9 * 10 
11 
+0

은 내가하지만 덕분에 많은 주위에 일이있어! 이것은 내가 가진 것입니다 : – Azyth

+0

설정을 MyFile = fso.OpenTextFile (파일 이름, ForReading) 마 MyFile.AtEndOfStream <> 진정한 TextLine입니다 = 텍스트 라인 및 MyFile.ReadLine & VBCR \t 카운터 = 카운터 + 1 \t 경우 (카운터 모드 동안 5 = 0) 다음 있는 MsgBox하는 TextLine 0 "페 타르 Moraliev" \t 요소는 텍스트 = "" \t 최종면 루프 있는 MsgBox하는 TextLine 0 "페 타르 Moraliev" MyFile.Close – Azyth