We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compile Extension
#10
You can test the extension dll for linereader I already sent you in standard Small Basic.

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)
Reply


Messages In This Thread
Compile Extension - by z-s - 03-16-2024, 02:49 PM
RE: Compile Extension - by litdev - 03-16-2024, 03:19 PM
RE: Compile Extension - by z-s - 03-17-2024, 06:01 AM
RE: Compile Extension - by litdev - 03-17-2024, 10:48 AM
RE: Compile Extension - by z-s - 03-17-2024, 11:00 AM
RE: Compile Extension - by litdev - 03-17-2024, 12:10 PM
RE: Compile Extension - by z-s - 03-17-2024, 03:06 PM
RE: Compile Extension - by litdev - 03-17-2024, 03:40 PM
RE: Compile Extension - by z-s - 03-17-2024, 04:28 PM
RE: Compile Extension - by litdev - 03-17-2024, 05:12 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)