03-17-2024, 05:12 PM
You can test the extension dll for linereader I already sent you in standard Small Basic.
Look at the C# extension code:
When you test it in SB you will find that it does exactly the same as the text2 code below, which concatenates the lines to a single string with newline character.
Look at the C# extension code:
Code:
public static Primitive ReadLines(Primitive filePath, Primitive startLine, Primitive endLine)
{
if (!System.IO.File.Exists(filePath))
{
throw new FileNotFoundException("File not found", filePath);
}
if (startLine < 1 || endLine < 1 || endLine < startLine)
{
throw new ArgumentException("Invalid line numbers");
}
using (StreamReader reader = new StreamReader(filePath))
{
string line;
string result = "";
int currentLine = 0;
while ((line = reader.ReadLine()) != null && currentLine < endLine)
{
currentLine++;
if (currentLine >= startLine)
{
result += line + Environment.NewLine;
}
}
return result;
}
}
}
When you test it in SB you will find that it does exactly the same as the text2 code below, which concatenates the lines to a single string with newline character.
Code:
xmlFile = "C:\Program Files (x86)\Microsoft\Small Basic\SmallBasicLibrary.xml"
text1 = ZSLineReader.ReadLines(xmlFile,3,5)
TextWindow.WriteLine(text1)
TextWindow.WriteLine("================================================")
text2 = ""
For i = 3 To 5
text2 = Text2 + File.ReadLine(xmlFile,i)+Text.GetCharacter(10)
EndFor
TextWindow.WriteLine(text2)