Love Gambas and it is working very well. I have some long SQL type statements, and my limited mind cannot figure out the best way to accomplish it without just multiple lines of SQLString = SQLString & xyz
SQLString = SQLString & abc
SQLString = SQLString & edf....
I tried the VB method of an Underscore following by the next line beginning with an & but that did not work. With all the ' ", ' " required to insert variables I am unsure as to how to elegantly split these up over multiple lines.
Thanks in advance for any help.
SOLVED: Multiline statement
SOLVED: Multiline statement
Last edited by CMWhitley on Thursday 9th September 2021 5:42pm, edited 1 time in total.
- BruceSteers
- Posts: 1572
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Multiline statement
There are these ways...CMWhitley wrote: ↑Thursday 9th September 2021 1:35pm Love Gambas and it is working very well. I have some long SQL type statements, and my limited mind cannot figure out the best way to accomplish it without just multiple lines of SQLString = SQLString & xyz
SQLString = SQLString & abc
SQLString = SQLString & edf....
I tried the VB method of an Underscore following by the next line beginning with an & but that did not work. With all the ' ", ' " required to insert variables I am unsure as to how to elegantly split these up over multiple lines.
Thanks in advance for any help.
SQLString &= "More text"
SQLString &= "Even More text"
or these methods will work as multiline...
SQLString = "some text\n" &
"some more text\n" &
"yet some more"
you can even omit the &Ie.
SQLString = "some text\n"
"some more text\n"
"yet some more"
Will workSimilar for commands/arrays using the comma ,
Ie..
MyCommand(arg1,
arg2,
arg3)
MyArray[Item1,
Item2,
Item3]
But note you will get problems with blank lines and positioning of ) ]
Ie.
Message.Question(
"My question"
)
that will fail.
Message.Question(
"My question")
will work
MyArray = [
Item1,
Item2
]
Will work
MyArray = [
Item1,
Item2
]
will fail
also when using multiline methods the IDE will loose the autocomplete ability when typing.
Last edited by BruceSteers on Thursday 9th September 2021 2:18pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Multiline statement
OK unthink that idea immediately. Its like trying to replace chocolate syrup with a sardine in a milkshake.CMWhitley wrote: ↑Thursday 9th September 2021 1:35pm Love Gambas and it is working very well. I have some long SQL type statements, and my limited mind cannot figure out the best way to accomplish it without just multiple lines of SQLString = SQLString & xyz
SQLString = SQLString & abc
SQLString = SQLString & edf...
I tried the VB method of an Underscore following by the next line beginning with an & but that did not work. With all the ' ", ' " required to insert variables I am unsure as to how to elegantly split these up over multiple lines.
I was sure that there is a page in the wiki about multi-line string constants but I can't see it. So,
In the IDE (or more specifically in the source code for a class) a string can be continued on the next line simply by making it like this:
Code: Select all
Dim sMary as "Mary had a little lamb, "
"So what, I hear you ask "
"I had a little omelet"
Now here is the bad news
You need to see the spaces!
If you try "SELECT *"
"FROM myStupidTable;"
You will get "SELECT *FROM myStupidTable"
which aint gunna work.
Have you ever noticed that software is never advertised using the adjective "spreadable".
Re: Multiline statement
Thank you gentleman! Those tips are exactly what I needed to make for a cleaner code.
Take care.
Take care.
Re: SOLVED: Multiline statement
I forgot to mention!
If you build your queries in an external tool, say something like dBeaver, you can copy your query and then in the IDE do a paste special (Shift + Ctl + V). In the popup there is an option down the bottom to paste "as multi-line string".
b
If you build your queries in an external tool, say something like dBeaver, you can copy your query and then in the IDE do a paste special (Shift + Ctl + V). In the popup there is an option down the bottom to paste "as multi-line string".
b
Have you ever noticed that software is never advertised using the adjective "spreadable".
Re: SOLVED: Multiline statement
Now that's something worth remembering. Thank you!thatbruce wrote: ↑Thursday 9th September 2021 7:44pm I forgot to mention!
If you build your queries in an external tool, say something like dBeaver, you can copy your query and then in the IDE do a paste special (Shift + Ctl + V). In the popup there is an option down the bottom to paste "as multi-line string".
b