By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

A97: I want a simple text capture on a website (IE, Edit, Select All, CTRL-C)

P: n/a
MLH
After running the following code snippet...

MyURL = "http://tycho.usno.navy.mil/what.html"
msXML.Open "GET", MyURL, False
msXML.send

I would like to execute code to perform essentially
what would amount to clicking Edit, Select All, CTRL-C
in Internet Explorer to capture some basic time 'n date
text from the military site and parse it.

Someone know how to replicate the effect of the
Edit, Select All, CTRL-C keyboard sequence from
within code? I'm hoping SendKeys ISN'T the answer.
Nov 13 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
On Mon, 03 Oct 2005 12:39:37 -0400, MLH <CR**@NorthState.net> wrote:
After running the following code snippet...
MyURL = "http://tycho.usno.navy.mil/what.html"
msXML.Open "GET", MyURL, False
msXML.send
I would like to execute code to perform essentially
what would amount to clicking Edit, Select All, CTRL-C
in Internet Explorer to capture some basic time 'n date
text from the military site and parse it.
Someone know how to replicate the effect of the
Edit, Select All, CTRL-C keyboard sequence from
within code? I'm hoping SendKeys ISN'T the answer.


No need for SendKeys! (<Gack!>) Try the code below instead. For
what it's worth, this isn't really my code, it's some I found on the
web and modified/fixed to actually work. (Note the change in the URL,
which now actually returns a valid time rather then a list of
resources.)

Personally, I prefer to use SNTP for this, using the winsock.ocx file
and linking up on port 123, but here is a HTTP solution for those who
have port 123 locked by their firewall. (See my previous posts on
this for how to do it using the winsock.ocx.)

And, Gee! Look, David! No use of IE! (Yeah, it's so blessed hard to
convert code that uses IE to code that doesn't.... <sigh>)

After pasting the code below into a public module, simply call the
SetComputerTimeFromHTTPAddress function from where ever you need to.

As always... Watch for the wrap!

Option Compare Database
Option Explicit
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3
Private Const scUserAgent = "VB Project"
Private Const INTERNET_FLAG_RELOAD = &H80000000

Private Declare Function InternetOpen _
Lib "wininet.dll" _
Alias "InternetOpenA" _
(ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) _
As Long
Private Declare Function InternetOpenUrl _
Lib "wininet.dll" _
Alias "InternetOpenUrlA" _
(ByVal hOpen As Long, _
ByVal sUrl As String, _
ByVal sHeaders As String, _
ByVal lLength As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) _
As Long
Private Declare Function InternetReadFile _
Lib "wininet.dll" _
(ByVal hFile As Long, _
ByVal sBuffer As String, _
ByVal lNumBytesToRead As Long, _
lNumberOfBytesRead As Long) _
As Integer
Private Declare Function InternetCloseHandle _
Lib "wininet.dll" _
(ByVal hInet As Long) _
As Integer
Private Declare Function GetTimeZoneInformation _
Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) _
As Long
Private Declare Sub GetLocalTime _
Lib "kernel32" _
(localTime As SYSTEMTIME)
Private Declare Sub SetLocalTime _
Lib "kernel32" _
(localTime As SYSTEMTIME)
Sub LocalZoneTime(tmUniversal As SYSTEMTIME, tmLocal As SYSTEMTIME)
Dim TZI As TIME_ZONE_INFORMATION
Dim retCode As Long
Dim iStandardMonth As Integer
Dim iDaylightMonth As Integer
Dim nZoneCorrection As Long
Dim nTotalMinutes As Integer

retCode = GetTimeZoneInformation(TZI)
iStandardMonth = TZI.StandardDate.wMonth
iDaylightMonth = TZI.DaylightDate.wMonth
nZoneCorrection = TZI.Bias

If retCode = 1 Then 'TIME_ZONE_ID_STANDARD
nZoneCorrection = nZoneCorrection + TZI.StandardBias
ElseIf retCode = 2 Then ' TIME_ZONE_ID_DAYLIGHT
nZoneCorrection = nZoneCorrection + TZI.DaylightBias
Else
Debug.Assert (0)
End If

nZoneCorrection = -nZoneCorrection
nTotalMinutes = tmUniversal.wHour * _
60 + _
tmUniversal.wMinute + _
nZoneCorrection

