PDA

View Full Version : Problem with includes


ABC123

Kevin Tucker
07-30-2004, 12:24 PM
Has anyone else tried to use the a5w_include statement? I am having problems with the final release. It worked fine in the beta but now it no longer works.

Cheryl Lemire
07-30-2004, 01:07 PM
Hi Kevin,

I use include files all over the place. What is the difficulty you are currently having? I will be happy to attempt to duplicate it for you.

Cheryl

Cheryl Lemire
07-30-2004, 01:58 PM
Just so there is no confusion, I tested all of my include files and they are working properly with the 2001 build as they did during the BETA.

I have had a ton of experience breaking include files (just ask Lenny, LOL) so if you can give us the error message and perhaps your code pages in a zip file ... if anybody can duplicate it, it will probably be me :)

Kevin Tucker
07-30-2004, 09:17 PM
I to have a lot of experience breaking the includes. That is how Lenny and I got aquainted. I have attached the .a5w file if you can look at it and see if you see anything that would cause it not to work correctly. This very same file ran perfect on the beta.

Kevin Tucker
07-30-2004, 09:18 PM
Sorry about the .txt extension I copied it from the server via VNC and pasted it into notepad. It does not have that extension on the server of course.

JerryBrightbill
07-30-2004, 09:30 PM
Kevin

I don't see anything wrong with the includes. However, I have run into one problem using them in testing. When you run a page from the html editor, it is "published" to the Live Preview folder. If the page you want to include is not in that folder, the include will fail. I get around that by "previewing" each page or code snippet used in an include first. That also validates that each piece runs alone and doesn't have a problem. Be sure to save the page before you run it or the page previewed has a temporary name instead of the real name.

Jerry

Kevin Tucker
07-30-2004, 09:33 PM
Jerry,

I actually hand coded all of that. I did it in Dreamweaver. However all of the files do reside in the same folder. It seems that if you just have for else if statements it works like a champ but you add that fourth one and it no longer works. I can't figure out why like I said before this exact code worked fine in the Beta versions after Lenny got me the patch to get it working.

Cheryl Lemire
07-31-2004, 04:33 AM
Good morning Kevin,

Unfortunately I was unable to open the file you attached :(

You mentioned that it works without the fourth but it worked fine before. Perhaps to help determine if the problem is definitely with the include, have you tried to take the content of your include file and place it directly in your page? Does it work that way with the fourth?

Cheryl

Kevin Tucker
07-31-2004, 05:45 AM
It will load the page outside of the Include, it is not necessarily just that include, if you change the order or have a different one (more than three) it will not work. There are about 10 else if statments that generate the proper include.

I have attached the file as a text file.

Cheryl Lemire
07-31-2004, 06:17 AM
OK, got the file this time. I apologize for all the questions here. Is it only if you are using the else if statements that you run into this problem? If you simply have include statements in general such as your navigation, do they work if you have 4, 5, or more? I also remember during the BETA one issue being with spacing and formatting. Whitespace is NOT supposed to be an issue and obviously would be a bug if that is the problem here. I noticed looking at your file that the format is not consistent throughout the else if statements. Maybe if you open it up in a text editor (notepad, textpad) re-format it so that it is consistent and see if that resolves the issue. If so then maybe whitespace is our problem which would need to be corrected.

Cheryl Lemire
07-31-2004, 06:20 AM
I also noticed the following in your code:

%A5 else if div = "dest" then %

Your first four statements have 'then' whereas all others following them do not.

JerryBrightbill
07-31-2004, 07:05 AM
Cheryl

The "then" is optional and should have no effect. However using that many nested levels in an if statement has proven in the past to be a recipe for trouble. A select case construction would make much more sense. Case statements are much more efficient since once a true is found, the rest of the case expressions are not evaluated. If the most likely hit is the first one, this will make the select case much fgaster.

Also, in the code, each if statement turns the a5 code on and off, which seems like a bad idea. A better method would be to use select case and place the desired page name in a variable. Then use one include to add the desired page. I have attached a text file with a sample that should work.

Jerry

JerryBrightbill
07-31-2004, 07:07 AM
Sorry. The last line

"%A5 end if%"

should not be there.

Jerry

Cheryl Lemire
07-31-2004, 07:46 AM
I understand that the then should not cause a problem, was just pointing out the coincidence that he had four of them and that is where he was running into difficulty. The fact that it all worked in BETA but does not now just had me looking for anything that may not be consistent.

I also agree with the use of case statements, they are normally my first choice over if statements. I have learned a lot about Alpha from reading your posts :)

JerryBrightbill
07-31-2004, 09:02 AM
Good point about the code working in the beta, but not the production build. I wonder if the issue is related to the speed issue in build 2001 since the code used so many embedded a5 xbasic code segments.

I am just getting into web page building with WAS, but I like putting as much code into one a5 code segment as possible, rather that the method shown in some of the early examples. In the examples one segment was the "if" statement, followed by html, then another a5 segment with the "else" part, then more html, and so one. I have been putting the whole if statement or select statement into a single a5 code segment and placing the resulting html into a variable. Then I output the variable at the end of the code. I don't know if that is more efficient code, but I can follow the logic easier.

Jerry

Kevin Tucker
07-31-2004, 09:19 AM
Jerry,

Everything works except for I need to put quotes around the inc_page for the a5w_include() to work correctly. At least that is what Lenny told me a while back. How do I add that to the string for the variable?

inc_page = hotel.htm
so then the a5w_include= a5w_include(hotel.htm) when it should actually be a5w_include("hotel.htm")

Thank you for your help, I had forgotten about the case select statements, it just doesn't make sense that this worked with out a single problem in the beta but now it doesn't work at all with the if then statements.

