2014-09-04 44 views
0

我有一個問題,我需要從文本文件中讀取指定數量的字符,但指定的數量變化,所以我不能使用常量EG:vbs使用.Read()與變量不是一個整數

variable = WhateverIsSpecified 

strText = objFile.Read (variable) ' 1 ~ n+1 

objOutfile.write strText 

NOT

strText = objFile.Read (n)   ' n = any constant (interger) 

當使用第一種方式時,輸出爲空(在輸出文件中沒有字符)

預先感謝

UPDATE

這些是主要的片段中的時間長一點代碼

Set file1 = fso.OpenTextFile(file) 

Do Until file1.AtEndOfStream 
    line = file1.ReadLine 

    If (Instr(line,"/_N_") =1) then 
     line0 = replace(line, "/", "%")          
     filename = file1.Readline 
     filename = Left(filename, len(filename)-3) & "arc" 
     Set objOutFile = fso.CreateTextFile(destfolder & "\" & filename) 
     For i = 1 to 5 
      line = file1.Readline 
     next 
     nBytes = line  'this line contains the quantity needed to be read eg 1234 

     Do until Instr(line,"\") > 0 
      line = file1.ReadLine 
     Loop 


     StrData = ObjFile.Read (nBytes) 
     objOutFile.Write StrData 
     objOutFile.close 
    End if 
Loop 

WScript.quit 
+0

你能告訴我們你所有的代碼嗎? – aphoria 2014-09-04 18:54:41

回答

0

我自己的愚蠢錯誤,

StrData = ObjFile.Read (nBytes) 

應該

StrData = file1.Read (nBytes) 
+0

'Option Explicit'可以捕獲像這樣的情況:) – Matt 2014-09-05 21:30:00