Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Convert to VBScript to JavaScript ?

Reply
Thread Tools

Convert to VBScript to JavaScript ?

 
 
davidgordon@scene-double.co.uk
Guest
Posts: n/a
 
      10-17-2005

Hi,

I have some pages with this VBScript code, which obviously does not
work in Firefox. How can I convert this to Javascript in order for my
web page to work in Firefox ? It basically fills a drop down with a
list of dates that a user can select.

Appreciate any help you can offer

----------------------

<SCRIPT language='vbscript'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbFriday - WeekDay(Date)
If TheDate < Date Then TheDate = TheDate + 7
Set Options = Document.All.Date.Options
For Count = 1 To 40
StrDate = "Friday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" &_
Month(TheDate),2) & "/" & Year(TheDate)
Options.Add Window.Option(StrDate,"for " & StrDate)
TheDate = TheDate + 7
Next
End Sub
</script>

-----------------------

Thanks


David

 
Reply With Quote
 
 
 
 
Zif
Guest
Posts: n/a
 
      10-17-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I have some pages with this VBScript code, which obviously does not
> work in Firefox. How can I convert this to Javascript in order for my
> web page to work in Firefox ? It basically fills a drop down with a
> list of dates that a user can select.
>
> Appreciate any help you can offer
>
> ----------------------
>
> <SCRIPT language='vbscript'>
> Sub Window_Onload
> Dim TheDate
> Dim Count
> Dim Options
> TheDate = Date + vbFriday - WeekDay(Date)
> If TheDate < Date Then TheDate = TheDate + 7
> Set Options = Document.All.Date.Options
> For Count = 1 To 40
> StrDate = "Friday " & Right("0" & Day(TheDate),2) & "/" &
> Right("0" &_
> Month(TheDate),2) & "/" & Year(TheDate)
> Options.Add Window.Option(StrDate,"for " & StrDate)
> TheDate = TheDate + 7
> Next
> End Sub
> </script>


The usual deal is to firstly describe what you want in plain language,
you know, 'requirements'. By stating your requirements in VBscript,
you immediately discount those who don't know it or don't care for it.

I'll guess that you want to generate a set of options with dates
starting from the next Friday for 40 weeks.

That stuff is much better done on the server, you have no idea what
the date/time of a users' system is, whether it is accurate or whether
it bears a suitable correlation to your location or that of your
server. You also avoid any issues with script incompatibility or
non-availability.

For the record, here's a script that does the above based on the date
of the user's system. But I wouldn't use it for anything important.



<form action="" name="formA">
<select name="weekDate" style="font-family: courier, sans-serif;">
<option>Select a date</option>
</select>
</form>



<script type="text/javascript">

function addDates(sel)
{
var months = ['Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'];
var numDates = 40; // number of dates to calculate
var daysBetween = 7; // days to add each time
var now = new Date(); // start from today

// Use following to set the date for testing
// var now = new Date(2005, 9, 21);

// Set the date to the next Friday
now.setDate(now.getDate() - ((now.getDay()+2)%7));

var i=1;
var optValue, optText;

while ( i <= numDates ){
now.setDate(now.getDate() + daysBetween);
optValue = now.getFullYear()
+ '-' + addZ(now.getMonth()+1)
+ '-' + addZ(now.getDate());
optText = now.getFullYear()
+ '-' + months[now.getMonth()]
+ '-' + addZ(now.getDate());
sel.options[i++] = new Option(optText, optValue);
}
}

function addZ(x)
{
return (x<10)? '0'+x : x;
}

window.onload = function () {
addDates(document.forms['formA'].elements['weekDate']);
};

</script>






--
Zif
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      10-17-2005
JRS: In article <435391c8$0$28207$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Mon, 17 Oct 2005 21:58:19, seen in
news:comp.lang.javascript, Zif <(E-Mail Removed)> posted :
>
> var now = new Date(); // start from today
>
>// Use following to set the date for testing
>// var now = new Date(2005, 9, 21);
>
> // Set the date to the next Friday
> now.setDate(now.getDate() - ((now.getDay()+2)%7));


ISTM add 7 for next Friday.
I think the OP's code allowed today as a starting point, in which case
add 6 and adjust the getDay()+ number by 1.

The OP allowed his posting agent to wrap his code .

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert VBScript into Javascript balzer Javascript 5 05-13-2010 06:36 PM
Trying to convert a line of asp vbscript to vb.net adupuis@dublin.ie ASP .Net 1 11-03-2008 11:47 AM
convert Vbscript to Perl code Boris Skoblo Perl Misc 28 01-19-2007 10:25 AM
Convert from VBScript... David Javascript 6 08-03-2004 08:31 PM
mixing Javascript and VBScript in ASP.NET? Jamie ASP .Net 1 12-05-2003 11:54 PM



Advertisments