Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 16th, 2014, 12:16 PM
Authorized User
Points: 129, Level: 2
Points: 129, Level: 2 Points: 129, Level: 2 Points: 129, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2009
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Functions & Subroutines

NOTE: Subroutine = Subsequence

The following Code is my "Basic Page Setup" for my Visual BASIC Script Projects; which, primarily is focused on Computer Game System Programming.

I do make modifications to this "Basic Page Setup" for each VBS Project; based on, the Computer System being used; and, the Printer being used; and, whether Letter, or Legal, Paper is being used for Printouts.

Actually, this VBS "Basic Page Setup" is a direct evolution of my GW-BASIC "BASIC-#0.BAS" Program Files that served as "Basic Page Setup" for my various GW-BASIC Projects that involved Computer Game System Programming and Artificial Intelligence Research Programming and other minor projects back in 1992.

Code:
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111
'00000000011111111112222222222333333333344444444445555555555666666666677777777778888888888999999999900000000001111111111222222222233333333334444444444555555
'12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
                                                                             '
'PAGE SETUP SETTINGS:  8-1/2"X14" Legal     Landscape     Left: 0.25     Right: 0.75     Top: 0.25     Bottom: 0.25     FONT: Batangche     FONT SIZE: 10
'PRINTER SYSTEM:  HP Officejet Pro 8600 Plus

'NOTEPAD FILE SIZE:  15 KB							'PRINTOUT COMMAND LINES PER PAGE / TOTAL COMMAND LINES:  42 / 306
	'	'	'	'	'	'	'	'	'	'
'FILENAME:  VBSpavilion.vbs							PROGRAMMING LANGUAGE:  Visual BASIC Script
'COMPUTER PROGRAMMING LANGUAGE PLATFORM:  Microsoft Windows 8 Script Host	COMPUTER SYSTEM:  DELL Inspiron mini

'CREATED ON:  31 March 2014							EDITED ON:  16 April 2014

'COMPUTER PROGRAM CODE AUTHORS / COMPUTER PROGRAM CREATORS & DESIGNERS:  1
'Steven T. Querin (Original Programmer/Creator/Designer)
	'1750 Quail Run Rd. : Lytle, Tx. 78052 : (830) 772-5780 : stqcom@lycos.com

'TOTAL ADDITIONAL PROGRAM FILES SIZE:  # Bytes + ? Bytes = #? Bytes

'ADDITIONAL FILE NAMES USED BY [VBSPAVILION.VBS]:  1
'Visual BASIC Script Engine (required for RUNning the [VBSpavilion.vbs] code)     ? Bytes (varies with the Visual BASIC Script Engine Version being used)

'ADDITIONAL FILE NAMES CREATED BY [VBSPAVILION.VBS]:  0

' T A B L E   O F   C O N T E N T S
'Pg 000     PROGRAM FILE INFORMATION
'Pg 000     TABLE OF CONTENTS
'Pg 000     [VBSPAVILION.VBS] CONCEPTION & CREATION NOTES
'Pg 000     AUTHORS' NOTES
'Pg 000     EDIT NOTES
'Pg 000     PREFIXES FOR VARIABLES & CONSTANTS & FUNCTIONS & SUBROUTINES
'Pg 000     USED FUNCTION NAMES
'Pg 000     USED SUBROUTINE NAMES
'Pg 000     DECLARED VARIABLES
'Pg 000     DECLARED CONSTANTS
'Pg 000     VISUAL GRAPHICS
'Pg 000     COPY-N-PASTE COMMAND LINES
'Pg 000     INTRODUCTION
'Pg 000     MAIN PROGRAM
'Pg 000     END OF PROGRAM
'Pg 000     [VBSPAVILION.VBS] PROCEDURES



' A U T H O R S '   N O T E S
'13 MARCH 2014 - STEVEN T. QUERIN -- [HPpavilion.vbs] is an edited version of the [DELLmini.vbs] Program.  [HPpavilion.vbs] is designed to be a "BASIC CODE_
' SETUP" Document like my GW-BASIC "BASIC*.BAS" Files and my Visual BASIC Script "*Setup.vbs" Files.  I initially created [HPpavilion.vbs] to work on my_
' [Quick-Play2.vbs] Files & Printouts on the HP Pavilion p7-1421 Desktop Computer System.

