|
-
May 30th, 2006, 09:12 AM
#1
Thread Starter
Frenzied Member
[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?
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.
-
May 30th, 2006, 09:18 AM
#2
Re: Breaking A Long Line Of Code Into Segments
Try:
 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.
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
-
May 30th, 2006, 09:22 AM
#3
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
-
May 30th, 2006, 09:36 AM
#4
Thread Starter
Frenzied Member
Re: Breaking A Long Line Of Code Into Segments
 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.
 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)
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.
-
May 30th, 2006, 10:25 AM
#5
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)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|