|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
I've made up a set of simple tide table files in notepad showing high and low tides. Each file is for 1 week (7 days) from Sunday to Sunday.
At present I change the text file manually every Sunday...Erm, ok, most of the time anyway. How can I call a different text file on a weekly basis, using ASP, from the directory which the .txt files are all stored in. (The site is an asp driven site) The existing files are each named by the starting Sunday date.....18_04_04.txt. (UK date format, sorry), but it'd be no effort to number them sequentially if neccesary. Last edited by devshed2000 : September 5th, 2003 at 08:00 AM. |
|
#2
|
|||
|
|||
|
you can run a batch file to edit your code/create the txt file. Are you asking how to create a text file through asp? I use FSO, filescriptingobject. It's pretty easy to use. Just put markers around the code in your main program that opens the text file. In the batch file you can open your main code (I'd recommend splitting it off with a SSI personally and just open the small file) and then edit the line to include the new date .txt file.
|
|
#3
|
||||
|
||||
|
Thanks for this.
Sorry, I havn't explained myself properly. I've already created the text files and uploaded them to a directory on the server, and I display them on the relevant page of the site through an include file. like so: <!-- #include file="tides_text_files/24_08_03.txt" --> Where 24_08_03.txt contains the high and low tide times for each day in that particular week. On sunday 31st August 2003, I manually edit the include file by changing the name of the .txt file to "31_08_03.txt" I have to do this every week and, beleive it or not, I sometimes forget....really. What I want is some scripting so that the old text file will be automatically updated every Sunday with the new file. As I say, the separate text files are already written and exist on the server. if neccesary I can rename them from: 24_08_03.txt, 31_08_03.txt, etc to 21.txt, 22.txt, etc Thanks again Last edited by devshed2000 : September 5th, 2003 at 09:20 AM. |
|
#4
|
|||
|
|||
|
I have a similar problem
instead of basing the file name on time (which I believe you can do with asp) I have based it on a variable from the querystring. Here are two examples of possible ways to code such a thing. Problem is neither work. <!--#include file="<%=inc%>.inc"--> or <% if inc <> "" then response.write "<!--#include file='" & inc & ".inc'-->" end if %> both of these would come after <% dim inc inc = request.querystring("inc") %> The first method results in a page can't be displayed as it looks for a file called "<%=inc%>.inc". The second method results in a blank page. If you check the source code (View...Source) you see that it but the proper line in the code but failed to notice you wanted to include the file not just write out the line. If there is an order of operations for browsers it must be includes first then asp? I'm going to look up the time portion of this now. If I find it I will post another message |
|
#5
|
|||
|
|||
|
Ok read these articles...perhaps they will help!
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=55 and this: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=57 Hope this helps! Sincerely Vlince |
|
#6
|
|||
|
|||
|
Your going to love this
<%=Date%> will bring back the date in the following format 9/5/2003 from there we should be able to compare the date with a set date (file names) and pick the appropriate value to put into the file name. now all we need is someone to answer my question |
|
#7
|
|||
|
|||
|
hey thanks! I love trying to do the impossible!!!!
![]() |
|
#8
|
|||
|
|||
|
You can't use asp code to dynamically determine an include file name. Included files are merged in to the overall code base of the page before any asp code is executed.
If the Filesystem Object is available on your server, you can open and read the contents of a text file using asp, and you can then send the results to the browser. With asp3 you may be able to do something with Server.Transfer or Server.Execute. |
|
#9
|
|||
|
|||
|
Guys,
We all knew, until now, that conditional file include doesnot work. But, I have this code that is a conditional file inclusion that works and is in production. This code is running fine in the past 3 Months. I had to use FSO as everyone did until now, for conditional inclusion. This is an ACCIDENTAL DISCOVERY. My vbscript dll version is "5.6.0.7426". Running on W2k Advanced Server and IIS 5.0. I don't know what causes it to work, but it works. Code:
<% if authUser(session("username"), "TG_AQR_CREATE") then 'show the editor %>
<!-- AQR Tools -->
<!--# include file='blocks/AQR_tools.asp'-->
<% end if %>
-aspman
__________________
If you ask a question you are a fool for a second. But if you dont ask, you are a fool for a life time. |
|
#10
|
|||
|
|||
|
aspman you are conditionally executing the code in the file that was unconditionally included.
If you want to test this, turn on option explicit, create 2 include files with functions or variables of the same name, and try: Code:
<% If condition Then %> <!--#include file="file1.inc"--> <% Else %> <!--#include file="file2.inc"--> <% End If %> You should get a name redefined error because both include files are present in your code and contain ambiguous variable names or functions. However, if you don't have conflicting names, only the code in the true If block will be executed. |
|
#11
|
|||
|
|||
|
Doug G, I understand what you are saying. I have to try it to make sure the condition works in that scenario too.
But, what I am trying to say is, we all know that the include files are processed first before the asp code and the contents are visible even if the condition fails. In my case, if the condition is false, the file is not visible and vice versa |
|
#12
|
|||
|
|||
|
Dear Devshed2k,
Quote:
I'm not sure how you're predicting the future of what will be the peak times on your server and everything but i'll go with the assumption that you have a program that autogenerates these ever night, if you're doing it by hand we need to work on you =P I apoligize for not making myself clear. You can leave the include file the same, that's fine, what these other people say is true but if you go outside of ASP you get an easy solution. What i was talking about was writing a batch job to run lets say every sunday at midnight (when the new week starts). And that batch job initiates an active X call to the FSO object. We use this to open up your script, we'll call it weekly.asp. If the first line in weekly.asp is this Code:
<!--# file="9-9-9999.asp"--> you use FSO to read in weekly.asp, you then replace the 9-9 with now()'s date (use read line or do a rexex search if you need to), and then rewrite it back out. You can now have dynamic date changes and don't need to worry about forgetting. Another method, is to use FSO instead of an include. If you use FSO to open the document, you could actually check the date at runtime, and depending on the date, like today, it'd use last sundays' date to open up the .txt file or however else you write it. YOu'd just need to change the name you want the active x object to open which CAN be altered at runtime/serverside. This approach might be a little better due to keep everything centralized. I'd recommend looking at components online for checking on what days are sundays because i certainly wouldn't want to write it, that's for sure, i'd do a method of 7th, 14th, and 21st and 28th of everymonth, but that doesn't sound like what you need. There's probably a way to get the word SUNDAY, MONDAY etc.. in date but i don't know one off hand, You could easily do a case of the day to determin the date of the previous sunday. Hope this helps. Last edited by unatratnag : September 8th, 2003 at 01:10 PM. |
|
#13
|
|||
|
|||
|
Quote:
Yes, this works but I'd try to avoid this kind of syntax. Let's say you have an include file that's different for each day of a week, and each include file is maybe 50kb in size. Code:
<% If DayString = "MON" Then %> <!--#include file="monday.txt"--> <% ElseIf DayString = TUE" then %> <!--#include file="tuesday.txt"--> <% ElseIf DayString = WED" then %> <!--#include file="wednesday.txt"--> <% ElseIf DayString = THU" then %> <!--#include file="thursday.txt"--> <% ElseIf DayString = FRI" then %> <!--#include file="friday.txt"--> <% ElseIf DayString = SAT" then %> <!--#include file="saturday.txt"--> <% ElseIf DayString = SUN" then %> <!--#include file="sunday.txt"--> <% Else %> <!--#include file="someotherday.txt"--> <% End If %> This will work as expected, but it's not very server friendly. You will be including some 400kb of server code on the page, and asp will need 400kb of cache at least for your page. This will be per-session as well, so if your site is very busy you will put a big hit on the memory requirements for the server. Using an FSO-based routine to accomplish the same thing, or even a database-based routine, will be much nicer to your web server.
__________________
====== Doug G ====== "Hide, hide witch! The good folk come to burn thee. Their keen enjoyment hid behind their gothic mask of duty." -Mark Clifton |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > display a different txt file every week |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|