'13 APRIL 2014 - STEVEN T. QUERIN -- I had accidentally overwritten [HPpavilion.vbs] with my [VBSgame-p7.vbs] Program while creating the [VBSgame-p7.vbs]._
'  Today, I am copying the "13 APRIL 2014 PRINTOUT" Version of [VBSpavilion.vbs] into the "13 APRIL 2014 EDIT" Version of [VBSpavilion.vbs].

'13 APRIL 2014 - STEVEN T. QUERIN -- I have decided to keep some of the saved [VBSgame-p7.vbs] Coding.  I also added New Coding that was part of the_
' Current [VBSgame-p7.vbs] Code to Update [VBSpavilion.vbs] with better Coding Sequences.  The current "HelloPlayer" Function & "GoodbyePlayer" Function do_
' need to be Updated.  I only did a Partial Update on those Functions.  A Full Update would require creating new Variables and addition Code Sequences.  At_
' this time, I am recreating [VBSpavilion.vbs] because I am wanting to use [VBSpavilion.vbs] for creating Artificial Intelligence Coding using the Visual_
' BASIC Script Computer Programming Language.  Editing [VBSpavilion.vbs] is a distraction from my Visual BASIC Script Artificial Intelligence Coding_
' Project.

'15 APRIL 2014 - STEVEN T. QUERIN -- I am Renaming [HPpavilion.vbs] to [VBSpavilion.vbs].  This was initially an unconscious activity brought about my own_
' habitual use of "VBS" in my Visual BASIC Script Filenames.  However, I like the "VBS" more than the "HP"; so, I am embracing the "VBS" Filename change._
' This is relevant to the Printouts of [HPpavilion.vbs] Codes and [VBSpavilion.vbs] Codes.

'15 APRIL 2014 - STEVEN T. QUERIN -- Because of my work with [VBSgame-p7.vbs] and [VBS-AI.vbs] and [VBSplanetology.vbs], I have decided to Update the_
' [HPpavilion.vbs] Code.  [HPpavilion.vbs] did have some Coding Errors and Incomplete Coding Sequences; which, revealed themselves to New Visual BASIC_
' Script Projects that needed to be addressed; so, I fixed those errors today.  I created the "CONCEPTION & CREATION NOTES" Section; because, some of my_
' Visual BASIC Script Project will be using such Sections; while, some of my Visual BASIC Script Projects won't be using such Sections.  I deemed it to be_
' more beneficial to me to include "CONCEPTION & CREATION NOTES" in the [VBSpavilion.vbs] Base Code.  This is also true with the "VISUAL GRAPHICS" Section;_
' which, basically only contains the "InputBox" Function & "MsgBox" Function Sequencing Notes.  Even though, I won't be fully utilizing the "InputBox"_
' Function & "MsgBox" Box Function capabilities, I have deemed that having the Code Sequencing Notes listed in the Code is more beneficial to me.



' E D I T   N O T E S
'15 APRIL 2014 - EDIT-STQ -- Renamed Filenames to [VBSpavilion.vbs] & [VBSPAVILION.VBS]; Updated "TABLE OF CONTENTS" Section; Created "[VBSPAVILION.VBS]_
' CONCEPTION & CREATION NOTES" Section; Updated "PREFIXES FOR VARIABLES & CONSTANTS & FUNCTIONS & SUBROUTINES" Section; Updated "DECLARED VARIABLES"_
' Section; Updated "InputBox" Function sequencing; Updated "MsgBox" Function sequencing; Added "Computer Program Information" MessageBox in the_
' "INTRODUCTION" Section; Added "Computer Program Introduction" MessageBox to the "INTRODUCTION" Section; Revised "Computer Program Finish Time" MessageBox_
' sequencing in the 'END OF PROGRAM" Section; Revised "Computer Program Duration" MessageBox sequencing in the "END OF PROGRAM" Section; Revised_
' "PlayerName" InputBox sequencing in the "HelloPlayer" Function in the "[VBSPAVILION.VBS] PROCEDURES" Section; Renamed "PlayerName" InputBox Variable to_
' "PlayerNameInput"; Renamed "PlayerName" Variable in "GoodbyePlayer" Function in the "[VBSPAVILION.VBS] PROCEDURES" Section to "PlayerNameInput"; Created_
' 2 AUTHORS' NOTES