If nTotalMinutes < 0 Then
nTotalMinutes = nTotalMinutes + 24 * 60
End If
If nTotalMinutes > 24 * 60 Then
nTotalMinutes = nTotalMinutes - 24 * 60
End If
tmLocal.wHour = Int(nTotalMinutes / 60)
tmLocal.wMinute = nTotalMinutes - tmLocal.wHour * 60
tmLocal.wSecond = tmUniversal.wSecond
End Sub
Public Function SetComputerTimeFromHTTPAddress( _
Optional strWebUrl As String = _
"http://tycho.usno.navy.mil/cgi-bin/timer.pl")
Dim hInternet As Long
Dim hHttp As Long
Dim bRet As Boolean
Dim sBuff As String * 2048
Dim lNumberOfBytesRead As Long
Dim sBuffer As String
Dim dtOldTime As SYSTEMTIME
Dim tmLocal As SYSTEMTIME
Dim tmUniversal As SYSTEMTIME
Dim sRep

hInternet = InternetOpen(scUserAgent, _
INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, _
vbNullString, _
0)
If hInternet = 0 Then Debug.Assert (0)

hHttp = InternetOpenUrl(hInternet, _
strWebUrl, _
vbNullString, _
0, _
INTERNET_FLAG_RELOAD, _
0)
If hHttp = 0 Then Debug.Assert (0)

sBuff = vbNullString
bRet = InternetReadFile(hHttp, _
sBuff, _
Len(sBuff), _
lNumberOfBytesRead)
sBuffer = sBuffer & Left$(sBuff, lNumberOfBytesRead)
If hHttp <> 0 Then InternetCloseHandle (hHttp)
If hInternet <> 0 Then InternetCloseHandle (hInternet)

Call GetLocalTime(tmLocal)
dtOldTime = tmLocal

Dim buffPos As Integer
buffPos = InStr(1, sBuff, "UTC")

If Not buffPos > 0 Then
MsgBox ("Unrecognized communication error!")
Exit Function
End If

Select Case Mid$(sBuff, buffPos - 18, 3)
Case "Jan"
tmUniversal.wMonth = 1
Case "Feb"
tmUniversal.wMonth = 2
Case "Mar"
tmUniversal.wMonth = 3
Case "Apr"
tmUniversal.wMonth = 4
Case "May"
tmUniversal.wMonth = 5
Case "Jun"
tmUniversal.wMonth = 6
Case "Jul"
tmUniversal.wMonth = 7
Case "Aug"
tmUniversal.wMonth = 8
Case "Sep"
tmUniversal.wMonth = 9
Case "Oct"
tmUniversal.wMonth = 10
Case "Nov"
tmUniversal.wMonth = 11
Case "Dec"
tmUniversal.wMonth = 12
End Select
tmUniversal.wDay = Mid$(sBuff, buffPos - 13, 2)
tmUniversal.wHour = Mid$(sBuff, buffPos - 9, 2)
tmUniversal.wMinute = Mid$(sBuff, buffPos - 6, 2)
tmUniversal.wSecond = Mid$(sBuff, buffPos - 3, 2)

' Calculate Local Time using received Universal Time.
Call LocalZoneTime(tmUniversal, tmLocal)
Call SetLocalTime(tmLocal)
MsgBox "Time Set Successful"
End Function
--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Nov 13 '05 #2

P: n/a
Why not just synchronise your computer's time and then use Date and/or
Now and DatePart to get whatever measure you want?

Public Sub SynchroniseTime()
Shell "w32tm /config /syncfromflags:manual
/manualpeerlist:time.nist.gov"
Shell "w32tm /config /update"
MsgBox DatePart("n", Now()) 'minutes
End Sub

Well, maybe you don't want to synchronise your computer's time, or
maybe you think the microseconds this code might take to run are of
consequence.

Nov 13 '05 #3

P: n/a
MLH
I tried it. MsgBox returns a number that I believe is my current
time's MINUTES setting. But the facility is not changing my
system date/time. Hmmm???

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Why not just synchronise your computer's time and then use Date and/or
Now and DatePart to get whatever measure you want?

Public Sub SynchroniseTime()
Shell "w32tm /config /syncfromflags:manual
/manualpeerlist:time.nist.gov"
Shell "w32tm /config /update"
MsgBox DatePart("n", Now()) 'minutes
End Sub

Well, maybe you don't want to synchronise your computer's time, or
maybe you think the microseconds this code might take to run are of
consequence.