Cheryl Lemire
07-31-2004, 09:35 AM
I prefer to use include files, case statements, and functions so that my actual a5w code page is primarily html calling my xbasic code.

If the issue with his code is specific to build 2001, they did release the 2002 and maybe that would resolve the issue as well. It would be nice to find out what is causing the trouble since it may be a bug.

Kevin Tucker
07-31-2004, 09:43 AM
Cheryl

I was hoping that the 2002 release would fix it but it did not. I am hoping that I can get it resolved quickly.

Kevin

Cheryl Lemire
07-31-2004, 09:48 AM
Hi Kevin,

Here is a sample case statement that I have as a function sorry for the formatting here):

%A5
function webpage as C(url as C)
'define a function called webpage and populate data into the variable url
SELECT 'begin case block
CASE url = "inventory"
'if the value of the variable url is equal to inventory
webpage = "inv.a5w"
'assign inv.a5w to webpage
CASE url = "purchasing"
'if the value of the variable url is equal to purchasing
webpage = "purch.a5w"
'assign purch.a5w to webpage
CASE url = "receiving"
'if the value of the variable url is equal to receiving
webpage = "rec.a5w"
'assign rec.a5w to webpage
CASE else
'if the value of the variable url is not equal to the above options
webpage = "main.a5w"
'assign main.a5w to webpage
end SELECT 'end case block
end function 'end the webpage function
%

************

Below is my function call which is in an include file that I use for that particular a5w page:

<a href="<%A5 ? webpage(tcompsec.Sec_Desc) %"""<%A5 ? tcompsec.Sec_Desc %"</a"

JerryBrightbill
07-31-2004, 10:01 AM
Kevin

I stand corrected. A5w_include() is the first function I have encountered in Alpha that won't accept a variable. However, you can still run the whole case statement within a single code section. Attached is a modified version of what I sent earlier. I tested this on a page I have than uses a5w_include() and it seems to work fine. The actual page code tested is included and had 7 case statements. I used V6 build 1531_2002.

Jerry

Cheryl Lemire
07-31-2004, 10:03 AM
Hi Kevin,

The attached zip file includes main.a5w and access_links.a5w.

The main.a5w is the page that displays the links based on the query in the access_links.a5w page which calls the webpage function (the case statement shown in my previous post)

Hopefully this will help.

Cheryl

PS I would still like to know why your if statements are no longer working if they in fact worked in the BETA version. Have you downloaded the 2002 patch? Do they still not work with that patch? If not, maybe you can remove the four 'then' or add the 'then' to your other statements to see if that is an issue. If we have a bug here, it would be nice to find it ... even if Lenny does hate us for it (we still love you Lenny and I know there are still a few strands of hair left to pull out)

Kevin Tucker
07-31-2004, 10:44 AM
Jerry is there a limit on how many case statements you can have? I have 12 and it won't work. However it I drop it to 7 it will work.

JerryBrightbill
07-31-2004, 11:24 AM
Kevin

There should be no practical limit on case statements. I just tried my test page with 20 case statements and it worked fine. I suspect the problem isn't the number, but the page being "included." If you identify the point where the code fails, change the page in the include. Or, just for testing, use the same page in every include statement.

Jerry

Kevin Tucker
07-31-2004, 07:12 PM
I have tried everything I can think of and it works but not with all of the case statments. I have tried loading each page that will not work with the case statement seperately and it will load fine but not with the include inside of the case statement. Also I thought that once the case statement equales true it stops going through each case? This apparently is not how it works on WAS. If I add the case statement that will not load yet select the very first option it will not load at all, it takes forever and finally errors out or gives a blank page. Any thoughts on this one?

JerryBrightbill
08-01-2004, 06:25 AM
Kevin

First, a little test will show that a select case construction only evaluates until it hits the first true result. Start a new script the regular code editor. Create a variable and give it a value. Build a select case construction with a number of options testing for the assigned value to the variable. Make at least 2 case statements exactly the same, but with a different response. Add debug(1) to the start of the code and run the code. You will see that the script stops at every case expression, but once it has a true, it will not respond to the second true expression.

One of the issues I see using A5 code in WAS pages is debugging and finding errors, especially logic errors. When I have made code errors, some will still output a page and show the error. But some errors, particularly with a5w_include(), just give a blank output and no messages. Troubleshooting becomes a challenge.

I still suspect the problem is in your code or the pages that are being "included". To test the program, I built 12 junk html pages. I then built an a5w page that has 12 select case statements. Each expression evaluates a variable value and "includes" one of the pages. I have tested every true statement, and the pages output fine. I have zipped the example and attached it. Unzip the junk.htm files to the Livepreview folder under your webroot folder. Unzip the a5w page to any project folder. Open the database with that project, open the page in the html editor and run it. Change the variable value and see if it loads the correct page.

If there are no true statements, then there should be no include and that section of the final code should be blank. You could also take your code and use my junk pages as the include pages. This should eliminate your other pages as the source of the issue. You could also cut and paste the whole a5 code into a regular script. Create values for the various variables needed at the start of the script and add debug(1) before the section from the a5w page. Run the script and step through the code lines. The a5w_include() will give an error as it is only recognized on an a5w page and is not a regular Alpha function, but you should see how the logic flows through the code and see how the expressions evaluate. I know debug is supposted to work in the html editor, but I haven’t been able to get it to work.

If all else fails, zip up your pages and post them. Someone may be able to see where the error occurs.

Jerry

Lenny Forziati
08-09-2004, 11:25 AM
I don't know if that is more efficient code, but I can follow the logic easier.

In terms of performance, there is no difference whether your code is in a single block or many blocks. That makes the choice of approaches a personal preference. Whichever is easiest for you is the one you should use.

Personally I use a mixture of both, depending on how complex of a formatted output string I am building up.

-Lenny