Small Basic Forum
Compile Extension - Printable Version

+- Small Basic Forum (https://litdev.uk/mybb)
+-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1)
+--- Forum: Discussion (https://litdev.uk/mybb/forumdisplay.php?fid=4)
+--- Thread: Compile Extension (/showthread.php?tid=40)



Compile Extension - z-s - 03-16-2024

Litdev Can You Compile This Extension : https://www.mediafire.com/file/vzf45xnmho7ga9u/ZSText.vb/file

And Can You Make An Extension Which Will In A File Read From Specific Line To Specific Line And Then Return It

And For Highlighting A Whole Line In Textbox When It Start With A Specific Character

And For Highlighting A Specific Text In Textbox Automatic


RE: Compile Extension - litdev - 03-16-2024

Hi,

There is more to it than in your vb, I would have to rewrite it.

Realistically, I'm not going to write/rewrite extensions for you to everything you want.

I could help you learn to do it, but that really would require you having access to Visual Studio.

One option for you is to look into LDInline - see the sample that comes with LitDev samples in other-samples/LDInline-Reflection.sb with cs and vb code used.  This can take extension code and compile it into a function to be used in SB.  However, writing the CS code required to do what you want will be a steep learning curve - probably harder than writing the program directly in VS, requiring the use of reflection delegates to interact with the GraphicsWindow for example.  PS, this method can also create extension dlls with xml intellisense - I forgot it could do that!

Also look into LDRichTextBox which can change individual word colours.  See sample in other-samples/RichTextBox.sb.

I don't think this can easiliy be done for a textbox, your vb looks like it is for a winform textbox, not wpf and changing the selection colour is the colour for overlay when a word is selected, see https://stackoverflow.com/questions/34666064/change-the-textbox-highlight-color-when-a-user-selects-text.


RE: Compile Extension - z-s - 03-17-2024

Can You Give From Where I Could Learn CSharp Or VB


RE: Compile Extension - litdev - 03-17-2024

Hi, There are plently online resources, but I believe it is essential to fist have access to Visual Studio.


RE: Compile Extension - z-s - 03-17-2024

I Use A 32 Bit Computer Windows 8.1 And 2gb RAM

I Have MSBuild Tool


RE: Compile Extension - litdev - 03-17-2024

Hi, I see the problem, perhaps Java or Python could be alternatives to look into, not for SB extensions but programming in general if the limitations of SB are too much.


RE: Compile Extension - z-s - 03-17-2024

Please can you compile line reader and highlighter extension for svb


RE: Compile Extension - litdev - 03-17-2024

Hi,

As I discussed:

1] The line reader can be done simply with existing SB methods - no need for extension.
2] The code you supplied for highlighting doesn't compile for SB or sVB, and if I corrected it the method you suggested only changes the highlight selection color (this is the background color when a user selects a bit of text), it does NOT set the font color of text - this CANNOT BE DONE for individual bits of text in a textbox.

These cannot help you with the language conversion project. I am unsure why you want this, rather than looking into how to perform the important functionality for this project with existing methods.

I can help you compile an extension yourself, or provide help with some of the suggestions I have made using for example LDInline, LDxml, LDConstrols.AddRichTextBox. I cannot write code for you, either extension or SB.


RE: Compile Extension - z-s - 03-17-2024

The code for line reader can not work in textbook if can please explain me and for highlighter leave it for now


RE: Compile Extension - litdev - 03-17-2024

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)