Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 14th, 2003, 07:47 AM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBScript Sub is executed twice....

Hello,

My following code executes the VBScript sub twice. Could someone help me figure out why this happens?
Thanks.
================================================== ==============
<HEAD>
    <LINK REL=StyleSheet HREF='/BPA/inc/pubstyle.css' TYPE='text/css' MEDIA=screen>
    <SCRIPT LANGUAGE="VBScript">

sub Templates_OnClick()

    Dim oExcel, oSheet
    Dim intFieldId(50), intCnt

    On Error Resume Next
    Set oExcel=GetObject(,"Excel.Application")
    If TypeName(oExcel) <> "Application" Then
           Set oExcel=CreateObject("Excel.Application")
    End If

    oExcel.Visible=False

    oExcel.WorkBooks.Open "c:\test.xls"

    intCnt=1
    For Columns=1 To 12
        intFieldId(Columns)=oExcel.ActiveSheet.Cells(1,Col umns)
    Next

    MsgBox intFieldId(3)

    oExcel.WorkBooks.Close
    oExcel.Quit
    Set oExcel = Nothing
End Sub

    </SCRIPT>

</HEAD>
<%

    Dim intMode
    Dim i

    intMode=Request.QueryString("Mode")

    If CInt(intMode) = 10 Then
        %><BODY onLoad="window.close()"><%
    Else
        %><BODY>

        <FORM NAME="Templates" METHOD=POST ACTION="offline.asp?mode=10">
        <INPUT TYPE="HIDDEN" NAME=temp Value=0>
        <INPUT TYPE="SUBMIT" NAME=Templates Value="Begin">
        </FORM>
        <%

    End If

%>
</BODY>
</HTML>

Reply With Quote
  #2 (permalink)  
Old April 12th, 2004, 12:43 AM
Registered User
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you sort this out ? I notice you are creating two objects (excel.application) you only need one
Reply With Quote
  #3 (permalink)  
Old April 22nd, 2009, 02:58 AM
Authorized User
 
Join Date: Apr 2009
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Post

It looks to me like you listed your Subroutine Procedure before your Main Program Procedure.

?Am I correct in this assessment?

Your Subroutine Procedures should be listed after your Main Program Procedures.

Because I have written lots of different Computer Programs, I have developed a Basic Layout Programs "BASIC-0#.BAS" for GW-BASIC and "Setup-0#.vbs" for VBScript.

My "BASIC-0#.BAS" and "Setup-0#.vbs" Programs also include Generic Routines that I want to use in all of my Computer Programs; thus, when I create a new Computer Programming Project, I Open up one of my "Setup.vbs" Programs, make changes to the Program Information, then start on my new Programming Project placing my New Code under the appropriate Section Headings.

I am new to Windows Programming; thus, my Basic Program Layout isn't really suitable for the Mini-Programming that VBScript is aimed at.

Although significantly different from my "BASIC-0#.BAS" Layout, my "Setup-0#.vbs" Layout looks like the following:

Code:
 
' V I S U A L   B A S I C   P R O G R A M M I N G   N O T E S
 
' A U T H O R ' S   N O T E S   &   E D I T I N G   N O T E S
 
' D E C L A R E D   V A R I A B L E S   &   C O N S T A N T S
 
' F I L E N A M E . V B S   M A I N   P R O G R A M
 
' F I L E N A M E . V B S   P R O C E D U R E S
 
' S E T U P . V B S   P R O C E D U R E S

Last edited by Tandy1000SL GW-BASIC; April 22nd, 2009 at 03:05 AM..
Reply With Quote
  #4 (permalink)  
Old April 22nd, 2009, 06:06 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Okay, another answer to a FIVE year old post. Why?

Also, another incorrect answer.

VBScript DOES NOT CARE whether the subroutines are before or after the main code.

You may be expert in GW BASIC, but your answers are irrelevant to VBScript.
Reply With Quote
  #5 (permalink)  
Old April 30th, 2009, 09:05 PM
Authorized User
 
Join Date: Apr 2009
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ONE
My replies to old Postings is because I am new to these Forums; and, have to change my Forum Settings.

TWO
This time, I will agree with you that I am wrong in my answer.
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
why is this code executed twice? hertendreef ASP.NET 2.0 Basics 1 February 23rd, 2007 06:05 AM
external.js not executed cyrus67 Javascript 2 November 17th, 2006 10:29 AM
how to grab and store executed value of url method PHP How-To 0 March 30th, 2006 01:57 PM
IsPostback executed twice amantona ASP.NET 1.0 and 1.1 Professional 3 February 3rd, 2005 08:41 AM
viewing executed programs Jonmark BOOK: Beginning Java 2 4 February 19th, 2004 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.