Nov 13 '05 #4

P: n/a
MLH
Can I get by w/o the debug.assert lines? They show up in red when
I paste them into an A97 global module. They appear to be VBE
specific tools. I'm gonna try remming them out.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx

No need for SendKeys! (<Gack!>) Try the code below instead. For
what it's worth, this isn't really my code, it's some I found on the
web and modified/fixed to actually work. (Note the change in the URL,
which now actually returns a valid time rather then a list of
resources.)

Personally, I prefer to use SNTP for this, using the winsock.ocx file
and linking up on port 123, but here is a HTTP solution for those who
have port 123 locked by their firewall. (See my previous posts on
this for how to do it using the winsock.ocx.)

<snip the snippet>
Nov 13 '05 #5

P: n/a
Chuck Grimsby <c.*******@worldnet.att.net.invalid> wrote in
news:50********************************@4ax.com:

[]
Personally, I prefer to use SNTP for this, using the winsock.ocx
file and linking up on port 123, but here is a HTTP solution for
those who have port 123 locked by their firewall. (See my
previous posts on this for how to do it using the winsock.ocx.)

And, Gee! Look, David! No use of IE! (Yeah, it's so blessed
hard to convert code that uses IE to code that doesn't.... <sigh>)


But it uses an OCX, which for me is just as bad as using IE, since
it introduces an outside dependency into your app.

Furthermore, it's an OCX that you can only acquire legally with VB.

I did substantial research on this problem, and could find only
solutions that used the VB Winsock control, or used a VB class that
I couldn't figure out how to convert for use in Access.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6

P: n/a
MLH
Say, Chuck, mind telling how you happened upon
that URL? I'm not much of a surfer. I don't know
how you found that site.
Nov 13 '05 #7

P: n/a
"lylefair" <ly***********@aim.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:
Why not just synchronise your computer's time and then use Date
and/or Now and DatePart to get whatever measure you want?

Public Sub SynchroniseTime()
Shell "w32tm /config /syncfromflags:manual
/manualpeerlist:time.nist.gov"
Shell "w32tm /config /update"
MsgBox DatePart("n", Now()) 'minutes
End Sub

Well, maybe you don't want to synchronise your computer's time, or
maybe you think the microseconds this code might take to run are
of consequence.


Surely there's more latency in the cross-Internet connection to a
time server than there would be in running the code.

Looks like a keeper to me!

I just never realized that Windows had a time server utility that
wasn't bound only to NETBios.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8

P: n/a
MLH
Oh rats! The site doesn't display the year.
I just realized that.
Nov 13 '05 #9

P: n/a
"lylefair" <ly***********@aim.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:
Why not just synchronise your computer's time and then use Date
and/or Now and DatePart to get whatever measure you want?

Public Sub SynchroniseTime()
Shell "w32tm /config /syncfromflags:manual
/manualpeerlist:time.nist.gov"
Shell "w32tm /config /update"
MsgBox DatePart("n", Now()) 'minutes
End Sub

Well, maybe you don't want to synchronise your computer's time, or
maybe you think the microseconds this code might take to run are
of consequence.


Well, I responded too soon -- the comandline arguments you are using
do not show up as being supported in the w32tm.exe on my Win3K box.

Care to explain what it does?

Also, when I run w32tm -once, it tells me it can't connect and will
wiat 15 minutes for next lookup. It appears to think it needs to use
an NT domain controller, which gets me back to my reason for
thinking the buit-in Windows utilities for this wouldn't work.

Your commandline does not work on my system, so that means it won't
work on some unpredictable number of systems, and is thus not usable
in general.

Too bad.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10

P: n/a
David W. Fenton wrote:
"lylefair" <ly***********@aim.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:
Why not just synchronise your computer's time and then use Date
and/or Now and DatePart to get whatever measure you want?

Public Sub SynchroniseTime()
Shell "w32tm /config /syncfromflags:manual
/manualpeerlist:time.nist.gov"
Shell "w32tm /config /update"
MsgBox DatePart("n", Now()) 'minutes
End Sub

Well, maybe you don't want to synchronise your computer's time, or
maybe you think the microseconds this code might take to run are
of consequence.


Well, I responded too soon -- the comandline arguments you are using
do not show up as being supported in the w32tm.exe on my Win3K box.

Care to explain what it does?

Also, when I run w32tm -once, it tells me it can't connect and will
wiat 15 minutes for next lookup. It appears to think it needs to use
an NT domain controller, which gets me back to my reason for
thinking the buit-in Windows utilities for this wouldn't work.

Your commandline does not work on my system, so that means it won't
work on some unpredictable number of systems, and is thus not usable
in general.

Too bad.


This is from MS:

http://www.microsoft.com/resources/d...ime_w32tm.mspx

**** begin quote ****

W32tm

A tool used to diagnose problems occurring with Windows Time
Syntax

{/config [/computer:ComputerName] [ [/update]
[/manualpeerlist:ListOfComputerNames] ] [/syncfromflags:ListOfFlags]
]|/monitor|/ntte|/ntpte|/register|/resync [{:ComputerName]
[/nowait]|[/rediscover}]|/tz|/unregister}
Top of pageTop of page
Parameters

