Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Today's featured TechNet Wiki article is from Nonki Takahashi:
Small Basic: How to Convert Multi-Line Text into Array of Lines
Small Basic can get multi-line text into a variable from multi-line input text box with Controls.GetTextBoxText() or from text file with File.ReadContents().
The following sample code shows how to convert a multi-line text into an array of lines.
CRLF ``= ``Text``.``GetCharacter``(``13``) ``+ ``Text``.``GetCharacter``(``10``)
GraphicsWindow``.``BackgroundColor ``= ``"LightGray"
GraphicsWindow``.``BrushColor ``= ``"Black"
gw ``= ``GraphicsWindow``.``Width
gh ``= ``GraphicsWindow``.``Height
tb ``= ``Controls``.``AddMultiLineTextBox``(``0``, ``0``)
Controls``.``SetSize``(``tb``, ``gw``, ``gh ``- ``30``)
Controls``.``AddButton``(``"Enter"``, ``gw ``- ``50``, ``gh ``- ``30``)
Controls``.``ButtonClicked ``= ``OnButtonClicked
Sub ``OnButtonClicked
``buf ``= ``Controls``.``GetTextBoxText``(``tb``)
``ConvertTextToLines``(``)
``ShowLines``(``)
EndSub
Sub ``ConvertTextToLines
``len ``= ``Text``.``GetLength``(``buf``)
``nLines ``= ``0
``ptr ``= ``1
``While ``ptr ``<``= ``len
``eol ``= ``Text``.``GetIndexOf``(``Text``.``GetSubTextToEnd``(``buf``, ``ptr``)``, ``CRLF``)
``If ``eol ``= ``0 ``Then ``' eol not found
``nLines ``= ``nLines ``+ ``1
``lines``[``nLines``] ``= ``Text``.``GetSubTextToEnd``(``buf``, ``ptr``)
``ptr ``= ``len ``+ ``1
``Else ``' eol found
``nLines ``= ``nLines ``+ ``1
``lines``[``nLines``] ``= ``Text``.``GetSubText``(``buf``, ``ptr``, ``eol ``- ``1``)
``ptr ``= ``ptr ``+ ``eol ``+ ``1
``EndIf
``EndWhile
EndSub
Sub ``ShowLines
``For ``i ``= ``1 ``To ``nLines
``TextWindow``.``WriteLine``(``"lines[" ``+ ``i ``+ ``"]: " ``+ ``lines``[``i``]``)
``EndFor
EndSub
Read the latest version of this TechNet Wiki article with an improved code block snippet here:
Small Basic: How to Convert Multi-Line Text into Array of Lines
Thanks again to Nonki for this great contribution!
- Ninja Ed
Comments
Anonymous
June 27, 2013
Hey Ed! Remember Me? Sorry for not posting here for awhile. Also I'm sorry for not doing the Coding Challenge we discussed. I have been real busy But I'm going to be on this site more often suggesting ideas and such. But I am going to play soccer during the summer/fall and some other sports so I might not post some days. Also I think it would be great to have SB being able to be used on this site (Link: roblox.com) It is a Gaming website where kids use programming to build games that others can play! I noticed it whenever I saw my Brother play it. It teaches Programming and it's for Kids just like SB is. It uses a language called Lua. I just wanted to bring that to your attention that other companies are basically doing the same Microsoft is! Sincerely, -Tim S. or "CodeWizardKid1"Anonymous
June 27, 2013
Hey Tim! Well, have a great summer!Anonymous
March 04, 2016
Help writing speed is to write test programs. drawn up displaying the text file is to write impersonated.