Jump to content

random insertion of a file with VB


netcracker

Recommended Posts

Here is a script that for some reason doesn't work.Need help on ASP :D A.S.A.P. please. This needs not be in VB but also JS, it's all the same to me. :) <script type="text/vbscript"> randomize() r=rnd() if r>0.5 then document.write("<!--#include file="include/file1.asp" -->") else document.write("<!--#include file="include/file2.asp" -->") end if</script>Also tried: :( <script type="text/vbscript"> randomize() dim text = '<!--#include file="include/file1.asp" -->' r=rnd() if r>0.5 then document.write (text) else document.write (text) end if</script>Still no good. :) The reason it doesn't work is "!" sign... :( I tried the use of "%21" in stead of that "!" but for the same result.Any recomandations, :blink: please?The purpose is to insert a random file into an ASP page. I didn't expect it to be this hard and anoying. :)

Link to comment
Share on other sites

that doesn't work due to the way it parses the code and include files the only way to deal with this is....<%randomize()r=rnd()if r>0.5 then%><!--#include file="include/file1.asp" --><%else%><!-- #include file="include/file2.asp" --><%end if%>

Link to comment
Share on other sites

thx for the swift response. :D so now it parses right :) but doesn't work the way I hoped it would.it includes both of the files in the source code and it does not randomize them, as I hoped... :)damn this is so much harder than expected. :(Please keep it comming, I really need the support and ideeas. This is supposed to be a script that inserts one file from a given few randomly. I need the files in the browser not in the source code.

Link to comment
Share on other sites

it should work like that tho, atleast this one does at my side...<%randomize()r=rnd()if r>0.5 then%><!-- #include file="inc1.asp" --><%else%><!-- #include file="inc2.asp" --><%end if%> inc1.asp = <%=1%>inc2.asp = <%=2%>it prints 1 or 2 as supposed to be.

Link to comment
Share on other sites

I get this ERROR: :( <<--Technical Information (for support personnel)Error Type:Microsoft JScript compilation (0x800A03ED)Expected '('/cartedeafaceri.ro/random.asp, line 12, column 3if r>0.5 then--^-->>Must be something with my IIS :) [ Internet Information Services | Microsoft Corporation | Version: 5.1 ]Since you say it works fine with you... gotta search for something wrong with my IIS, no dobt.Thank you still. :)

Link to comment
Share on other sites

here's a copy/paste of my testing asp file:<BODY><%randomize()r=rnd()if r>0.5 then%><!-- #include file="include/tblleft1.asp" --><%else%><!-- #include file="include/tblleft2.asp" --><%end if%> include/tblleft1.asp = <%=1%>include/tblleft2.asp = <%=2%></BODY>I have no ideea why it doesn't work. :) HELP ME, PLEASE !!! :)

Link to comment
Share on other sites

I belive you, if you say that test_file works fine with you than it has got to be something with my IIS !! :) I just wonder what ?! :) I've been looking around for clues and couldn't find any...

Link to comment
Share on other sites

the only things that could cause problems is rights on folders and that "enable parent paths" or something simular that's dissabled.unzip that file to you c:\inetpub\wwwroot and see if it works there, then try again on the server.

Link to comment
Share on other sites

unzip that file to you c:\inetpub\wwwroot and see if it works there, then try again on the server.
yep! it seems that it only works in inetpubwwwroot !?! I cannot explain it, because I have the same settings on all sites (virtual folders)... It's all good then. Thank you verry verry much for all the help and support, and the source code :) ...One last question... if I have more files to include, say 4 I set the "r" to be "r>0.25" right ?!THX, you're the gratest ! :)
Link to comment
Share on other sites

okay, so we can all agree that my VB is sooo BAD ! I didn't wanna admit it at first, but it's obvious now... BUT I WANT TO LEARN !! :) so back to the script we've been discussing... we now have more files to include randomly.the script is like this:

<%randomize() r=rnd()  if r>0 then%>    <!-- #include file="include/tblleft1.asp" -->  <%else%>    <!-- #include file="include/tblleft2.asp" -->  <%else%>    <!-- #include file="include/tblleft3.asp" -->  <%else%>    <!-- #include file="include/tblleft4.asp" --><%end if%>
What I didn't get is where do I insert thar part of code you told me last time:
randomizenr=int(rnd*4)+1
Don't get mad, just apreciate my willing to learn and support me please :)
Link to comment
Share on other sites

hmm that code of your will only insert tblleft1 or tblleft4this should be a solution (without using nested if then else elseif stuff)<%randomize()filenr=int(rnd*4)+1select case filenrcase 1%><!-- #include file="include/tblleft1.asp" --><%case 2%><!-- #include file="include/tblleft2.asp" --><%case 3%><!-- #include file="include/tblleft3.asp" --><%case 4%><!-- #include file="include/tblleft4.asp" --><%end select%>if it doesn't work try case "1" , dunno if it deals with numbers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...