473,671 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert from VBScript...

Hi,

I have a script in one of my .asp pages which I think is written in
VBScript (I did not write it). I would like to know how to do the
following in Javascript.

Have a combo on my page which basically lists all the following
Tusdays & Thursdays dates, up to a set qty, i.e. 20 in the list.

E.g. todays date is 2nd August, so the combo would list 20 lines of:

Tusday 3rd August
Thursday 5th August
Tusday 10th August
Thursday 12 August

and so on for another 16 lines...

How is this possible ?

_______________ _______________ ____________

The code I have at the mo has been tweeked by myself, but I can only
get the combo to list the Tuesdays first, then all the Thursdays, not
all in date order.

_______________ _

<SCRIPT language='vbscr ipt'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbTuesday - WeekDay(Date)
TheDate2 = Date + vbThursday - WeekDay(Date)
If TheDate < Date Then TheDate = TheDate + 7
Set Options = Document.All.Da te.Options
For Count = 1 To 20
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" &_
Month(TheDate), 2) & "/" & Year(TheDate)
Options.Add Window.Option(S trDate,"for " & StrDate)
TheDate = TheDate + 7
Next

If TheDate2 < Date Then TheDate2 = TheDate2 + 7
Set Options = Document.All.Da te.Options
For Count = 1 To 20
StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2 ) & "/" &
Right("0" &_
Month(TheDate2) ,2) & "/" & Year(TheDate2)
Options.Add Window.Option(S trDate2,"for " & StrDate2)
TheDate2 = TheDate2 + 7
Next
End Sub
</script>

_______________ _______________ _

Hope you can help ?
David
Jul 23 '05 #1
6 3092
In article <c1************ **************@ posting.google. com>, david@scene-
double.co.uk enlightened us with...
Hi,

I have a script in one of my .asp pages which I think is written in
VBScript (I did not write it). I would like to know how to do the
following in Javascript.

Have a combo on my page which basically lists all the following
Tusdays & Thursdays dates, up to a set qty, i.e. 20 in the list.
<snip>

The code is also IE only.

The code I have at the mo has been tweeked by myself, but I can only
get the combo to list the Tuesdays first, then all the Thursdays, not
all in date order.


I checked this in IE. Should work in Netscape, too. Check other browsers as
needed. Watch for word-wrap.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript" language="javas cript">
function formatDate(t_da te, format)
{
/* t_date is expected to be a Date() and format is a string */

var r_date = null; /* string to return */

/* add more formats as desired */
switch (format)
{
case ("mm/dd/yyyy"):
tmp = t_date.getMonth ()+1;
tmp = tmp<10?"0"+tmp: tmp;
r_date = tmp+"/";
tmp = t_date.getDate( );
tmp = tmp<10?"0"+tmp: tmp;
r_date += tmp+"/"+t_date.getFul lYear();
break;
default:
alert("That is not a valid format");
}
return r_date;
}

function addDays(t_date, days)
{
return new Date(t_date.get Time() + days*24*60*60*1 000);
}

function fillIt()
{
var s = document.forms["f1"].elements["date"];
var o;
var theDate = new Date();
var i;

for (i=0; i<20; i++)
{
/* if this is a Tuesday (2) or Thursday (4), put in option, else add a
day and check again */
while (theDate.getDay () != 2 && theDate.getDay( ) != 4)
theDate = addDays(theDate ,1);
/* we get here, it's either Tursday or Thursday - write option,
increment, and loop */
tmp = formatDate(theD ate, "mm/dd/yyyy");
o = new Option(tmp, tmp);
s.options[i] = o;
theDate = addDays(theDate ,1);
}
}
</script>
</head>

<body onLoad = "fillIt()">
<form name="f1" id="f1">
<select name="date" id="date"></select>
</form>
</body>
</html>

--
--
~kaeli~
When you choke a smurf, what color does it turn?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
ben
david, try something like:
<script>

function FillThemDateOpt ions()
{
var dateSelector = document.form2. JSDate;
var maxOptions = 20;
var today = new Date();

for(var i=0;i<((maxOpti ons*7)/2);i+=7)
{
var tueDate =
new Date(today.getY ear(), today.getMonth( ),
today.getDate() +i+1);
var thuDate =
new Date(today.getY ear(), today.getMonth( ),
today.getDate() +i+3);

dateSelector.op tions.add(Forma tTheDateAsASele ctOptionThing(t ueDate));
dateSelector.op tions.add(Forma tTheDateAsASele ctOptionThing(t huDate));
}
}