'16 APRIL 2014 - EDIT-STQ -- Edited "Computer Program Duration" MessageBox sequence; Corrected Right Margin Spacing in "15 APRIL 2014 - EDIT-STQ" EDIT_
' NOTE;_



' P R E F I X E S   F O R   V A R I A B L E S   &   C O N S T A N T S   &   F U N C T I O N S   &   S U B R O U T I N E S

'dtm     Date & Time Moment
'int     Integer Variable
'str     String Variable


' U S E D   F U N C T I O N   N A M E S

'TimeSeeder     Random Seed Number Generator using the "Time" Function

'HelloPlayer     the Computer Hello Greets the User
'GoodbyePlayer     the Computer Good-Bye Greets the User



' U S E D   S U B R O U T I N E   N A M E S



' D E C L A R E D   V A R I A B L E S

Dim dtmNumber     'Time generated by the "Time" Function during the RUNning of this Program / Multi-Generated
Dim dtmNumber0     'Time generated by the "Time" Function upon Starting this Program / Single-Generated
Dim dtmNumber1     'Time generated by the "Time" Function upon ENDing this Program / Single-Generated

Dim SessionHours     'Time generated by subtracting the "Hour(dtmNumber0)" Variable from the "Hour(dtmNumber1)" Variable / Single-Generated
Dim SessionMinutes     'Time generated by subtracting the "Minute(dtmNumber0)" Variable from the "Minute(dtmNumber1)" Variable / Single-Generated
Dim SessionSeconds     'Time generated by subtracting the "Second(dtmNumber0) Variable from the "Second(dtmNumber1)" Variable / Single-Generated

Dim dtmSeed     'Seed Number generated by the "Time" Function during the RUNning of this Program / Multi-Generated
Dim dtmSeed0     'Seed Number generated by the "Time" Function upon Starting this Program / Single-Generated
Dim dtmSeed1     'Seed Number generated by adding the "dtmSeed"0" & "dtmSeed" Variables together / Multi-Generated

Dim Randomizer     'Variable used for calling Random Number Generator Procedures

Dim TryAgain     '"Yes/No" Do-While Loop Variable used for repeating a Block Of Code

Dim VisitorUser     'Variable used for calling User-Computer Interaction Procedures
Dim Response     'Variable used for Computer Messages based on the User's Input box Entries

Dim PlayerNameInput     'Variable used for identifying the User's Input in the "PlayerNameInput" InputBox for identifying the name of the User
Dim PlayerName     'Variable used for identifying the name of the User
Dim Hello     'Variable used for the Computer's Hello Greeting to the User
Dim Goodbye     'Variable used for the Computer's good-Bye greetings to the User



' D E C L A R E D   C O N S T A N T S



' V I S U A L   G R A P H I C S

'InputBox(prompt, title, default, xpos, ypos, helpfile, context)
  'prompt     InputBox Message
  'title     TitleBar Text
  'default     String Data displayed while Loading
  'xpos     distance from Screen Left Edge to InputBox Left Side
  'ypos     distance from Screen Top Edge to InputBox Top Side
  'helpfile     Help File Data within Help Button
  'context     Help File Context Number with Help Button

'MsgBox(prompt, buttons, title, helpfile, context)
  'prompt     Message Box Text
  'buttons     Message Box Buttons
  'title     TitleBar Text
  'helpfile     Help File Name for the Message Box within Help Button
  'context     Help File ID with Help Button

'Const vbOKOnly = 0     'display only the [OK] button
'Const vbOKCancel = 1     'display the [OK] & [Cancel] Buttons
'Const vbYesNoCancel = 3     'display the [Yes] & [No] & [Cancel] Buttons
'Const vbYesNo = 4     'display the [Yes] & [No] Buttons

'Const vbOkay = 1     'the [OK] Button was Clicked
'Const vbCancel = 2     'the [Cancel] Button was Clicked
'Const vbYes = 6     'the [Yes] Button was Clicked
'Const vbNo = 7     'the [No] Button was Clicked



' C O P Y - N - P A S T E   C O M M A N D   L I N E S

'InputBox("" & _
'vbNewLine , "[VBSpavilion.vbs]")

'MsgBox "" & _
'vbNewLine , , "[VBSpavilion.vbs]"



' I N T R O D U C T I O N

