[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:
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:
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)
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?
Re: Breaking A Long Line Of Code Into Segments
Try:
Quote:
Originally Posted by SeanK
VB Code:
lngTotalPolicy = Val(adoRS.Fields.Item("tot_liab_paid_bal").Value) & _
- [color=red][b]([/b][/color]Val(adoRS.Fields.Item("prior_bal").Value)[color=red][b])[/b][/color] & _
- [color=red][b]([/b][/color]Val(adoRS.Fields.Item("incurred_debt").Value)[color=red][b])[/b][/color] & _
- [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.
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
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:
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)
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:
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)