Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Week number with DatePart syntax, and Server...

Reply
 
Old 11-21-2008   #1 (permalink)
Benny Pedersen


 
 

Week number with DatePart syntax, and Server...

Hello
I friend of mine who work on a newspaper wanted a script to open
the latest folder. (week numbers included in folder names), so
I had to use the Datepart syntax.

Benny Pedersen, www.fineraw.com
NOTE: e-mail address is outdated.

BTW: Before he can open the folders on "Server on Drive (G", he
most first login the Server with Username and Password. Since I havn't
a server here but just a normal WinXP computer, I can't test this
script, but it seems to work fine when I used my drive C

Is it posible to include something to this vbscript, so he can
also login? Maybe something like this:
User= "his name": vbscript ServerLogin "Connect server and " & User &
Password... ?

option explicit
' OpenWeeksFolder.VBS by Benny Pedersen, Nov 21, 2008
dim fso, wso, WeekNow, WeekNext, Drive _
, PathNow, PathNext, Path, Paths, i

set fso= createObject("scripting.fileSystemObject")
set wso= createObject("wScript.shell")

WeekNow = datePart("ww",now,vbMonday,vbFirstFourDays)
WeekNext= datePart("ww",DateAdd("d",7,now),vbMonday,vbFirstFourDays)

Drv= "G:" '// is the drive on his server.
PathNow = Drv &"\All Weeks\"& WeekNow &"\NEWS "& WeekNow &" PDF\"
PathNext= Drv &"\All Weeks\"& WeekNext &"\NEWS "& WeekNext &" PDF\"

