Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DOM & VBSCRIPT, Global Variable Problem

Posted on 1998-10-15
3
828 Views
Last Modified: 2009-12-16
I have these two DOM events, I would like the value of g_startTime to be the value from the onunload event but I am not sure how to make it global I have tried a <script> public g_startDate </script> but to no avail.  Basically what I am trying to do is time the interval in seconds between the loading and unloading of a web page.

<SCRIPT FOR=window EVENT=onload LANGUAGE="VBSCRIPT">
  Dim g_endTime
  window.status = "Page is loaded!"
  g_endTime = Now()
  MsgBox("Thanks")
  MsgBox("Start Time: " & g_startTime & " End Time: " & g_endTime)
  MsgBox( (DateDiff("s",g_startTime, g_endTime)) )
</SCRIPT>

<SCRIPT FOR=window EVENT=onunload LANGUAGE="VBSCRIPT">
  window.status = "Page is Unloaded!"
  g_startTime = Now()
  MsgBox("Start Time: " & g_startTime)
</SCRIPT>
0
Comment
Question by:sfranks
  • 2
3 Comments
 

Accepted Solution

by:
tgoglia earned 50 total points
ID: 1440159
You need to define a variable outside of any functions or subroutines to make it global. You can create a separate script tag to define global variables:
<script language="vbscript">
g_startTime=Now()
</script>


0
 

Expert Comment

by:tgoglia
ID: 1440160
I don't know if this the the actual code you are using, but there seems to be a little confusion in the naming of variables.The g_endTime variable is being set in the onload event and the g_startTime variable is being set in the onunload event.

0
 
LVL 1

Author Comment

by:sfranks
ID: 1440161
That is the code I am using and it is correct.   What I want is the time it takes for the page to load.  The onload event fires after the page is done loading.  The onunload event fires when an URL is executed (when the request for the document is sent to the server) so I want the time between the onunload and the onload unfortunately VBs time functions lowest denominator is seconds which unfortunately is not precise enough.  I am therefore going to have to use Jscript.  
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question