'Computer Program Information
MsgBox "C O M P U T E R   P R O G R A M   I N F O R M A T I O N" & vbNewLine & vbNewLine &_
  "COMPUTER PROGRAM NAME:  [VBSpavilion.vbs]" & vbNewLine & vbNewLine & _
  "COMPUTER PROGRAM CREATOR/S:  1" & vbNewLine & _
  "Steven T. Querin" & vbNewLine & vbNewLine & _
  "COMPUTER PROGRAM CODE AUTHOR/S:  1" & vbNewLine & _
  "Steven T. Querin" & vbNewLine & vbNewLine & _
  "CREATION DATE:  31 March 2014" & vbNewLine & _
  "LAST EDITED DATE:  16 April 2014" & _
vbNewLine , , "[VBSpavilion.vbs]"

'Computer Program Start Time
dtmNumber0 = Time
dtmSeed0 = Second(dtmNumber0)
MsgBox "C O M P U T E R   P R O G R A M   S T A R T   T I M E" & vbNewLine & vbNewLine & _
  "Time = " & dtmNumber0 & vbNewLine & _
  "Hour = " & Hour(dtmNumber0) & vbNewLine & _
  "Minute = " & Minute(dtmNumber0) & vbNewLine & _
  "Second = " & Second(dtmNumber0) & vbNewLine & vbNewLine & _
  "dtmSeed0 = " & dtmSeed0 & _
  vbNewLine , , "[VBSpavilion.vbs]"

VisitorUser = HelloPlayer     'the Computer says "Hello" to the User

'Computer Program Introduction
MsgBox PlayerName & "," & vbNewLine & _
  "[VBSpavilion.vbs] is a Generic Start-Up Program created, and used by, Steven T." & vbNewLine & _
  "  Querin for Visual BASIC Script Code Writing." & _
vbNewLine , , "[VBSpavilion.vbs]"



' M A I N   P R O G R A M



' E N D   O F   P R O G R A M

VisitorUser = GoodbyePlayer     'the Computer says "Good-Bye" to the User

'Computer Program Finish Time
dtmNumber1 = Time
MsgBox "C O M P U T E R   P R O G R A M   F I N I S H   T I M E" & vbNewLine & vbnewLine & _
  "Time = " & dtmNumber1 & vbNewLine & _
  "Hour = " & Hour(dtmNumber1) & vbNewLine & _
  "Minute = " & Minute(dtmNumber1) & vbNewLine & _
  "Second = " & Second(dtmNumber1) & _
vbNewLine , , "[VBSpavilion.vbs]"

'Computer Program Duration
MsgBox "C O M P U T E R   G A M E   D U R A T I O N" & vbNewLine & vbNewLine & _
  "Finish Time = " & dtmNumber1 & vbNewLine & _
  "Start Time   = " & dtmNumber0 & _
vbNewLine , , "[VBSpavilion.vbs]"

MsgBox "END of [VBSpavilion.vbs] Program." & _
vbNewLine , , "[VBSpavilion.vbs]"



' [ V B S P A V I L I O N . V B S ]   P R O C E D U R E S

Function TimeSeeder     'creates a Seed Number using the "Time" Function
	dtmNumber = Time
	dtmSeed = Second(dtmNumber)
	dtmSeed1 = dtmSeed0 + dtmSeed
	MsgBox "T I M E   S E E D E R" & vbNewLine & _
	  "Time = " & dtmNumber & vbNewLine & _
	  "Hour = " & Hour(dtmNumber) & vbNewLine & _
	  "Minute = " & Minute(dtmNumber) & vbNewLine & _
	  "Second = " & Second(dtmNumber) & vbNewLine & vbNewLine & _
	  "dtmSeed0 = " & dtmSeed0 & vbNewLine & _
	  "dtmSeed = " & dtmSeed & vbNewLine & _
	  "dtmSeed1 = " & dtmSeed1 & _
	vbNewLine , , "[VBSpavilion.vbs]"
End Function     'TimeSeeder



