|
|
Simple ScriptsThe beginning of each VB script is marked <% and the end is marked %>. FrontPage shows the scripts in brown text for easier reading. Don't forget that the VB scripts are used to build the HTML code which is then sent to the browser where the HTML code is used to build the actual web page. It's a bit complicated! In Vbscript the instruction 'Response.write' is an instruction to include whatever follows directly in the html code. An equals sign is an abbreviation for 'Response.write' so <% Response.Write "Hello!" %> is the same as <% = "Hello!" %> Sample scriptA sample script (don't forget that the VB script is running on the server which is located in the US where the time is not the same as in France): Today is <%=now%> and all is well.<br>
Result: Today is 5/18/2012 2:44:04 PM and all is well.Good Evening SubroutinesThis script shows how subroutines can be created and then called, although defining subroutines is not required, as shown in the first example. <% Sub SayHello Response.Write "Hello!<br>" Response.write "The time on the server is: " & Time() End Sub sayhello %> Result: Hello!The time on the server is: 2:44:04 PM A loopThis little script uses a loop to write text in increasing sizes: <% = "<br>" %> <% for a = 1 to 5 %> <font size = <% = a %> > Hello World </font> <br> <% next %> Result: Manipulating dates and timesIn the following script dates and times are manipulated and then written to the page in two different ways: the first lines are written within the VB script using Response.write and the final lines are written using straightforward html (but with the actual times and dates added using VB script). <%
when=now()
tommorow=dateadd("d",1,when)
twoweekslater=dateadd("ww",2,when)
fourteenweekdayslater=dateadd("w",14,when)
monthlater=dateadd("m",1,when)
sixminuteslater=dateadd("n",6,when)
sixhourslater=dateadd("h",6,when)
fortysecslater=dateadd("s",40,when)
response.write "Now <b>" & when & "</b><br>"
response.write "tommorow <b>" & tommorow & "</b><br>"
response.write "2 weeks from Now <b>" & twoweekslater & "</b><br>"
response.write "fourteen working days from Now <b>" & fourteenweekdayslater & "</b><br>"
response.write "1 month from Now <b>" & monthlater & "</b><br>"
%>
six minutes from now <b> <%=sixminuteslater%> </b><br> six hours from now <b> <%=sixhourslater%> </b><br> forty seconds later <b> <%=fortysecslater%> </b><br> Result: Now 5/18/2012 2:44:04 PMtommorow 5/19/2012 2:44:04 PM 2 weeks from Now 6/1/2012 2:44:04 PM fourteen working days from Now 6/1/2012 2:44:04 PM 1 month from Now 6/18/2012 2:44:04 PM six minutes from now 5/18/2012 2:50:04 PM six hours from now 5/18/2012 8:44:04 PM forty seconds later 5/18/2012 2:44:44 PM |
|
|