/config [/computer:ComputerName] [ [/update]
[/manualpeerlist:ListOfComputerNames] ] [/syncfromflags:ListOfFlags] :
Adjusts the time settings on the local or target computer. Time
synchronization peers can be set with the /manualpeerlist switch.
Changes to configuration are not used by Windows Time unless the service
is restarted or the /update switch is used. /syncfromflags can be used
to set the types of sources used for synchronization, and can be set to
either MANUAL to use the manual peer list or DOMHIER to synchronize from
a domain controller.

/monitor : Monitors the target computer or list of computers.

/ntte : Converts an NT system time into a readable format.

/ntpte : Converts an NTP time into a readable format.

/register : Register to run as a service and add default configuration
to the registry.

/resync [{:ComputerName] [/nowait]|[/rediscover}] : Resynchronize the
clock as soon as possible, disregarding all accumulated error
statistics. If no computer is specified, the local computer will
resynchronize. The command will wait for resynchronization unless the
/nowait switch is used. Currently used time resources will be used
unless /rediscover is used, which will force redetection of network
resourced before resynchronization.

/tz : Display the current time zone settings.

/unregister : Unregister service and remove all configuration
information from the registry.

/? : Displays help at the command prompt.
Top of pageTop of page
Remarks


This tool is designed for network administrators to use for diagnosing
problems with Windows Time.

For more information, see net time in Related Topics.


For the Windows Time service to use the changed made with W32tm, it must
be notified of the changes. To notify Windows Time, at the command
prompt, type w32tm /config /update.

Examples

To display the current time zone settings, type:

w32tm /tz

**** end quote ****

Not having any machines other than XP machines I was unaware that this
was not universally implemented.

There are many free synchronizers; any one of these could be run
(shelled) to synchronize the local computer's time.
Nov 13 '05 #11

P: n/a

Sure. Just comment them out.

Or better yet, replace them with "real" error traps.

On Thu, 06 Oct 2005 21:18:47 -0400, MLH <CR**@NorthState.net> wrote:
Can I get by w/o the debug.assert lines? They show up in red when
I paste them into an A97 global module. They appear to be VBE
specific tools. I'm gonna try remming them out.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx

No need for SendKeys! (<Gack!>) Try the code below instead. For
what it's worth, this isn't really my code, it's some I found on the
web and modified/fixed to actually work. (Note the change in the URL,
which now actually returns a valid time rather then a list of
resources.)
Personally, I prefer to use SNTP for this, using the winsock.ocx file
and linking up on port 123, but here is a HTTP solution for those who
have port 123 locked by their firewall. (See my previous posts on
this for how to do it using the winsock.ocx.)

<snip the snippet>

--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Nov 13 '05 #12

