Using _ line continuation in a Code file

Discussion in 'Questions (Windows Mobile)' started by Ricky D, Sep 30, 2008.

  1. Ricky D

    Ricky D Well-Known Member Licensed 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
  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I think that it is treating the first continuation as a string.
    Try this instead...

    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?

  3. Ricky D

    Ricky D Well-Known Member Licensed 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.
  4. Erel

    Erel Administrator Staff Member Licensed User

    This issue will be fixed in the next release.
    BTW, I recommend you to use a parameterized query instead. It is much cleaner and simpler.
  5. Ricky D

    Ricky D Well-Known Member Licensed 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
  6. Erel

    Erel Administrator Staff Member Licensed User

    I think that the best solution is to first add all the required parameters and later use the parameters you need.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice