TextArea question

Hi Everyone! I’m new to Xojo and to programming, and would like to create some desktop tools to automate portions of my day-to-day work tasks. In particular, I’d like to create something like this:
https://www.zerosack.org/keyword_modifier_tool

Essentially, a keyword mod tool that can sit on the background of my desktop computer. When building out the program. I’m using the TextArea control.

I have a button, and in the Action I have
TextArea1.Text = “+” + TextArea1.Text

This works great for one keyword, but when I pasted in additional keywords from my clipboard it doesn’t work. I would like to read in multiple lines of keywords and also read for pairs split keywords (long tail keywords) like this:
first last
new old
middle
one two three

I would like the result to be:
+first +last
+new +old
+middle
+one +two +three

The link has this going to an input and output window. I was thinking it would be really cool to have the input window and output window or text area be the same window/textarea. So the when the button is pressed the keywords change into modified keywords with the plus signs in the same window.

My main question is–Is there a way of reading multiple lines and split text in the TextArea control or keyword? Or a way of sectioning lines in the TextArea?

I’m already trying work this out for looping the program–but am getting stuck on the syntax errors. I’m thinking something like this:
While Loop Until End of Character is read (still reading through the docs to figure out how to do this)
// loop to read if + is detected
If + then skip
end

        if no plus then add one in
              detect if any more words on the line
              add another plus sign to the second word or third works/etc...

         end

Please let me know if textarea isn’t the correct thing to use–I’ve tried text field–but it doesn’t allow for multiple lines. Any pointers to how I can work with text is really appreciated. Thanks!

Hi and welcome to Xojo! There are a number of great resources for beginners available :slight_smile:

First, if you’re an absolute beginner to programming, there’s the textbook. It teaches you to program as well as use Xojo at the same time. Great two-in-one system.

There’s also a manual that comes with Xojo that teaches you the ins and outs of using the IDE, the language, and the features within. You can find that in the Documentation folder next to your installation of Xojo. There’s also an online reference http://documentation.xojo.com

Lastly, when you’re ready to learn from examples, there’s a folder full of example projects next to your Xojo install called “Example Projects” It helps when you don’t intend to reinvent the wheel. Do not copy and paste code from example projects, that won’t help you at all.

Best of luck to you!

Look at the Split command. Transform your text into an array, add the “+” to each individual entry, then use Join to put them back into a string and put that into your TextArea. You might consider 2 loops, one to split on endofline, and then split each line on the space character.

Was feeling playful, so have a look at this https://www.dropbox.com/s/44aoqdp228l7ki1/Keywords.zip?dl=0

Left you a bit of cleaning up to do - remember: your source might not be nice and could even contain forbidden characters

Thanks Tim! I didn’t know there were additional docs! It’s super helpful!

Thanks TIm H! I now have a ton of questions about the Split command!

Currently reading through the docs to better frame my questions :slight_smile: Any pointers to where I can find some examples about how transform my text into an array would be super helpful–I did find this post on the forum–but is strA a placeholder? Working through the coding but it doesn’t seem to store anything? Or maybe it needs to be initialized?

https://forum.xojo.com/4481-get-value-in-textarea-individually-line/0
// first, get the text into an array of lines:
dim lines() as String = ReplaceLineEndings(TextArea1.Text,EndOfLine).Split(EndOfLine)

// then make sure that there are at least 2 lines in the array so that they can be assigned (otherwise, one gets an outofBounds exception)
if lines.Ubount < 1 then
redim lines(1) // this gives us two lines (at index 0 and 1)
end

// now replace the lines
lines(0) = strA
lines(1) = strA

// and store it back in the textarea:
TextArea1.Text = Join (lines, EndOfLine)

Hi Markus! I would really like to see your example–but the link has a 404 error, or any pointers to how I can get something like this to work out would be greatly appreciated :slight_smile:

I had made a little change, and unlike previously Dropbox creates a completely separate link. Here it is again:

https://www.dropbox.com/s/fevjzberudd0ejp/Keywords.zip?dl=0

Wow! Thanks Markus! I totally need to read through more of the docs and get better with Xojo! Thanks for sharing the great example.

I had no idea that the Split command could be so useful!

For the cleaning up: have a look at the ReplaceAll and Trim functions …

P.S. Also the webinars can be very helpful: http://developer.xojo.com/webinars

Thanks! The webinars are really awesome!