P: n/a
On Thu, 06 Oct 2005 20:24:44 -0500, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
Chuck Grimsby <c.*******@worldnet.att.net.invalid> wrote in
news:50********************************@4ax.com :
Personally, I prefer to use SNTP for this, using the winsock.ocx
file and linking up on port 123, but here is a HTTP solution for
those who have port 123 locked by their firewall. (See my
previous posts on this for how to do it using the winsock.ocx.)
And, Gee! Look, David! No use of IE! (Yeah, it's so blessed
hard to convert code that uses IE to code that doesn't.... <sigh>)
But it uses an OCX, which for me is just as bad as using IE, since
it introduces an outside dependency into your app.
Furthermore, it's an OCX that you can only acquire legally with VB.
I did substantial research on this problem, and could find only
solutions that used the VB Winsock control, or used a VB class that
I couldn't figure out how to convert for use in Access.


Go back and this time actually _look_ at the code I posted, David.

The code I posted does *NOT* require the winsock.ocx. It's a API only
solution. I only *referred* to code that used the winsock.ocx.

As for being unable to convert code that uses a OCX to one that uses
APIs (especially the winsock.ocx), well.... That isn't all that hard
either. It's tedious, to be sure, but it's not all that hard. Just a
ton of lines of code. I did it once, but decided there wasn't much
advantage to it.

Oh, and before I forget, there are plenty of _other_ OCX files about
that do NTP and SNTP. Mabry (if memory serves) has one, as do many
others. If you prefer to buy a control and not use Microsoft's, there
are plenty of options. Personally, I have several VB licenses, so MS'
control is not an issue.

I do have a half-memory about the MS winsock.ocx license also being
available to any Developer edition license holder, but it's only a
half-memory. You'll probably want to check on that to be sure. I
know it's no big deal to download the ocx....

Oh, wait... here:
http://support.microsoft.com/default...b;en-us;179117
ACC97: ActiveX Controls Installed by Microsoft Access, ODE, and Other
Programs

The following ActiveX controls are designed for use with Microsoft
Access 97 or run-time applications created using the Microsoft Office
97 Developer Edition Tools (ODE):
....
WinSock Control MSWINSCK.OCX 106,256 12/12/96
5.00.3601
....

So it appears that the use of the winsock.ocx file is a non-issue.
Maybe you ended your "substantial research" a bit too early? Or
perhaps you don't have the Developer edition. There's a link on that
page to the Office license fix program, if that's the problem you are
having.
--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Nov 13 '05 #13

P: n/a
On Thu, 06 Oct 2005 21:26:03 -0400, MLH <CR**@NorthState.net> wrote:
Say, Chuck, mind telling how you happened upon
that URL? I'm not much of a surfer. I don't know
how you found that site.


I think I just googled "NTP VB", and it popped up a few pages down.
--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Nov 13 '05 #14

P: n/a
On Thu, 06 Oct 2005 21:33:51 -0400, MLH <CR**@NorthState.net> wrote:
Oh rats! The site doesn't display the year.
I just realized that.


Good catch! I hadn't noticed that myself... (Drat!)

Switch to using http://tycho.usno.navy.mil/cgi-bin/anim as strWebUrl,
and replace the part the parses the page to:

Select Case Mid$(sBuff, buffPos - 22, 3)
Case "Jan"
tmUniversal.wMonth = 1
Case "Feb"
tmUniversal.wMonth = 2
Case "Mar"
tmUniversal.wMonth = 3
Case "Apr"
tmUniversal.wMonth = 4
Case "May"
tmUniversal.wMonth = 5
Case "Jun"
tmUniversal.wMonth = 6
Case "Jul"
tmUniversal.wMonth = 7
Case "Aug"
tmUniversal.wMonth = 8
Case "Sep"
tmUniversal.wMonth = 9
Case "Oct"
tmUniversal.wMonth = 10
Case "Nov"
tmUniversal.wMonth = 11
Case "Dec"
tmUniversal.wMonth = 12
End Select
tmUniversal.wDay = Mid$(sBuff, buffPos - 18, 2)
tmUniversal.wHour = Mid$(sBuff, buffPos - 15, 2)
tmUniversal.wMinute = Mid$(sBuff, buffPos - 12, 2)
tmUniversal.wSecond = Mid$(sBuff, buffPos - 9, 2)
tmUniversal.wYear = Mid$(sBuff, buffPos - 6, 4)

--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Nov 13 '05 #15

P: n/a
Chuck Grimsby <c.*******@worldnet.att.net.invalid> wrote in
news:4u********************************@4ax.com:
So it appears that the use of the winsock.ocx file is a non-issue.
Maybe you ended your "substantial research" a bit too early?


For me, OCX's are a deal breaker, whatever the licensing issues.

I don't ship apps with OCX's because I did that once with A2K and
it's way too much trouble to convert to new versions of Access and
to install the damned things. Indeed, one of the two apps that used
OCX's is still running in Access 2 because it's too much work to
convert it to a modern version of Access.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #16

P: n/a
MLH
Well, there you go. Google is my friend.
Nov 13 '05 #17

P: n/a
MLH
Can't wait to try it out.
Nov 13 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.