Results 1 to 5 of 5

Thread: [RESOLVED] Breaking A Long Line Of Code Into Segments

  1. #1

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Resolved [RESOLVED] Breaking A Long Line Of Code Into Segments

    This works like a champ is I have it all on one line, but it is also very difficult to read.
    VB Code:
    1. lngTotalPolicy = Val(adoRS.Fields.Item("tot_liab_paid_bal").Value) - Val(adoRS.Fields.Item("prior_bal").Value) - Val(adoRS.Fields.Item("incurred_debt").Value) - Val(adoRS.Fields.Item("fund_balance").Value)
    But, nothing I've tried to put it on separate lines have works. This was my lastest failure
    VB Code:
    1. lngTotalPolicy = Val(adoRS.Fields.Item("tot_liab_paid_bal").Value) & _
    2. -Val(adoRS.Fields.Item("prior_bal").Value) & _
    3. -Val(adoRS.Fields.Item("incurred_debt").Value) & _
    4. -Val(adoRS.Fields.Item("fund_balance").Value)
    How can I put this line (which, obviously, is a calculation) on multiple lines so it is easier to read and understand, and still have it work?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Breaking A Long Line Of Code Into Segments

    Try:
    Quote Originally Posted by SeanK
    VB Code:
    1. lngTotalPolicy = Val(adoRS.Fields.Item("tot_liab_paid_bal").Value) & _
    2. - [color=red][b]([/b][/color]Val(adoRS.Fields.Item("prior_bal").Value)[color=red][b])[/b][/color] & _
    3. - [color=red][b]([/b][/color]Val(adoRS.Fields.Item("incurred_debt").Value)[color=red][b])[/b][/color]  & _
    4. - [color=red][b]([/b][/color]Val(adoRS.Fields.Item("fund_balance").Value)[color=red][b])[/b][/color]
    How can I put this line (which, obviously, is a calculation) on multiple lines so it is easier to read and understand, and still have it work?
    If that still doesn't work, post exactly what's not working and what, if any, error message you get.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Breaking A Long Line Of Code Into Segments

    Get rid of the ampersands... your concatenating and performing arithmetic operations

    Total = A _
    + B _
    - C _
    / D

  4. #4

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: Breaking A Long Line Of Code Into Segments

    Quote Originally Posted by Al42
    Try:
    If that still doesn't work, post exactly what's not working and what, if any, error message you get.
    The code I posted is exactly what is not working. As I said before, if I don't try and break the line up, the calculation works just fine. When I tried to break it up (using both the method I posted, as well as your suggestion, I get an Error 13 - Type Mismatch, and the entire line is highlighted. The fact that the entire line is highlighted tells me that VB is recognizing it as a single line, but I suspect that because it is a calculation, things are getting botched up. I can always just run it as a single line, but for readilbility purposes, it would be nice to break it into individual lines that are concantanted.
    Quote Originally Posted by leinad31
    Get rid of the ampersands... your concatenating and performing arithmetic operations
    This worked. Thanks leinad31!
    VB Code:
    1. lngTotalPolicy = Val(adoRS.Fields.Item("tot_liab_paid_bal").Value)  _
    2. - Val(adoRS.Fields.Item("prior_bal").Value)  _
    3. - Val(adoRS.Fields.Item("incurred_debt").Value)  _
    4. - Val(adoRS.Fields.Item("fund_balance").Value)
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [RESOLVED] Breaking A Long Line Of Code Into Segments

    Do what leinad31 said - I overlooked the fact that you're doing a string concatenation.
    VB Code:
    1. lngTotalPolicy = Val(adoRS.Fields.Item("tot_liab_paid_bal").Value)  _
    2. - Val(adoRS.Fields.Item("prior_bal").Value)  _
    3. - Val(adoRS.Fields.Item("incurred_debt").Value)  _
    4. - Val(adoRS.Fields.Item("fund_balance").Value)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width