Calling VB coders, stupid question for u's - Chicagoland Sportbikes
Chicagoland Sportbikes
 
Open Forum This forum is for all off-topic discussion.

 
LinkBack Thread Tools Display Modes
post #1 of 5 (permalink) Old 09-22-2005, 11:55 AM Thread Starter
 
Join Date: Apr 2002
Posts: 6,882
           
Calling VB coders, stupid question for u's

Trying to get a bunch of IF's to run basically to show an address all nice and pretty, otherwise if I simply set the fields within Crystal reports then there are gaps sometimes. So my original code was...

{Command.CUSTOMERNAME} & chrw(13);
if {Command.ADDRESS1}<> "" then {Command.ADDRESS1} & chrw(13);
if {Command.ADDRESS2}<> "" then {Command.ADDRESS2} & chrw(13);
if {Command.ADDRESS3}<> "" then {Command.ADDRESS3};

Why won't this work? I allow the field to grow but it seems to return only one of the Address (usually Address3) fields (the customername always displays correctly).

Finally I ended up doing it this way which seemed to do the job, but curious about what is wrong with my logic above...

Stringvar Address;
Address := {Command.CUSTOMERNAME} & chrw(13);
if {Command.ADDRESS1}<> "" then Address := Address & {Command.ADDRESS1} & chrw(13);
if {Command.ADDRESS2}<> "" then Address := Address & {Command.ADDRESS2} & chrw(13);
if {Command.ADDRESS3}<> "" then Address := Address & {Command.ADDRESS3} & chrw(13);
Address:=Address & {@Display City State Zip};
Address;
BIGGY is offline  
Sponsored Links
Advertisement
 
post #2 of 5 (permalink) Old 09-22-2005, 12:23 PM
I do it in the dirt!
 
X-SLaYeR's Avatar
 
Join Date: Apr 2002
Location: East Chicago, Indiana
Posts: 607
Location: East Chicago, Indiana
Sportbike: 05 CRF250R #606, 03 XR70
Years Riding: lots
How you found us: Intarwebz
           
It's been awhile, but I believe the 2nd way works because it is comparing a variable. Something to do with VB's memory handling I believe.
X-SLaYeR is offline  
post #3 of 5 (permalink) Old 09-22-2005, 12:33 PM Thread Starter
 
Join Date: Apr 2002
Posts: 6,882
           
2nd method yes. I simply create a variable and concat on to it.
BIGGY is offline  
post #4 of 5 (permalink) Old 09-22-2005, 02:42 PM
 
Join Date: Apr 2003
Posts: 1,038
           
WARNING! GEEK TALK INCOMING!

{Command.CUSTOMERNAME} & chrw(13);
if {Command.ADDRESS1}<> "" then {Command.ADDRESS1} & chrw(13);
if {Command.ADDRESS2}<> "" then {Command.ADDRESS2} & chrw(13);
if {Command.ADDRESS3}<> "" then {Command.ADDRESS3};

The way it's evaluating this statement is that it evaluates all the if clauses before it returns the value to the field. So each time it sees a {Command.AddressX} it is overwriting the previous value for the field. So if Command.ADDRESS3 is not blank, that is all that will be returned. So you would never get an address1 or customer name returned, the only values that could be returned are Address2 if Address3 is blank or address3. In crystal you have to think like the field is a string, not an output stream, which means you must store you evaluations and then return the result at the end instead of "printing" to the field as you evaluate.
flinchy is offline  
post #5 of 5 (permalink) Old 09-22-2005, 02:52 PM Thread Starter
 
Join Date: Apr 2002
Posts: 6,882
           
Ok, that makes sense. Although I'm pretty sure it was giving me the customername. Could it print the name and then cycle through all the IF's, or does it fly through the full function? I don't really care to go back and test, but I know I was seeing the customernames, perhaps I manually put that field in and that's what I was seeing. Oh well. Now I know. Thanks!
BIGGY is offline  
Reply

Quick Reply
Message:
Options

Register Now



In order to be able to post messages on the Chicagoland Sportbikes forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.

User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.

Password:


Confirm Password:
Email Address
Please enter a valid email address for yourself.

Email Address:
OR

Log-in










Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Display Modes
Linear Mode Linear Mode



Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

 
For the best viewing experience please update your browser to Google Chrome