I am so new to xojo scripting I simply don’t know and can’t seem to find out; how do I reference a line at a time in a method with scripting language?
just what do you mean…
if so… you dont’… and shouldn’t…
dim code as string = Text
dim codeLines() as string = code.Split( EndOfLine )
I mean in the IDE script I am creating, If I assume that all the text,lines, etc in the module can be referenced by refering to the word Text, can I do this?
dim x as integer
if x <> -1 then
I want to be able to replace any matching string I give it with something else. The ReformatCode.xojo.script script works fine, but I want to create a simple script that only replaces certain instances of words with something else. If I am somehow referring to all lines of code in my method by using the word Text, then how can I specify the line I’m on?
By the way the above code does not work it gives me Compiler error (87).
Might I suggest you grab this https://github.com//ReformatCode
Either alter the source and add your personal additions to RC_ReplaceList() on line 25 or add the following string constant to your app:
Inside that string constant write
and the alterations will be picked up automagically
Oops, I forgot to answer your actual question. Unfortunately the reformat code script can’t reference anything outside of the line or code block that it’s currently working on. Also, there’s currently a bug (<https://xojo.com/issue/52343>) so you can’t even reference each line of a block that you’re processing (i.e. from a pasted chunk of code).
Thank you so much. I have been doing exactly that and it works beautifully, but I am trying to learn how to use this feature and it is pretty cryptic to me. I am attaching an image of the IDE. This is what thought you meant, but it doesn’t work for me, or at least it doesn’t change anything. What I am confused about now is if I create a new script with only the word ReplaceWords in it, am I doing it correctly? Will putting this constant in my app take care of it or do I have to mention it in my script?
As you can see I tried to insert the image but I don’t know how to change the path to my Desktop. If it doesn’t ask me to upload or drag and drop I don’t know how to get it on the page. When I tried to drag it, it took over the entire window and wouldn’t let me do anything else.
Try dragging it into this page, then pasting the link in here:
as long as there’s nothing private in there of course.
Wow round about, but it works. Thanks. Now lets see if you can help after looking at this.
Here you go
Where you have written string in default value just type
Then then you type hello it will replace it with world
If you want more just add them with comma separation like:
Make sure there is always an even number of them. So the first is replaced with the second.
Here’s a link to my video about it
Amazing! If I can accomplish this feat with only a constant, why would I want to or need to use a script?
I’m sure there are plenty of reasons, I just can’t see one in this case. At least it is there if I need it. Can I create constants named UpperCase, TitleCase, etc?
Its only possible because Norman implemented it in the IDE so I could write that reformat code script
Technically ReplaceWords will work for changing the case too, so you could enter:
and it would change hello to HELLO and similarly for case
would change hello to HeLLo
Or had you some other method/system in mind?
Without Julian’s efforts here, you would be facing a IDE script exercise of near Herculean scope (okay, so maybe more Tom Sawyer-ish, but it would have still been a lot of work ).
Thanks guys, you all are awesome. I really appreciate your help!.