PathNow = fso.buildPath(PathNow, "\")
PathNext= fso.buildPath(PathNext,"\")

if fso.folderExists(PathNext) then
Path= PathNext
else Path= PathNow
end if

if fso.folderExists(Path) then
'// Open the folder (if exist)
wso.run "explorer /select," & Path
else
wScript.quit'// Create the folder if not exist:
if vbYes = msgBox("Create Folder:" & string(2,vbLf) _
& PathNext, 4096 +vbYesNo +vbDefaultButton2, "?") _
then
paths= split(PathNext,"\")
for i= 1 to uBound(paths) -1
paths(0)= paths(0) & "\" & paths(i)
' msgBox "Create the new folder "& paths(0), 4096
if not fso.folderExists(paths(0)) _
then fso.createFolder paths(0)
next
wso.run "explorer /select," & paths(0)
end if
end if

My System SpecsSystem Spec
Old 11-21-2008   #2 (permalink)
Al Dunbar


 
 

Re: Week number with DatePart syntax, and Server...


"Benny Pedersen" <b.pedersen@xxxxxx> wrote in message
news:bbb5af09-d799-4107-b3c0-14bd865ed66b@xxxxxx
Quote:

> Hello
> I friend of mine who work on a newspaper wanted a script to open
> the latest folder. (week numbers included in folder names), so
> I had to use the Datepart syntax.
>
> Benny Pedersen, www.fineraw.com
> NOTE: e-mail address is outdated.
>
> BTW: Before he can open the folders on "Server on Drive (G", he
> most first login the Server with Username and Password.
Do you mean that he logs on *at* the server, either directly by being
physically there, remotely through a remote desktop session, or by some
other means? Or do you mean that he logs onto the domain and gets mapped to
shares on the server as a result.

If it is just a matter of logging on to the domain, then he will not be able
to run a script to do that - without first being logged on. But, once he is
logged on, if the share is mapped, then the script should work, assuming the
drive letter is correct, and permissions allow.

If it is just a matter of getting a drive mapped to a share on the server
where "the latest folder" exists, read up on the MapNetworkDrive method of
the WScript.Network object.

Also, I see a few problems with your script - see comments inline below...
Quote:

> Since I havn't
> a server here but just a normal WinXP computer, I can't test this
> script, but it seems to work fine when I used my drive C
>
> Is it posible to include something to this vbscript, so he can
> also login? Maybe something like this:
> User= "his name": vbscript ServerLogin "Connect server and " & User &
> Password... ?
>
> option explicit
> ' OpenWeeksFolder.VBS by Benny Pedersen, Nov 21, 2008
> dim fso, wso, WeekNow, WeekNext, Drive _
> , PathNow, PathNext, Path, Paths, i
>
> set fso= createObject("scripting.fileSystemObject")
> set wso= createObject("wScript.shell")
>
> WeekNow = datePart("ww",now,vbMonday,vbFirstFourDays)
> WeekNext= datePart("ww",DateAdd("d",7,now),vbMonday,vbFirstFourDays)
>
> Drv= "G:" '// is the drive on his server.
> PathNow = Drv &"\All Weeks\"& WeekNow &"\NEWS "& WeekNow &" PDF\"
> PathNext= Drv &"\All Weeks\"& WeekNext &"\NEWS "& WeekNext &" PDF\"
>
> PathNow = fso.buildPath(PathNow, "\")
> PathNext= fso.buildPath(PathNext,"\")
>
> if fso.folderExists(PathNext) then
> Path= PathNext
> else Path= PathNow
> end if
>
> if fso.folderExists(Path) then
> '// Open the folder (if exist)
> wso.run "explorer /select," & Path
> else
> wScript.quit'// Create the folder if not exist:
If the above wscript.quit statement is executed, then none of the code below
will run.

/Al
Quote:

> if vbYes = msgBox("Create Folder:" & string(2,vbLf) _
> & PathNext, 4096 +vbYesNo +vbDefaultButton2, "?") _
> then
> paths= split(PathNext,"\")
> for i= 1 to uBound(paths) -1
> paths(0)= paths(0) & "\" & paths(i)
> ' msgBox "Create the new folder "& paths(0), 4096
> if not fso.folderExists(paths(0)) _
> then fso.createFolder paths(0)
> next
> wso.run "explorer /select," & paths(0)
> end if
> end if

My System SpecsSystem Spec
Old 11-21-2008   #3 (permalink)
Benny Pedersen


 
 

Re: Week number with DatePart syntax, and Server...

On Nov 21, 9:32*am, "Al Dunbar" <aland...@xxxxxx> wrote:
Quote:

> "Benny Pedersen" <b.peder...@xxxxxx> wrote in message
>
> news:bbb5af09-d799-4107-b3c0-14bd865ed66b@xxxxxx
SNIP
Quote:

> Do you mean that he logs on *at* the server, either directly by being
> physically there, remotely through a remote desktop session, or by some
> other means? Or do you mean that he logs onto the domain and gets mapped to
> shares on the server as a result.
Quote:

> wScript.quit
The "wScript.quit" should be removed later

I don't know what the server is. but it is in another room and he can
see it in the "My Computer" folder, and also he can see it
under Network or something like. The connect box popup on his computer
and on all the other computers at work...

Benny
Btw. to figure out the DatePart syntax ... vbMonday, vbFirstFourDays
would work good,
I just tried all dates 200 years like this:
(First set local language in Control panel, then set it to English
(USA))

option explicit
dim fso, DataFi, iEnd, myDate, f, i, arrLocal, arrOther
set fso= createObject("scripting.fileSystemObject")
DataFi= fso.getSpecialFolder(2) & "\data.tmp"
iEnd= 200 * 365
myDate= now

if fso.fileExists(DataFi) then
set f= fso.openTextFile(DataFi, 1)
arrLocal= split(vbCrLf & f.readAll, vbCrLf): reDim preServe arrLocal
(iEnd)
arrOther= split(""): reDim arrOther(iEnd)
for i= 1 to iEnd
' vbUseSystem vbFirstJan1 vbFirstFourDays vbFirstFullWeek
arrOther(i)= DatePart("ww", myDate, vbMonday, vbFirstFourDays)
myDate = DateAdd("d", 1, myDate)
next
for i= 1 to iEnd
if not arrLocal(i) = cStr(arrOther(i)) then msgBox "Failure. i = "
& i & vbLf _
& "Local: "& arrLocal(i) & vbLf & "Other: "& arrOther(i), 4096:
wScript.quit
next
msgbox "All done. You may now delete the tmp-file, or restart
script", 4096
else
arrLocal= split(""): reDim arrLocal(iEnd)
for i= 1 to iEnd
arrLocal(i)= DatePart("ww", myDate, vbUseSystemDayOfWeek,
vbUseSystem)
myDate = DateAdd("d", 1, myDate)
next
set f= fso.openTextFile(DataFi, 2, -1)
for i= 1 to iEnd
f.writeLine arrLocal(i)
next
msgbox "Now you may change from local to other settings, then
restart script", 4096
end if
f.close: set f= nothing: set fso= nothing
My System SpecsSystem Spec
Old 11-21-2008   #4 (permalink)
Dr J R Stockton


 
 

Re: Week number with DatePart syntax, and Server...

In microsoft.public.scripting.vbscript message <bbb5af09-d799-4107-b3c0-
14bd865ed66b@xxxxxx>, Thu, 20 Nov 2008 22:08:24,
Benny Pedersen <b.pedersen@xxxxxx> posted:
Quote:

>I friend of mine who work on a newspaper wanted a script to open
>the latest folder. (week numbers included in folder names), so
>I had to use the Datepart syntax.
No, you did not have to. It is easy enough to code it using simple
arithmetic and maybe DateSerial, Year, Month, Day, Date.

I expect you want the ISO 8601 Week Number, as is used throughout the
enlightened world; beware of answers from elsewhere, since those
southwest of Greenland frequently do not comply.

Don't use DatePart for ISO 8601 week numbers; it gets three days wrong
per 28 normal years, plus one per 400 years. Microsoft do have
alternative code; but AFAIK they still provide the inadequate version,
and their alternative is horribly bloated. Evidently it was written by
someone who does not use or understand 8601 - probably someone from
RAH's Lookout Mountain Avenue.

Instead, read <URL:http://www.merlyn.demon.co.uk/vb-date2.htm#DP>, but
start at the top of the page. Then use View Source, and seek

Sub WeekNumJRS(Tdy, YNo, WNo, DoW) '' Tdy is CDate in; Y W D out
&
function JRSWeekNum

You can also find a reverse function there. But test carefully.

How about a translation into Windows XP Batch?


And, if you go via my Home Page, you can read it all in something
horribly resembling Danish.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
My System SpecsSystem Spec
Old 11-23-2008   #5 (permalink)
Dr J R Stockton


 
 

Re: Week number with DatePart syntax, and Server...

In microsoft.public.scripting.vbscript message <f91df923-dbd6-4606-baf5-
f5ea4f945a4a@xxxxxx>, Sat, 22 Nov 2008 21:59:04,
Benny Pedersen <b.pedersen@xxxxxx> posted:
Quote:

>Below is a new function with special code,
>Dr J R Stockton, you know that I like to experiment, (or maybe you
>have forgot me?)
That would be difficult.

Quote:

>function DName(byVal X, byVal Lang)
> if len(X) > 2 then
> X= uCase(X)
> select case left(X,1)
>
> case"J"X= mid("761",1-(mid(X,2,1)="A")-(mid(X,3,1)="N"),1)
> case"M"X= mid("35",2+(left(X,3)="MAR"),1)
> case"A"X= mid("48",2+(left(X,2)="AP"),1)
> case"F"X= "2": case"S"X= "9": case"O"X= "10"
> case"N"X= "11": case"D"X= "12"end select
> DName= right("0"& X,2): exit function
> else
I would make a string " JAN FEB MAR ... DEC", find the position in
it of (space & the string supplied), and divide by 4.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
My System SpecsSystem Spec
Old 11-23-2008   #6 (permalink)
Benny Pedersen


 
 

Re: Week number with DatePart syntax, and Server...

On Nov 23, 10:35*pm, Dr J R Stockton <j...@xxxxxx> wrote:
Quote:

> In microsoft.public.scripting.vbscript message <f91df923-dbd6-4606-baf5-
> f5ea4f945...@xxxxxx>, Sat, 22 Nov 2008 21:59:04,
> Benny Pedersen <b.peder...@xxxxxx> posted:
>
Quote:

> >Below is a new function with special code,
> >Dr J R Stockton, you know that I like to experiment, (or maybe you
> >have forgot me?)
>
> That would be difficult.
>
Quote:

> >function DName(byVal X, byVal Lang)
> > *if len(X) > 2 then
> > *X= uCase(X)
> > *select case left(X,1)
>
Quote:

> > *case"J"X= mid("761",1-(mid(X,2,1)="A")-(mid(X,3,1)="N"),1)
> > *case"M"X= mid("35",2+(left(X,3)="MAR"),1)
> > *case"A"X= mid("48",2+(left(X,2)="AP"),1)
> > *case"F"X= "2": case"S"X= "9": case"O"X= "10"
> > *case"N"X= "11": case"D"X= "12"end select
> > *DName= right("0"& X,2): exit function
> > *else
>
> I would make a string * * " * JAN FEB MAR ... DEC", find the position in
> it of (space & the string supplied), and divide by 4.
Hmm,
-----
Dr J R Stockton: Prove right for sure.

Now, my test below proves that Dr. Stockton isn't a mad professor,
but instead our world has just recived a sensational information.
Ok, a bug found in software by Microsoft is not a sensation, but
most likely is very common. Anyway, a bug like this, is comlete
grotesque and ridiculous! If a society is unable to calculate a
calendar, it wouldn't be enlightend, and probably; not civilized
either... So, the question about whether Dr. Stockton is a mad
professor, OR the countries southwest Greenland are living in
the Stone Age, is now answered... (See the script below).

Benny,
BTW. I made a calendar, ("skin-photo" shot by meself),
It use Monday as the first day, and it show the week numbers, HERE:
Url: http://customize.org/rainlendar/skins/53040
(Use up-arrow to jump year. Right click it for further information.)

Note: Also calendars built in mobil phones, is Dr J R Stockton
affirmative...

PS: All code below begins with least two space char.

option explicit' VBS file by Benny Pedersen, www.fineraw.com
dim iEnd: iEnd= 200 * 365' Set number of days.

' Make a DOS-alike display avaible:
if wScript.arguments.count = 0 then
createObject("wScript.shell").run"cScript.exe //nologo " _
&"//d """& wScript.scriptFullName & """ """& iEnd & """"
wScript.quit
end if

' Number of days. Convert (skip string type, add zero
iEnd= wScript.arguments(0) +0

' Display information on the DOS-look-alike screen:
Show "Number of days: "& iEnd +1

' Some variable that we would like to use:
dim BeginDate, SomeDate, i
dim arrJRS(), arrVBS(): reDim arrJRS(iEnd): reDim arrVBS(iEnd)

' Begin:
BeginDate= cStr(now)
i= inStr(BeginDate, chr(32))' Remove space and time info:
if i > 1 then BeginDate= left(BeginDate, i -1)
BeginDate= cDate(BeginDate)
BeginDate= DateAdd("yyyy",-4,BeginDate)' Subtract, e.g. 4 years.

SomeDate= BeginDate
if vbNo = msgBox("Ready to calculate the week numbers" & vbLf _
&"for "& iEnd +1 &" days. Begin Date is "& SomeDate, 4096 +4) _
then wScript.quit
for i= 0 to iEnd
arrJRS(i)= JRSWeekNum(SomeDate)
arrVBS(i)= DatePart("ww", SomeDate, vbMonday, vbFirstFourDays)
SomeDate= cDate(DateAdd("d",1,SomeDate))'increase, add one day.
next
for i= 0 to iEnd
if arrJRS(i) = arrVBS(i) then' Show progress:
Show DateAdd("d",i,BeginDate) & vbTab & "Progress: "& _
i & "//" & iEnd
else' see note no. 1.
msgBox "Failure" & vbLf & string(80,"_") & vbLf _
& "JRS, Dr. Stocton: The week number is: "& arrJRS(i) _
& vbLf _
& "VBS, (Microsoft): The week number is: "& arrVBS(i) _
& string(2,vbLf) & "FATAL Date is: " _
& DateAdd("d",i,BeginDate), 4096, i &"//"& iEnd: wScript.quit
end if
next
msgBox "All Done, OK.", 4096, ""

:function JRSWeekNum(Tdy) '' Tdy is CDate in; return W
Dim N, Thu, YNo, SoY: N = 2
Thu = ((Tdy+3+N) \ 7) * 7 - N '' Nearest Thu
YNo = Year(Thu)
SoY = DateSerial(YNo, 1, 1) '' Date, YYYY-01-01
JRSWeekNum = ((Thu - SoY) \ 7) + 1
end function

sub Show(X)wScript.echo X:end sub

' Note no. 1: (Begin date was November 24, 2008)
' elseIf inStr("01132 05514", right("0000"& i,5)) = 0 then
' 31-12-2007 i=1132
' 30-12-2019 i=5514
' 29-12-2031 i=9896
' failure each 12 years
My System SpecsSystem Spec
Old 11-24-2008   #7 (permalink)
Benny Pedersen


 
 

Re: Week number with DatePart syntax, and Server...

On Nov 23, 10:35*pm, Dr J R Stockton <j...@xxxxxx> wrote:
Quote:

> In microsoft.public.scripting.vbscript message <f91df923-dbd6-4606-baf5-
> f5ea4f945...@xxxxxx>, Sat, 22 Nov 2008 21:59:04,
> Benny Pedersen <b.peder...@xxxxxx> posted:
>
Quote:

> >Below is a new function with special code,
> >Dr J R Stockton, you know that I like to experiment, (or maybe you
> >have forgot me?)
>
> That would be difficult.
>
Quote:

> >function DName(byVal X, byVal Lang)
> > *if len(X) > 2 then
> > *X= uCase(X)
> > *select case left(X,1)
>
Quote:

> > *case"J"X= mid("761",1-(mid(X,2,1)="A")-(mid(X,3,1)="N"),1)
> > *case"M"X= mid("35",2+(left(X,3)="MAR"),1)
> > *case"A"X= mid("48",2+(left(X,2)="AP"),1)
> > *case"F"X= "2": case"S"X= "9": case"O"X= "10"
> > *case"N"X= "11": case"D"X= "12"end select
> > *DName= right("0"& X,2): exit function
> > *else
>
> I would make a string * * " * JAN FEB MAR ... DEC", find the position in
> it of (space & the string supplied), and divide by 4.
>
> --
> *(c) John Stockton, Surrey, UK. *?...@xxxxxx * Turnpikev6.05 * MIME.
> *Web *<URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms,& links.
> *Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
> *Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Hmm,
-----
Dr J R Stockton: Proved right for sure.

Now, my test below proves that Dr. Stockton isn't a mad professor,
but instead our world has just recived a sensational information.
Ok, a bug found in software by Microsoft is not a sensation, but
most likely is very common. Anyway, a bug like this, is comlete
grotesque and ridiculous! If a society is unable to calculate a
calendar, it wouldn't be enlightend, and probably; not civilized
either... So, the question about whether Dr. Stockton is a mad
professor, OR the countries southwest Greenland are living in
the Stone Age, is now answered... (See the script below).

Benny,
BTW. I made a calendar, ("skin-photo" shot by meself),
It use Monday as the first day, and it show the week numbers, HERE:
Url: http://customize.org/rainlendar/skins/53040
(Use up-arrow to jump year. Right click it for further information.)

Note: Also calendars built in mobil phones, is Dr J R Stockton
affirmative...

PS: All code below begins with least two space char.

option explicit' VBS file by Benny Pedersen, www.fineraw.com
dim iEnd: iEnd= 200 * 365' Set number of days.

' Make a DOS-alike display avaible:
if wScript.arguments.count = 0 then
createObject("wScript.shell").run"cScript.exe //nologo " _
&"//d """& wScript.scriptFullName & """ """& iEnd & """"
wScript.quit
end if

' Number of days. Convert (skip string type, add zero
iEnd= wScript.arguments(0) +0

' Display information on the DOS-look-alike screen:
Show "Number of days: "& iEnd +1

' Some variable that we would like to use:
dim BeginDate, SomeDate, i
dim arrJRS(), arrVBS(): reDim arrJRS(iEnd): reDim arrVBS(iEnd)

' Begin:
BeginDate= cStr(now)
i= inStr(BeginDate, chr(32))' Remove space and time info:
if i > 1 then BeginDate= left(BeginDate, i -1)
BeginDate= cDate(BeginDate)
BeginDate= DateAdd("yyyy",-4,BeginDate)' Subtract, e.g. 4 years.

SomeDate= BeginDate
if vbNo = msgBox("Ready to calculate the week numbers" & vbLf _
&"for "& iEnd +1 &" days. Begin Date is "& SomeDate, 4096 +4) _
then wScript.quit
for i= 0 to iEnd
arrJRS(i)= JRSWeekNum(SomeDate)
arrVBS(i)= DatePart("ww", SomeDate, vbMonday, vbFirstFourDays)
SomeDate= DateAdd("d",1,SomeDate)'increase, add one day.
next
for i= 0 to iEnd
if arrJRS(i) = arrVBS(i) then' Show progress:
Show DateAdd("d",i,BeginDate) & vbTab & "Progress: "& _
i & " // " & iEnd
else' see note no. 1.
msgBox "Failure" & vbLf & string(80,"_") & vbLf _
& "JRS, Dr. Stockton: The week number is "& arrJRS(i) _
& vbLf _
& "VBS, (Microsoft): The week number is "& arrVBS(i) _
& string(2,vbLf) & "FATAL Date is: " _
& DateAdd("d",i,BeginDate),4096,i &" // "& iEnd: wScript.quit
end if
next
msgBox "All Done, OK.", 4096, ""

:function JRSWeekNum(Tdy) '' Tdy is CDate in; return W
Dim N, Thu, YNo, SoY: N = 2
Thu = ((Tdy+3+N) \ 7) * 7 - N '' Nearest Thu
YNo = Year(Thu)
SoY = DateSerial(YNo, 1, 1) '' Date, YYYY-01-01
JRSWeekNum = ((Thu - SoY) \ 7) + 1
end function

sub Show(X)wScript.echo X:end sub

' Note no. 1: (Begin date was November 24, 2008)
' elseIf inStr("01132 05514", right("0000"& i,5)) = 0 then
' 31-12-2007 i=1132
' 30-12-2019 i=5514
' 29-12-2031 i=9896
' failure each 12 years
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
The transfer syntax is not supported by the RPC server. (0x800706C2) Vista performance & maintenance
The transfer syntax is not supported by the RPC server. (0x800706C Vista performance & maintenance
The transfer syntax is not supported by the RPC server Vista performance & maintenance
Powershell EventHandling syntax with SQL Server? PowerShell
Week number in Windows Calender? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46