Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While...Do

Status
Not open for further replies.

wesleycrusher

Technical User
Sep 30, 2003
61
US
Why does this return "True" in each case instead of printing the numbers if its true and blank_chars if it isn't? I'm only reading true/false from the DB.


numberVar i=0;
while i=0 do
(
i:=i+1;
If {furnace_model.electronic_ignition_ind}="1" Then "1," Else "";
);
while i=1 do
(
i:=i+1;
If {furnace_model.electro_mech_vent_damper_ind}="1" Then "2," Else "";
);
while i=2 do
(
i:=i+1;
If {furnace_model.power_combustion_or_vent_ind}="1" Then "3," Else "";
);
while i=3 do
(
i:=i+1;
If {furnace_model.condensing_type_ind}="1" Then "4," Else "";
);
while i=4 do
(
i:=i+1;
If {furnace_model.direct_vent_ind}="1" Then "5," Else "";
);
while i=5 do
(
i:=i+1;
If {furnace_model.single_package_unit_ind}="1" Then "6" Else "";
);
 
Your first line:

numberVar i=0;

is missing the ":" in the assignment operator

should be:
numberVar i :=0

HTH
Bob Suruncle



Bob Suruncle
 
Let us talk about the loop structure first

**********
numberVar i=0;
while i=0 do
(
i:=i+1;
If {furnace_model.electronic_ignition_ind}="1" Then "1," Else "";
);
*******

It should be numberVar i:= 0;
while i:=0 do


Now you will enter the loop properly and it will execute.

But I have to wonder what you are accomplishing here...the loop seems to be doing nothing..it automatically gets kicked out after the first pass....the same thin happens in the rest of the loops...one evaluation then out.

Also IF THE FORMULA EXECUTES PROPERLY...the final result will be either "6" or NULL...ie the result of the last loop...??????

It looks to me that you want to know if any or all of these conditions exist...so the following formula makes a lot more sense

WhilePrintingRecords;
StringVar electronic_ignition_ind := "0";
StringVar electro_mech_vent_damper_ind:= "0";
StringVar power_combustion_or_vent_ind:= "0";
StringVar condensing_type_ind:= "0";
StringVar direct_vent_ind:= "0";
StringVar single_package_unit_ind:= "0";
StringVar electronic_ignition_ind := "0";
StringVar electronic_ignition_ind := "0";

If {furnace_model.electronic_ignition_ind} = "1" then
electronic_ignition_ind := "1";
If {furnace_model.electro_mech_vent_damper_ind} = "1" then
electro_mech_vent_damper_ind := "2";
If {furnace_model.power_combustion_or_vent_ind} = "1" then
power_combustion_or_vent_ind := "3";
If{furnace_model.condensing_type_ind}="1" Then
condensing_type_ind := "4";
If {furnace_model.direct_vent_ind}="1" Then
direct_vent_ind := "5";
If {furnace_model.single_package_unit_ind} = "1" Then
single_package_unit_ind := "6";

Or it may be that you are simply trying to identify Furnace model then the formula would be

WhilePrintingRecords;
StringVar FurnaceModelType := "0";

If {furnace_model.electronic_ignition_ind} = "1" then
FurnaceModelType := "1";
If {furnace_model.electro_mech_vent_damper_ind} = "1" then
FurnaceModelType := "2";
If {furnace_model.power_combustion_or_vent_ind} = "1" then
FurnaceModelType := "3";
If{furnace_model.condensing_type_ind}="1" Then
FurnaceModelType := "4";
If {furnace_model.direct_vent_ind}="1" Then
FurnaceModelType := "5";
If {furnace_model.single_package_unit_ind} = "1" Then
FurnaceModelType := "6";

FurnaceModelType ;

Hope this helps



Jim Broadbent
 
It should be numberVar i:= 0;
while i:=0 do

********

Sorry it is only the NumberVar that has the problem

while i=0 do ..... is correct



Jim Broadbent
 
I don't think that you want a while do, but it's unclear what you intend, try:

whileprintingrecords;
stringvar Thechoices := ""
If {furnace_model.electronic_ignition_ind}="1" Then
Thechoices := "1,";
If {furnace_model.electro_mech_vent_damper_ind}="1" Then Thechoices := Thechoices +"2,";
If {furnace_model.power_combustion_or_vent_ind}="1" Then
Thechoices := Thechoices +"3,";
etc...

The last thing you'd display is TheChoices to get a concatenation of the values as a string.

-k
 
I am not exactly a programmer nor have much experience with it. The above formula is supposed to be used for a footnotes section. The bottom of the page has a text field explaining which numbers correspond to which feature. However, we have each individual footnote stored in the DB as a true/false. I want to read each of these fields and print the numbers our if they have the feature but not if they don't. My problem is that I don't want to see "1,2, ,4, ,6" but "1,2,4,6". I will look at what you all posted and try to follow it, it seems a bit over my head. I'll let you know...
 
Thanks all! I changed to variable declaration to a string and using the +"2," strategy it worked! Thanks for all of your help!
 
How would I trim the last comma from the string? So it appears as "1,2,6" and not "1,2,6,"?
 
In your formula that you are using to display the variable insert the following: Replace "TheChoices" with your variable name.

stringVar TheChoices;

If Length(TheChoices) > 0 then
Left(TheChoices, Length(TheChoices)-1)

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top