Using _ line continuation in a Code file

Ricky D

Well-Known Member
Licensed User
Longtime User
I am having to split my app into various text files because it is quite big.

One of the subs has this code

sqlText="Insert Into TaxSummaries (ShiftDate,GST,PAYG,TotalTax,MyTotal) Values (" & _
"'" & ThisShiftDate & "'," & _
GST & "," & _
PAYG & "," & _
TotalTax & "," & _
MyTotal & ")"

When I put it into a file, add the file to the project and compile it complains with

Error compiling program.
Error description: syntax error.
Occurred on line: 4391
sqlText="Insert Into TaxSummaries (ShiftDate,GST,PAYG,TotalTax,MyTotal) Values (" & _

From this I assume the continuation doesn't work in external code files.
If I put the code back into the main .sbp file and take away the reference to the code file it runs.

Has anyone else had this?

regards, Ricky
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I think that it is treating the first continuation as a string.
Try this instead...

B4X:
sqlText="Insert Into TaxSummaries (ShiftDate,GST,PAYG,TotalTax,MyTotal) Values ([COLOR="Red"]" &[/COLOR] _
"'" & ThisShiftDate & "'," & _
GST & "," & _
PAYG & "," & _
TotalTax & "," & _
MyTotal [COLOR="red"]& "[/COLOR])"

Remove the items highlighted in red.
Also, do you need to have the single astrophe's either side of ThisShiftDate?

Regards,
RandomCoder
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Thanks but that won't work

Thanks RandomCoder. In Notepad on my desktop I removed all _ and carriage returns and now it works. I just wish I didn't have to to that to the code.

I use the _ continuation to make the code readable. Alas now it's not:sign0148:

Oh well.

As to the ' around the date field the answer is yes it's needed. Sql dates need to be a string in yyyy-mm-dd format.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Thanks Erel

Thanks mate.

I use one command object throughout my app.
How do I clear the parameters after I use them?

For example the Shifts tabls has these fields

ShiftId, Owner, ShiftDate, ShiftStart, ShiftEnd, Fares, EndSpeedo, StartSpeedo, PayIn50, InsLevy, FuelExp, Dockets, EFTPOS, MyTotal & Quotes

The Fares table has

FareId, FareDate, FareHash, TimeStart, TimeEnd, Pickup, Dropoff, Fare, FareType, Booked & Tip

I'd like to name my parameters like

cmd.AddParameter("Owner") and add all Shifts parameters, then build for the Fares table and so on for all the other tables.

or do I add all parameters in say app_start and then build my command text using only the parameters I need.

regards, Ricky
 
Top