function FormatTheDateAs ASelectOptionTh ing(d)
{
var aWeekDayNames =
new Array('Sunday', 'Monday','Tuesd ay','Wednesday' ,'Thursday','Fr iday','Saturday ');

var sText =
aWeekDayNames[d.getDay()] +
' ' +
((d.getDate()<1 0)?'0':'') +
d.getDate() +
'/' +
((d.getMonth()< 10)?'0':'') +
d.getMonth() +
'/' +
d.getFullYear() ;

var sValue = 'for ' + sText;

return new Option(sText, sValue);
}

window.onload = FillThemDateOpt ions;

</script>

irt.org have a load of FAQs on javascript:
http://developer.irt.org/script/date.htm give them a try for some
ideas.

ben
Jul 23 '05 #3
JRS: In article <MP************ ************@nn tp.lucent.com>, dated
Mon, 2 Aug 2004 11:32:31, seen in news:comp.lang. javascript, kaeli
<ti******@NOSPA M.comcast.net> posted :
In article <c1************ **************@ posting.google. com>, david@scene-
double.co.uk enlightened us with...
I have a script in one of my .asp pages which I think is written in
VBScript (I did not write it). I would like to know how to do the
following in Javascript.

Have a combo on my page which basically lists all the following
Tusdays & Thursdays dates, up to a set qty, i.e. 20 in the list.


You've not specified what happens if today is Tue or Thu, unless we take
"following" literally.

If the number is always to be even, one can take advantage of the fact
that the duration will always be a little over 10 weeks.

I checked this in IE. Should work in Netscape, too. Check other browsers as
needed. Watch for word-wrap.
But did you check it in February or September at sensitive times of day?
Ten weeks from now it is still Summer.

function addDays(t_date, days)
{
return new Date(t_date.get Time() + days*24*60*60*1 000);
}

There are circumstances in which that can be correct; except that
there's no point in typing 24*60*60*1000 when 864e5 will suffice. That
code may be one of them; but if a Sunday were wanted a special one would
ISTM be missed or duplicated.
function fillIt() var theDate = new Date(); theDate = addDays(theDate ,1);

In late Winter, if the code is started late enough in the day, a day
will be missed; and vice versa for early Summer morning.

Function addDays could be

function addDays(t_date, days) { // but alters t_date
t_date.setDate( t_date.getDate( ) + days ) }

Alternatively, use setHours(12) early on.


The following will write the desired dates :-
D = new Date() ; K = 20 ;
while (K) {
D.setDate(D.get Date()+1) // AddADay
X = D.getDay()
if ( X==2 || X==4 ) document.write( D, ' ', K--, '<br>')
}

If speed matters, however, find today's day-of-week, calculate the
offset to the Tue/Thu before the next, add it, then add 2 & 5
appropriately 20 times.

Otherwise, if the dates are to be used in ISO-8601 form such as
"2004-08-02 Mon" then one can stick first the Tuesdays then the
Thursdays in an array, and sort it.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
Ben,

Thanks for that, but I cannot get your script working with a form....

</script>
</head>

<body onLoad = "FillThemDateOp tions()">
<form name="form2" id="form2">
<select name="JSDate" id="JSDate"></select>
</form>
</body>
</html>
I know this simple, but I must be missing a trick here ?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
Hi,

Just to let you know that I suddenly had a brainwave with my original
code and changed it to:

<SCRIPT language='vbscr ipt'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbTuesday - WeekDay(Date)
TheDate2 = Date + vbThursday - WeekDay(Date)
If TheDate < Date Then TheDate = TheDate + 7
Set Options = Document.All.Da te.Options
For Count = 1 To 20
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" &_
Month(TheDate), 2) & "/" & Year(TheDate)
Options.Add Window.Option(S trDate,"for " & StrDate)
TheDate = TheDate + 7
StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2 ) & "/" & Right("0"
&_
Month(TheDate2) ,2) & "/" & Year(TheDate2)
Options.Add Window.Option(S trDate2,"for " & StrDate2)
TheDate2 = TheDate2 + 7
Next