Function HelloPlayer     'the Computer asks for the User's Name & Hello Greets the User
	Do	
	TryAgain = "No"
		PlayerNameInput = InputBox("?What is your name?" & _
		vbNewLine , "[VBSpavilion.vbs]")
			If PlayerNameInput = "" Then
				PlayerName = "_ "
				Hello = "Okay.  You don't want to tell me your name."     'Hello1
			ElseIf PlayernameInput = " " Then
				PlayerName = "_ "
				Hello = "That can't be your name."     'Hello2
			Else
				PlayerName = PlayerNameInput
				Hello = "Hello, " & PlayerName & ".  Pleased to meet you."     'Hello3
			End If     'PlayerNameInput
		MsgBox Hello & _
		vbNewLine , , "[VBSpavilion.vbs]"
	If TryAgain = "Yes" Then
		MsgBox "You must [ENTER] your name to continue." & _
		vbNewLine , , "[VBSpavilion.vbs]"
	End If     'TryAgain
	Loop While TryAgain = "Yes"
	MsgBox "Welcome to the [VBSpavilion.vbs] Program." & _
	vbNewLine , , "[VBSpavilion.vbs]"
End Function     'HelloPlayer



Function GoodbyePlayer     'the Computer Good-Bye Greets the User before ENDing the Program
	If PlayerNameInput = "" Then
		Goodbye = "I am glad to have met you; but, I wish I knew your name."     'Goodbye1
	ElseIf PlayerNameInput = " " Then
		Goodbye = "I am glad to have met you; but, I wish I knew your name."     'Goodbye1
	Else
		Goodbye = "Good-Bye, " & PlayerName & ".  It was pleasant to have met you."     'Goodbye2
	End If     'PlayerNameInput
	MsgBox Goodbye & vbNewLine & vbNewLine & _
	  "The Computer is now ENDing the [VBSpavilion.vbs] Program." & _
	vbNewLine , , "[VBSpavilion.vbs]"
End Function     'GoodbyePlayer



'fini
_S_I_D_E_ _N_O_T_E_
The "VISUAL GRAPHICS" Section of my Code contains MsgBox & InputBox Code Sequencing that have been REMed.

The reason is that I am having Failure Issues concerning the application of Constants for my Message Boxes & Input Boxes.

Also, the REMed MsgBox Code & InputBox Code serve to remind me of the Function Arguments/Parameters in case I want to do some fancy stuff with my Message Boxes & Input Boxes.

_F_U_N_C_T_I_O_N_S_ _ & _ _S_U_B_R_O_U_T_I_N_E_S_
I just noticed the following Error the other day; and, I have been making this Error since I started using VBS back in 2008.

My "GoodbyePlayer" Function sequence should be a Subroutine sequence.

Code:
Sub GoodbyePlayer     'the Computer Good-Bye Greets the User before ENDing the Program
	If PlayerNameInput = "" Then
		Goodbye = "I am glad to have met you; but, I wish I knew your name."     'Goodbye1
	ElseIf PlayerNameInput = " " Then
		Goodbye = "I am glad to have met you; but, I wish I knew your name."     'Goodbye1
	Else
		Goodbye = "Good-Bye, " & PlayerName & ".  It was pleasant to have met you."     'Goodbye2
	End If     'PlayerNameInput
	MsgBox Goodbye & vbNewLine & vbNewLine & _
	  "The Computer is now ENDing the [VBSpavilion.vbs] Program." & _
	vbNewLine , , "[VBSpavilion.vbs]"
End Sub     'GoodbyePlayer
This begs the question:

?Other than the Philosophical/Ideological Theory/Concept of distinguishing Functions & Subroutines from each other, what Real Difference is there between "Function...End Function" Sequences and "Sub...End Sub" Sequences?

I could probably use "Sub...End Sub" for my "HelloPlayer" Sequence. I haven't tried it yet; and, I am not planning on experimenting with that at all.

In GW-BASIC, "ONSUB...END SUB" & "GOSUB...END SUB" Sequences could be used to Generate Data and/or to Transfer Existing Data to other parts of the Code.

?Why the change in Computer Code Ideology?

It makes no sense to me.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Functions and Subroutines zaid BOOK: Beginning ASP.NET 4 : in C# and VB 3 June 2nd, 2012 02:53 PM
Creating a library of subroutines kscase Pro Visual Basic 2005 5 July 6th, 2007 02:58 PM
Javascript && keeps turnig into && ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 04:41 PM
Calling subs & Functions Zooker Beginning VB 6 4 August 20th, 2003 07:09 PM



All times are GMT -4. The time now is 02:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.