End Sub
</script>

Thanks again for all your help and code. I'm testing your different
versions now.

David.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6
JRS: In article <41************ *********@news. newsgroups.ws>, dated
Tue, 3 Aug 2004 15:45:00, seen in news:comp.lang. javascript, David
Gordon <da***@scene-double.co.uk> posted :
Hi,

Just to let you know that I suddenly had a brainwave with my original
code and changed it to:

<SCRIPT language='vbscr ipt'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbTuesday - WeekDay(Date)
TheDate2 = Date + vbThursday - WeekDay(Date)
In principle, one should call only one of Date, Time, Now on any given
page (unless one wishes to show the passage of time), since they are not
constant functions. In this case, that's unlikely to matter.
If TheDate < Date Then TheDate = TheDate + 7
If TheDate2 < Date ... ' also?

Alternatively, Date + (7 + vbTuesday - WeekDay(Date)) mod 7
or Date + (6 + vbTuesday - WeekDay(Date)) mod 7 + 1
Set Options = Document.All.Da te.Options
For Count = 1 To 20
Twice as many as I thought you wanted.
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
or Right(100 + Day(TheDate), 2) . IMHO,
that should be made a function, for legibility and modularity.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


And how do you propose to transfer that reward to those who answer your
questions? <URL:http://www.merlyn.demo n.co.uk/index.htm#Spon> .

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/vb-dates.htm> VB maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
14274
by: Bill | last post by:
I need to convert a variable, nNum, into a two-character string. nNum is always less than 100. If nNum is 0, the string needs to be "00", if it's 1, it needs to be "01", if it's 34, it needs to be "34". What's the best way to do this? Thanks,
4
20134
by: Dean G | last post by:
I need to compare two values. one from a text field 'bid' and the other from a field in an sql server database 'maxbid'. The problem is the column in the database has decimal as its data type and i'm getting a type mismatch. does anyone know how to convert 'bid' into decimal from varchar? the field datatype doesnt necessarily have to be decimal although i need two decimal places so it cant be an int. Thanks, Dean
2
8898
by: davidgordon | last post by:
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 ----------------------
5
1393
by: Mike | last post by:
I have an outlook application that I'm thinking about converting to VB.NET. Would it be easier to convert the code over or just re-write the application? thanks
4
5826
by: CJ | last post by:
Hi I'm trying to send email via a c# app, and I've come across various ways to do it, but the way that seems best given my constraints is this little vbscript: Dim theApp, theNameSpace, theMailItem set theApp = CreateObject("Outlook.Application") Set theMailItem = theApp.CreateItem(0)
28
5872
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly. See section 4.7 for Rounding issues.
2
2176
by: LostnCode | last post by:
Hi, Can anyone help, I need to convert his code from vbscript to sharp C# for use with ASP.Net2.0? This is my first time using a forum. I don't know anything about either coding language so would really appreciate it if you could make it as simple as possible. Code convert from VBScript to Sharp C#:
2
2504
by: teecee99 | last post by:
This may be a dumb question but here goes. I have a retail web-site and back end order processing system built with vbscript that is currently hosted on GoDaddy on a shared hosting platform (i.e. I have no access to server based schedulers). We are about to move to a dedicated server so I can now schedule "server" processes. We have a number of ".asp" pages that perform tasks such as tidying up the database that right now we run by...
0
1153
by: pyar | last post by:
Hi guys, I am trying since so long to resolve my query as how to convert VBScript to DLL(.NET DLL).I browsed thru net but no use.So please could anyone of you guys help me out by giving a sample VBScript and steps to convert it.I am really in need of it.Thanx with hopes to get quick replies.
1
1959
by: pyar | last post by:
Hi guys, I am trying since so long to resolve my query as how to Convert VBScript to DLL(.NET DLL).I browsed thru net but no use.So please could anyone of you guys help me out by giving a sample VBScript and steps to convert it.I am really in need of it.Thanx with hopes to get quick replies. Another query : How to load my VBScript to VB.NET?
0
8907
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8817
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8663
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7423
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4396
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1799
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.