Recommended: ASP 3.0 Advanced Programming (41) 9.2.3 The use of stored procedures The use of stored procedures is an area in which Command objects are applied. Stored procedures (sometimes called storage queries) are SQL query statements that are predefined in a database. Why should stored procedures be created and used instead of directly using them in code
This is a game about word coding, written in ASP, VBScript and JavaScript.
No major problems were found under test under Win98 OEM2, PWS, and IE5.
How to use:
Method 1: For example, the directory of your 3W service is C:/Inetpub/wwwroot, create a directory below, such as wordAsb; copy the game file (wordAsb.asp) into the directory; type http:// your machine name/wordAsb/wordAsb.asp or http://127.0.0.1/wordAsb/wordAsb.asp in the address bar of IE, and press Enter to start the game.
Method 2: Copy the game file (wordAsb.asp) into a newly created directory. Right-click the directory, select properties in the menu, click the Web Sharing property page, click the Share this folder item, and click OK. Type http:// your machine name/new directory name/wordAsb.asp or http://127.0.0.1/ in the address bar of IE. Enter and start the game.
Note: Your machine OS should be NT or Win2000 Server or other OS but PWS is installed
Game method:
Click the game instructions in the game to know; if the page sometimes is blank, please press F5 to refresh it (this is also the biggest bug at present).
The code is as follows:
| The following is the quoted content: <%@ Language = VBScript%> <% Option Explicit 'Last Updated By Recon On 03/16/2001 Dim m_iPartCnt Dim m_strPrompt Dim m_astrSenPart(), m_astrFileName() Dim m_astrWords(), m_aiOpStatus() '------------------------------------------ 'Constant variable description 'm_iPartCnt: Number of vocabulary categories. Integer 'm_strPrompt: A prompt after the file operation is completed. String type 'm_astrSenPart: The name of the vocabulary classification. Character array 'm_astrFileName: Records the file names of various vocabulary files. Character array 'm_astrWords: Record all kinds of vocabulary. Two-dimensional character array 'm_aiOpStatus: Records the status after operating on each file. Integer array '------------------------------------------ 'ShowMethod m_iPartCnt = 4 m_strPrompt = ReDim m_astrSenPart(m_iPartCnt) ReDim m_astrFileName(m_iPartCnt) ReDim m_astrWords(m_iPartCnt) ReDim m_aiOpStatus(m_iPartCnt) 'Define the names of various vocabulary categories m_astrSenPart(0) = Subject m_astrSenPart(1) = Adverbial degree m_astrSenPart(2) = Adverbial place m_astrSenPart(3) = Predicate 'Define the names of various vocabulary documents m_astrFileName(0) = Who.txt m_astrFileName(1) = How.txt m_astrFileName(2) = Where.txt m_astrFileName(3) = What.txt If Request.ServerVariables(REQUEST_METHOD) = POST Then 'If the request method of the page is POST '*************************** 'Get client information '*************************** Dim m_iSenPart Dim m_strOpWay Dim m_bRptedData '------------------------------------------ 'Constant variable description 'm_iSenPart: Numbers representing vocabulary classification. Integer ' The vocabulary classification comes from the array m_astrSenPart ' Possible values are: ' 0: Subject '1: Adverbial degree '2: Adverbial place '3: Predicate 'm_strOpWay: File operation method. String type ' Possible values are: '1. SAVE: Save a certain type of vocabulary into a file ' 2. SAVEALL: Save all categories of vocabulary into a file ' 3. LOAD: Load a certain type of vocabulary from the file ' 4. LOADALL: Load all categories of vocabulary from the file 'm_bRptedData: Indicates whether the form data submitted this time is the same as the last time. Boolean type ' Possible values are: '1. False: The form data is not duplicated ' 2. True: The form data is repeated (i.e. the form is submitted repeatedly) '------------------------------------------ 'ShowForm 'How to get user requests m_strOpWay = Request.Form(txtOpWay) 'Show(m_strOpWay) 'Get words in various categories For m_iCount = 0 To (m_iPartCnt - 1) If Request.Form(txtWords & m_iCount) <> Then m_astrWords(m_iCount) = Split(Request.Form(txtWords & m_iCount), ,) End If 'Response.Write UBound(m_astrWords(m_iCount)) & <br> Next 'Detection of repeated submission of forms 'If Session(FormInf) = Request.Form Then ' 'The form is repeated submission ' m_bRptedData = True 'Else ' 'The form is non-repeated submission ' Session(FormInf) = Request.Form ' m_bRptedData = False 'End If 'Show(m_bRptedData) '*************************** 'Operate the word file '*************************** 'If m_bRptedData = False Then Dim m_iCount, m_iErrCnt Dim m_strFilePath '------------------------------------------ 'Constant variable description 'm_iCount : Counter. Integer 'm_iErrCnt: The number of times the operation failed. Integer 'm_strFilePath: record the path of various vocabulary files. String type '------------------------------------------ 'Get the path to place the vocabulary file m_strFilePath = Request.ServerVariables(PATH_TRANSLATED) m_strFilePath = Left(m_strFilePath, InStrRev(m_strFilePath, /)) 'm_strFilePath = m_strFilePath & Words/ 'Show(m_strFilePath) 'Start the file operation 'Response.Write Begin to Operate Word Files<br> Select Case m_strOpWay Case SAVE 'Save words to file m_iSenPart = CInt(Request.Form(txtSenPart)) m_aiOpStatus(m_iSenPart) = SaveFile(m_iSenPart) 'According to the operation status, get the prompt information Select Case m_aiOpStatus(m_iSenPart) Case 0 m_strPrompt = [ & m_astrSenPart(m_iSenPart) & ]Some words have been successfully saved to the file Case 1 m_strPrompt = [ & m_astrSenPart(m_iSenPart) & ]Saving some files failed End Select Case SAVEALL 'Save all categories of words into the file m_iErrCnt = 0 For m_iCount = 0 To (m_iPartCnt - 1) m_aiOpStatus(m_iCount) = SaveFile(m_iCount) If m_aiOpStatus(m_iCount) = 1 Then m_iErrCnt = m_iErrCnt 1 End If Next 'According to the operation status, get the prompt information Select Case m_iErrCnt Case 0 m_strPrompt = All categories of words have been successfully saved to the file Case m_iPartCnt m_strPrompt = word files in all categories failed to save Case Else m_strPrompt = where, For m_iCount = 0 To (m_iPartCnt - 1) If m_aiOpStatus(m_iCount) = 1 Then m_strPrompt = m_strPrompt & [ & m_astrSenPart(m_iCount) & ], End If Next m_strPrompt = Left(m_strPrompt, Len(m_strPrompt) - 1) m_strPrompt = m_strPrompt & Some files failed to save End Select Case LOAD 'Load words from file m_iSenPart = CInt(Request.Form(txtSenPart)) m_aiOpStatus(m_iSenPart) = LoadFile(m_iSenPart) 'According to the operation status, get the prompt information Select Case m_aiOpStatus(m_iSenPart) Case 0 m_strPrompt = [ & m_astrSenPart(m_iSenPart) & ]Some words have been successfully loaded Case 1 m_strPrompt = [ & m_astrSenPart(m_iSenPart) & ] Some files do not exist and loading fails End Select Case LOADALL 'Load words from each file m_iErrCnt = 0 For m_iCount = 0 To (m_iPartCnt - 1) m_aiOpStatus(m_iCount) = LoadFile(m_iCount) If m_aiOpStatus(m_iCount) = 1 Then m_iErrCnt = m_iErrCnt 1 End If Next 'According to the operation status, get the prompt information Select Case m_iErrCnt Case 0 m_strPrompt = All categories of words have been successfully loaded Case m_iPartCnt m_strPrompt = Word files in all categories do not exist, loading completely fails Case Else m_strPrompt = where, For m_iCount = 0 To (m_iPartCnt - 1) If m_aiOpStatus(m_iCount) = 1 Then m_strPrompt = m_strPrompt & [ & m_astrSenPart(m_iCount) & ], End If Next m_strPrompt = Left(m_strPrompt, Len(m_strPrompt) - 1) m_strPrompt = m_strPrompt & Some files do not exist, some loading fails End Select End Select 'End If End If 'Response.Write End to Operate Word Files<br> 'Response.Write Begin to Write Client Page<br> %> <html> <head> <title> Word matching game</title> <meta name=Generator content=EditPlus> <meta name=Author content=> <meta name=Keywords content=> <meta name=Description content=> <!--Style Table--> <style> <!-- /*English font 1*/ .fontEng1 { font-family: TIMES NEW ROMAN; font-style: ; } /*English font 2*/ .fontEng2 { font-family: TIMES NEW ROMAN; font-style: ITALIC; } /*Adhere to font*/ .fontEmp { color: RED; } /*Link*/ .link { font-family: TIMES NEW ROMAN; font-style: ITALIC; text-decoration: NONE; } /* List of displayed words*/ .listShown { position: ABSOLUTE; width: 140px; height: 200px; display: INLINE; border: LIGHTCORAL 1px SOLID; background-color: GAINSBORO; } /*Hidden word list*/ .listHidden { position: ABSOLUTE; width: 140px; height: 200px; display: NONE; border: LIGHTCORAL 1px SOLID; background-color: GAINSBORO; } /*Fixed word list*/ .listFixed { position: ABSOLUTE; width: 140px; height: 200px; display: INLINE; border: RED 1px SOLID; background-color: GAINSBORO; } /*Showed Help List*/ .helpShown { position: ABSOLUTE; width: ; height: ; display: block; border: LIGHTCORAL 1px SOLID; background-color: GAINSBORO; } /*Hidden Help List*/ .helpHidden { position: ABSOLUTE; width: ; height: ; display: NONE; border: LIGHTCORAL 1px SOLID; background-color: GAINSBORO; } /*Pinned Help List*/ .helpFixed { position: ABSOLUTE; width: ; height: ; display: block; border: RED 1px SOLID; background-color: GAINSBORO; } /*Tags highlighted*/ .lblMOver { text-decoration: NONE; color: LIGHTCORAL; background-color: ; } /*Normal display tag*/ .lblMOut { text-decoration: NONE; color: ; background-color: ; } /*Clicked tag*/ .lblClicked { text-decoration: UNDERLINE; color: RED; background-color: ; } /* Highlighted button*/ .btnLighted { width: 105px; color: BLUE; background-color: ; } /*Ordinary display button*/ .btnDelighted { width: 105px; color: ; background-color: ; } /* Highlighted word list item*/ .optLighted { text-decoration: UNDERLINE; color: BLUE; background-color: ; cursor: HAND; } /*Normal displayed word list item*/ .optDelighted { text-decoration: NONE; color: ; background-color: ; cursor: ; } --> </style> <!--Client script--> <script language=JavaScript> <!-- //Client public and test functions //*************************************** //Function name: lTrim //Function: Remove the space on the left side of the string //Input: 1. strTemp: The string to be regular. String type //Output: regular string. String type //*************************************** function lTrim(strTemp) { var iCount, iLength; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iLength: The length of the string. Integer //------------------------------------------ iLength = strTemp.length; for (iCount = 0; iCount < iLength; iCount ) if (strTemp.charAt(iCount) != ) return strTemp.substring(iCount, iLength); return ; } //*************************************** //Function name: rTrim //Function: Remove the space on the right side of the string //Input: 1. strTemp: The string to be regular. String type //Output: regular string. String type //*************************************** function rTrim(strTemp) { var iCount, iLength; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iLength: The length of the string. Integer //------------------------------------------ iLength = strTemp.length; for(iCount = iLength - 1; iCount >= 0; iCount --) if (strTemp.charAt(iCount) != ) return strTemp.substring(0, iCount 1); return ; } //*************************************** //Function name: trim //Function: Remove the spaces on both sides of the string //Input: 1. strTemp: The string to be regular. String type //Output: regular string. String type //*************************************** function trim(strTemp) { return rTrim(lTrim(strTemp)); } //Convert 2-digit numbers into 2-digit string //*************************************** //Function name: get2bNumStr //Function: Convert 2-bit numbers into 2-bit numbers string //Input: 1. iNumber: the number to be converted. Integer //Output: The converted numeric string. Integer //*************************************** function get2bNumStr(iNumber) { var str2bNum; //------------------------------------------ //Constant variable description //str2bNum: numeric string. String type //------------------------------------------ if (parseInt(iNumber) < 10) str2bNum = 0 iNumber; else str2bNum = iNumber; return str2bNum; } //*************************************** //Func function name: assignFunc //Function: Specify the element's event handling function //Input: 1. ele: The element of the event handling function to be specified. Object type // 2. func: event handling function. Functional // 3. event: event type. String type //Output: None //*************************************** function assignFunc(ele, func, event) { var iCount, iEleCount; var strEvent; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iEleCount: The number of elements in the collection of elements with the same name. Integer //strEvent: Event type. String type //------------------------------------------ if (event == null) strEvent = onclick; else strEvent = event; iEleCount = ele.length; if (iEleCount == undefined) eval(ele. strEvent = func); else for (iCount = 0; iCount < iEleCount; iCount ) eval(ele[iCount]. strEvent = func); } //*************************************** //Function name: getEleIndex //Function: Get the index of the element where the event occurred in the collection of the same name //Input: 1. eleSrc: The element where the event occurred. Object type //Output: Index of the element where the event occurred in the collection of the same name //*************************************** function getEleIndex(eleSrc) { var colSrc; var iCount, iEleCount; //------------------------------------------ //Constant variable description //colSrc: Collection of elements of the same name. Object-type array //iCount: Counter. Integer //iEleCount: The number of elements in the collection of elements with the same name. Integer //------------------------------------------ colSrc = eval(eleSrc.id); iEleCount = colSrc.length; for (iCount = 0; iCount < iEleCount; iCount ) { if (colSrc[iCount] == eleSrc) return iCount; } return -1; } //Show the value of the constant variable (for debugging) //!Prepare to delete function show(strDef1, strDef2, strDef3, strDef4) { var iCount, iDefCnt; var strShow, strTemp; iDefCnt = 4; strShow = [constant variable value]; for (iCount = 1; iCount <= iDefCnt; iCount ) { strTemp = eval(strDef iCount); if (strTemp != undefined && strTemp != null) strShow = /n strTemp : eval(strTemp); } alert(strShow); } //*************************************** //Function name: showArray //Function: Display elements of one-dimensional array (for debugging) //Input: 1. array: the one-dimensional array to be displayed. Array //Output: None //*************************************** function showArray(array) { var iCount, iEleCount; var strShow; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iEleCount: The number of array elements. Integer //strShow: A string composed of array element values. String type //------------------------------------------ iEleCount = array.length; strShow = Array Length: iEleCount; strShow = /n-----------------------------------/n; for (iCount = 0; iCount < iEleCount; iCount ) { if (typeof(array[iCount]) == object) strShow = array[iCount].id; else strShow = array[iCount] ; } alert(strShow); } //*************************************** //Function name: show2DArray //Function: Display elements of a two-dimensional array (for debugging) //Input: 1. array: the two-dimensional array to be displayed. Array //Output: None //*************************************** function show2DArray(array) { var iX, iY, iLen1, iLen2; var strShow; //------------------------------------------ //Constant variable description //iX: Counter. Integer //iY: Counter. Integer //iLen1: The number of one-dimensional array. Integer //iLen2: The number of two-dimensional arrays. Integer //strShow: A string composed of array element values. String type //------------------------------------------ iLen1 = array.length; strShow = Array 1D Length: iLen1; strShow = /n---------------------------------; for (iX = 0; iX < iLen1; iX ) { strShow = /n; iLen2 = array[iX].length; for (iY = 0; iY < iLen2; iY ) strShow = array[iX][iY]; } alert(strShow); } //--> </script> <script language=JavaScript> <!-- //----------------------------------------------------------------------------------------------------------------------------- //window_onload // //getWord //reset //save //load // //showList //hideList //fixList //valueList // //showHelp //hideHelp //fixHelp // //resetAll //saveAll //loadAll //assemble // //lightBtn //delightBtn //lightOpt //delightOpt // //makeOpt //removeOpt //----------------------------------------------------------- var m_iPartCnt; var m_astrSenPart, m_astrWords; var m_strPrompt; var m_iListFixed, m_iHelpFixed; //------------------------------------------ //Constant variable description //m_iPartCnt: Number of vocabulary categories. Integer //m_astrSenPart: The name of the vocabulary classification. Character array //m_astrWords: record various vocabulary. Two-dimensional character array //m_strPrompt: Prompt message after file operation is completed. String type //m_iListFixed: The number representing the fixed word list. Integer // -1 means no word list is fixed //m_iHelpFixed: The number that represents the fixed state of the help list. Integer // -1 means that the help list is not fixed //------------------------------------------ window.onload = window_onload; //----------------------------------------------------------- //Initialize the page function window_onload() { var iCount, iEleCnt; var colButton; var strHelp; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iEleCnt: The number of elements in the collection. Integer //colButton: Collection of BUTTON elements. Object-type array //strHelp: Help file content. String type //------------------------------------------ m_iPartCnt = <%= m_iPartCnt%>; m_strPrompt = <%= m_strPrompt%>; m_iListFixed = -1; m_iHelpFixed = -1; m_astrSenPart = new Array(); m_astrWords = new Array(); //alert(m_iPartCnt: m_iPartCnt /nm_strPrompt: m_strPrompt); //Get the name of the vocabulary classification and the various vocabulary that have been loaded <%For m_iCount = 0 To (m_iPartCnt - 1)%> //Get all kinds of vocabulary loaded <%If IsEmpty(m_astrWords(m_iCount)) = True Then%> m_astrWords[<%= m_iCount%>] = new Array(); <%Else%> m_astrWords[<%= m_iCount%>] = <%= Join(m_astrWords(m_iCount), ,)%>.split(,); <%End If%> //Get the name of the vocabulary classification m_astrSenPart[<%= m_iCount%>] = <%= m_astrSenPart(m_iCount)%>; <%Next%> //show2DArray(m_astrWords); //showArray(m_astrSenPart); //Write all kinds of loaded vocabulary to the page for (iCount = 0; iCount < m_iPartCnt; iCount ) valueList(m_astrWords[iCount], iCount); //Load the help file //strHelp = tblHelp.outerHTML; //strHelp = divHelp1.innerHTML; //tblHelp.outerHTML = ; //divHelp.innerHTML = strHelp; //tblHelp.style.display = ; //divHelp.style.display = NONE; //divHelp.style.left = divHelp1.style.left; //alert(left: divHelp.style.left /nleft: divHelp1.style.left); //alert(pixelleft: divHelp.style.pixelLeft /npixelleft: divHelp1.style.pixelLeft); //alert(posLeft: divHelp.style.posLeft /nposLeft: divHelp1.style.posLeft); //alert(offsetLeft : divHelp.offsetLeft /noffsetLeft : divHelp1.offsetLeft ); //alert(clientLeft: divHelp.clientLeft /nclientLeft: divHelp1.clientLeft); //Specify the event handling function of the page element assignFunc(txtWord, getWord, onkeypress); assignFunc(btnGetWord, getWord); assignFunc(btnReset, reset); assignFunc(btnSave, save); assignFunc(btnLoad, load); assignFunc(lblWordList, showList, onmouseover); assignFunc(lblWordList, hideList, onmouseout); assignFunc(lblWordList, fixList); assignFunc(lblHelp, showHelp, onmouseover); assignFunc(lblHelp, hideHelp, onmouseout); assignFunc(lblHelp, fixHelp); assignFunc(btnResetAll, resetAll); assignFunc(btnSaveAll, saveAll); assignFunc(btnLoadAll, loadAll); assignFunc(btnAsb, assemble); colButton = document.all.tags(BUTTON); iEleCnt = colButton.length; //showArray(colButton); //alert(iEleCnt: iEleCnt); for (iCount = 0; iCount < iEleCnt; iCount ) { assignFunc(colButton[iCount], lightBtn, onmouseover); assignFunc(colButton[iCount], delightBtn, onmouseout); } //Set the initial status of the page if (m_strPrompt != ) alert(m_strPrompt); txtWord[0].focus(); } //----------------------------------------------------------- //Get the word entered by the user function getWord() { //Only when press Enter or in the word input box //Continue to do it when pressing the save button if (window.event.type != keypress && window.event.type != click) return; else if (window.event.type == keypress && window.event.keyCode != 13) return; var eleSrc; var iIndex, iNxtWrdIdx; var strWord; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //iNxtWrdIdx: The index of new words in word array. Integer //strWord: The word entered by the user. String type //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); //Get index strWord = trim(txtWord[iIndex].value); //Get the word entered by the user //Detect whether the entered word is legal // If it is an illegal word, exit if (strWord == ) { //If the entered word is empty or space string alert(words cannot be empty or space string); txtWord[iIndex].select(); return; } if (strWord.indexOf(,) != -1 || strWord.indexOf( ) != -1) { //If the entered word contains commas or spaces alert(words cannot contain commas or spaces); txtWord[iIndex].select(); return; } //Save words into vocabulary array iNxtWrdIdx = m_astrWords[iIndex].length; m_astrWords[iIndex][iNxtWrdIdx] = strWord; //showArray(m_astrWords[iIndex]); //Write words to the page valueList(m_astrWords[iIndex], iIndex); txtWord[iIndex].value = ; txtWord[iIndex].focus(); } //----------------------------------------------------------- //Delete all words in the current category from memory function reset() { var eleSrc; var iIndex, iCount; var strPrompt; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //iCount: Counter. Integer //strPrompt: Operation prompt. String type //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); strPrompt = Are you sure you want to clear all words in the [m_astrSenPart[iIndex]] part from memory? ; if (window.confirm(strPrompt) == false) return; m_astrWords[iIndex] = new Array(); valueList(m_astrWords[iIndex], iIndex); //showArray(m_astrWords[iIndex]); strPrompt = word cleared; alert(strPrompt); txtWord[iIndex].select(); } //----------------------------------------------------------- //Save the current vocabulary of the selected category into the file function save() { var eleSrc; var iIndex, iCount; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //iCount: Counter. Integer //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); if (m_astrWords[iIndex].length == 0) { //If the current number of words in the selected category is zero var strPrompt; strPrompt = [ m_astrSenPart[iIndex] ] section now has no optional word, are you sure you want to save it? ; strPrompt = /n (this will generate an empty new file); if (window.confirm(strPrompt) == false) return; } //Save all words in the current memory for (iCount = 0; iCount < m_iPartCnt; iCount ) eval(frmWords.txtWords iCount).value = m_astrWords[iCount].join(,); frmWords.txtSenPart.value = iIndex; frmWords.txtOpWay.value = SAVE; frmWords.submit(); } //----------------------------------------------------------- //Read word records of selected category from the file function load() { var eleSrc; var iIndex, iCount; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //iCount: Counter. Integer //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); //Save all words in the current memory for (iCount = 0; iCount < m_iPartCnt; iCount ) eval(frmWords.txtWords iCount).value = m_astrWords[iCount].join(,) frmWords.txtSenPart.value = iIndex; frmWords.txtOpWay.value = LOAD; frmWords.submit(); } //----------------------------------------------------------- //Show vocabulary list function showList(iIndex) { //If the parameter iIndex is not given //Get iIndex if (iIndex == undefined) { //If the word list is already fixed, exit the function if (m_iListFixed != -1) return; var eleSrc; var iIndex; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); } //alert(iIndex: iIndex); //Show vocabulary list //lblWordList[iIndex].innerText = [lblWordList[iIndex].innerText ]; //lblWordList[iIndex].innerText = lblWordList[iIndex].innerText >; lblWordList[iIndex].className = lblMOver; divWordList[iIndex].className= listShown; } //----------------------------------------------------------- //Hide vocabulary list function hideList(iIndex) { //If the parameter iIndex is not given //Get iIndex if (iIndex == undefined) { //If the word list is already fixed, exit the function if (m_iListFixed != -1) return; var eleSrc; var iIndex; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); } //alert(iIndex: iIndex); //Hide vocabulary list //lblWordList[iIndex].innerText = lblWordList[iIndex].innerText.slice(0, -1); lblWordList[iIndex].className = lblMOut; divWordList[iIndex].className= listHidden; } //----------------------------------------------------------- //Fixed vocabulary list function fixList() { var eleSrc; var iIndex; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //iIndex: Number representing vocabulary classification. Integer //------------------------------------------ eleSrc = window.event.srcElement; iIndex = getEleIndex(eleSrc); switch (m_iListFixed) { case -1: //If there is no word list yet //Fix the current list m_iListFixed = iIndex; lblWordList[iIndex].className = lblClicked; divWordList[iIndex].className= listFixed; break; case iIndex: //If the fixed word list is the current list //Resolve the current list m_iListFixed = -1; lblWordList[iIndex].className = lblMOver; divWordList[iIndex].className= listShown; break; default: //If the fixed word list is not the current list //The list of fixed fixes hideList(m_iListFixed); m_iListFixed = -1; lblWordList[iIndex].className = lblMOver; showList(iIndex); break; } //alert(m_iListFixed: m_iListFixed /niIndex: iIndex); } //----------------------------------------------------------- //Write words loaded in a certain type of vocabulary function valueList(aWords, iSenPart) { var iCount, iWrdCnt; var strListPpt; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iWrdCnt: The number of words of a certain type of vocabulary. Integer //strListPpt: Prompt in word list. String type //------------------------------------------ //Data preparation iWrdCnt = aWords.length; lblWordCount[iSenPart].innerText = iWrdCnt; strListPpt = <div><span style='color: RED; font-style: Italic; font-size: 10.5pt;'>; strListPpt = Double-click the word to delete it </span> </div>; //Write words to list if (iWrdCnt != 0) { divWordList[iSenPart].innerHTML = strListPpt; for (iCount = 0; iCount < iWrdCnt; iCount ) divWordList[iSenPart].innerHTML = makeOpt(aWords[iCount], iCount); } else divWordList[iSenPart].innerHTML = strListPpt; } //----------------------------------------------------------- //Show the help list function showHelp() { //If the help list has been fixed, exit the function if (m_iHelpFixed == 0) return; //Show help lblHelp.className = lblMOver; divHelp.className = helpShown; } //----------------------------------------------------------- //Hide Help List function hideHelp() { //If the help list has been fixed, exit the function if (m_iHelpFixed == 0) return; //Hide help lblHelp.className = lblMOut; divHelp.className = helpHidden; } //----------------------------------------------------------- //Fixed Help List function fixHelp() { if (m_iHelpFixed == -1) { //If the help list has not been fixed //Fix it m_iHelpFixed = 0; lblHelp.className = lblClicked; divHelp.className = helpFixed; } else { //If the help list has been fixed //Resolve it m_iHelpFixed = -1; lblHelp.className = lblMOver; divHelp.className = helpShown; } } //----------------------------------------------------------- //Reset the page to the initial state function resetAll() { var iCount; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //------------------------------------------ for (iCount = 0; iCount < m_iPartCnt; iCount ) { txtWord[iCount].value= ; m_astrWords[iCount] = new Array(); //Empty the word array valueList(m_astrWords[iCount], iCount); } txtSentence.value = ; txtWord[0].focus(); } //----------------------------------------------------------- //Save all categories of words into file function saveAll() { var iCount, iEmptyCnt; var strPrompt; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iEmptyCnt: The number of categories with 0 words. Integer //strPrompt: Operation prompt. String type //------------------------------------------ iEmptyCnt = 0; for (iCount = 0; iCount < m_iPartCnt; iCount ) { //Save all words in the current memory eval(frmWords.txtWords iCount).value = m_astrWords[iCount].join(,); if (m_astrWords[iCount].length == 0) iEmptyCnt ; } //alert(iEmptyCnt: iEmptyCnt); if (iEmptyCnt > 0) { switch (iEmptyCnt) { case m_iPartCnt: strPrompt = The number of vocabulary words in all categories is 0, and the operation will produce m_iPartCnt empty files; strPrompt = /n Are you sure you want to do this? ; break; default: strPrompt = where,; for (iCount = 0; iCount < m_iPartCnt; iCount ) if (m_astrWords[iCount].length == 0) strPrompt = [ m_astrSenPart[iCount] ],; strPrompt = strPrompt.slice(0, -1); strPrompt = The number of some words is 0; strPrompt = /n operation will generate iEmptyCnt empty files; strPrompt = , are you sure you want to do this? ; } if (window.confirm(strPrompt) == false) return; } frmWords.txtOpWay.value = SAVEALL; frmWords.submit(); } //----------------------------------------------------------- //Load all categories of words from the file function loadAll() { var iCount; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //------------------------------------------ //Save all words in the current memory for (iCount = 0; iCount < m_iPartCnt; iCount ) eval(frmWords.txtWords iCount).value = m_astrWords[iCount].join(,) frmWords.txtOpWay.value = LOADALL; frmWords.submit(); } //----------------------------------------------------------- //Please vocabulary match and get a sentence function assemble() { var iCount, iWrdCnt, iRndIndex; var strSentence; //------------------------------------------ //Constant variable description //iCount: Counter. Integer //iWrdCnt: The number of words of a certain type of vocabulary. Integer //iRndIndex: Randomly generated word index. Integer //strSentence: A sentence composed of random words in each category of vocabulary. String type //------------------------------------------ strSentence = ; for (iCount = 0; iCount < m_iPartCnt; iCount ) { //If the current number of vocabulary in category is 0 //Give a prompt and abort the collocation iWrdCnt = m_astrWords[iCount].length; if (iWrdCnt == 0) { var strPrompt; //------------------------------------------ //Constant variable description //strPrompt: Operation prompt. String type //------------------------------------------ strPrompt = [ m_astrSenPart[iCount] ] part has no optional word; strPrompt = /nPlease enter at least one word; alert(strPrompt); txtWord[iCount].select(); return; } // Randomly select a word from the current category vocabulary //Add to the sentence iRndIndex = Math.floor(Math.random()*iWrdCnt); strSentence = m_astrWords[iCount][iRndIndex]; //alert(iWrdCnt: iWrdCnt /niRndIndex: iRndIndex); } strSentence = . ; txtSentence.value = strSentence; } //Button where the mouse moves //Produce a light-up effect function lightBtn() { var eleSrc; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //------------------------------------------ eleSrc = window.event.srcElement; while (eleSrc.tagName.toUpperCase() != BUTTON) eleSrc = eleSrc.parentElement; eleSrc.className = btnLighted; } //Button that takes the mouse away //Restore to initial state function delightBtn() { var eleSrc; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //------------------------------------------ eleSrc = window.event.srcElement; while (eleSrc.tagName.toUpperCase() != BUTTON) eleSrc = eleSrc.parentElement; eleSrc.className = btnDelighted; } //In the list, the word where the mouse is moved //Produce a light-up effect function lightOpt(ele) { var eleSrc; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //------------------------------------------ eleSrc = ele; eleSrc.className = optLighted; } //In the list, the word that makes the mouse leave //Restore to initial state function delightOpt(ele) { var eleSrc; //------------------------------------------ //Constant variable description //eleSrc: The element where the event occurred //------------------------------------------ eleSrc = ele; eleSrc.className = optDelighted; } //Get defined words to be added to the list function makeOpt(strWord, iWrdIdx) { var strOptHead, strOptFoot; var strOptWord; //------------------------------------------ //常变量说明 //strOptHead :重定义单词头。字符串型 //strOptFoot :重定义单词尾。字符串型 //strOptWord :重定义单词。字符串型 //------------------------------------------ strOptHead = <div class='optDelighted' onmouseover='lightOpt(this);' onmouseout='delightOpt(this);' ondblclick='removeOpt(this);' wrdIdx=' iWrdIdx '>; strOptFoot = </div>; strOptWord = strOptHead strWord strOptFoot; //alert(strOptWord); return strOptWord; } //删除列表中的单词 function removeOpt(ele) { var eleSrc; var iIndex, iWrdIdx; var astrWords, astrHead, astrFoot; //------------------------------------------ //常变量说明 //eleSrc :发生事件的元素 //iIndex :表示词汇分类的数字。整型 //iWrdIdx :单词在单词数组中的索引。整型 //astrWords :某类词汇单词数组。字符串型数组 //astrHead :某类词汇单词数组头部分。字符串型数组 //astrFoot :某类词汇单词数组尾部分。字符串型数组 //------------------------------------------ eleSrc = ele; iIndex = getEleIndex(eleSrc.parentElement); iWrdIdx = parseInt(eleSrc.wrdIdx); //将单词从词汇数组中删去 //showArray(m_astrWords[iIndex]); astrWords = m_astrWords[iIndex].concat(); astrHead = astrWords.slice(0, iWrdIdx); astrFoot = astrWords.slice(iWrdIdx 1); m_astrWords[iIndex] = astrHead.concat(astrFoot); //showArray(astrHead); //showArray(astrFoot); //showArray(m_astrWords[iIndex]); //将剩余的单词重新写入到页面中 valueList(m_astrWords[iIndex], iIndex); txtWord[iIndex].select(); } //--> </script> </head> <body> <!--标题--> <div align=CENTER> <span style=font-size: 20pt; font-weight: BOLD>词语搭配游戏</span> <span class=fontEng2>v1.0</span> </div> <hr style=visibility: HIDDEN> <!--主表格1--> <table border=0 align=CENTER width=80%> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup align=CENTER></colgroup> <colgroup></colgroup> <%For m_iCount = 0 To (m_iPartCnt - 1)%> <tr> <td><%= m_astrSenPart(m_iCount)%></td> <td width=20%><input type=text id=txtWord style=width: 100%></td> <td><button id=btnGetWord style=width: 75px title=将单词保存到内存中>保存</button></td> <td><button id=btnReset style=width: 75px title=从内存中删去当前类别所有的单词>重置</button></td> <td><button id=btnSave style=width: 75px title=将单词保存到文件中>存入</button></td> <td><button id=btnLoad style=width: 75px title=从文件中载入单词>载入</button></td> <td width=15%><label id=lblWordList title=单击固定我>单词列表</label></td> <td> <div id=divWordList class=listHidden></div> 个数:<label id=lblWordCount class=fontEng1><%= 0%></label> </td> </tr> <%Next%> </table> <hr style=visibility: HIDDEN> <hr style=color: BLUE> <!--主表格2--> <table border=0 align=CENTER width=80%> <colgroup width=16%></colgroup> <colgroup width=16%></colgroup> <colgroup width=16%></colgroup> <colgroup></colgroup> <tr> <td><button id=btnResetAll accesskey=r title=从内存中删去所有类别的单词class=btnDelighted>全部重置<u>R</u></button></td> <td><button id=btnSaveAll accesskey=s title=将所有类别的单词保存到文件中class=btnDelighted>全部存入<u>S</u></button></td> <td><button id=btnLoadAll accesskey=l title=从文件中载入所有类别的单词class=btnDelighted>全部载入<u>L</u></button></td> <td> <span style=font-size: 9pt; color: RED;>请单击</span> <label id=lblHelp title=单击固定我>游戏说明</label> <!--帮助说明表格--> <div id=divHelp class=helpHidden> <table id=tblHelp border=0 align=CENTER width=300px style=font-size: 9pt;> <colgroup width=75px></colgroup> <colgroup></colgroup> <tr><td colspan=2> <a href=#1 style=color: BLUE;>游戏步骤</a> <a href=#2 style=color: BLUE;>操作说明</a> <a href=#3 style=color: BLUE;>游戏起源</a> <a href=#4 style=color: BLUE;>制作原因</a> <a href=#5 style=color: BLUE;>游戏功效</a> <a name=0 style=display: NONE;>TOP</a> </td></tr> <!--游戏步骤--> <tr><td colspan=2></td></tr> <tr><td colspan=2> [<a name=1 style=color: BLUE;>游戏步骤</a>] <a href=#0 class=link>TOP</a> </td></tr> <tr><td colspan=2> <span class=fontEng1><1></span>在每个部分的<span class=fontEmp>输入框</span>中输入单词, 按<span class=fontEmp>回车</span>或<span class=fontEmp>保存</span>按钮存入内存中; 或按<span class=fontEmp>载入</span>按钮调出以前保存的某类别单词纪录; 或按<span class=fontEmp>全部载入</span>按钮调出以前保存的所有类别单词纪录<br> <span class=fontEng1><2></span>按<span class=fontEmp>开始搭配</span>按钮,系统将从各类单词中随机抽取一个,组成一个句子 </td></tr> <!--操作说明--> <tr><td colspan=2></td></tr> <tr><td colspan=2> [<a name=2 style=color: BLUE;>操作说明</a>] <a href=#0 class=link>TOP</a> </td></tr> <tr> <td>保存</td> <td>得到用户输入的单词</td> </tr> <tr> <td>重置</td> <td>将当前类别所有的单词从内存中删去</td> </tr> <tr> <td>存入</td> <td>将所选类别的当前词汇保存进文件中</td> </tr> <tr> <td>载入</td> <td>从文件中读取所选类别的单词纪录</td> </tr> <tr> <td>全部重置</td> <td>重置页面至初始状态</td> </tr> <tr> <td>全部保存</td> <td>把所有类别的单词都存入文件</td> </tr> <tr> <td>全部载入</td> <td>从文件中载入所有类别的单词</td> </tr> <tr> <td>开始搭配</td> <td>进行词汇搭配,得到一个句子</td> </tr> <tr><td></td></tr> <tr><td colspan=2> <span class=fontEng1><1></span> <span class=fontEmp>将鼠标移至单词列表处</span>,会弹出该类词汇的单词列表; <span class=fontEmp>将鼠标移开</span>,列表会自动隐藏; <span class=fontEmp>点击单词列表</span>,会固定单词列表; <span class=fontEmp>再次点击</span>,会取消固定<br> <span class=fontEng1><2></span> 在<span class=fontEmp>固定住一个单词列表</span>后, <span class=fontEmp>双击</span>该列表中的某个单词,可以将该单词从内存中删去<br> <span class=fontEng1><3></span> 输完一个单词后,<span class=fontEmp>直接按回车</span>就可以保存了,这样比按保存保存单词更方便 </td></tr> <!--游戏起源--> <tr><td colspan=2></td></tr> <tr><td colspan=2> [<a name=3 style=color: BLUE;>游戏起源</a>] <a href=#0 class=link>TOP</a> </td></tr> <tr><td colspan=2> 这个游戏想法来自于小时候玩的纸团游戏。那时和姐姐在家里闲得无聊,就玩这个,哈哈。 玩法很简单,做一些纸片,分成四堆,分别写上<span class=fontEmp>亲朋好友的名字</span>、<span class=fontEmp>形容程度的词语</span>、<span class=fontEmp>关于地点的词语</span>和<span class=fontEmp>所做的事情</span>。 然后,将纸片捏成纸团,<span class=fontEng1>OK, Let's Start!</span> 现在从每堆中抽出一个纸团,就有四个词语,将它们组成一句话,因为是随便抽的,有时能组成很搞笑的句子。 如:陈楠兴奋地在大街上跳夏威夷草裙舞;万民悠闲地在公园里洗澡。^_ </td></tr> <!--制作原因--> <tr><td colspan=2></td></tr> <tr><td colspan=2> [<a name=4 style=color: BLUE;>制作原因</a>] <a href=#0 class=link>TOP</a> </td></tr> <tr><td colspan=2> 主要是无聊,想做个游戏娱乐一下自己,当然也希望大家能从中得到笑声。 其次也想锻炼一下自己的技术,以前用<span class=fontEng1>VB</span>做过一个,不是很好,这次用的是<span class=fontEng1>ASP</span>,不知有没有进步,呵呵 这个版本我大概地测试了一下,没发现大的<span class=fontEng1>bug</span>。如果您在游戏中发现了问题或有什么建议,请一定告诉我,在此先谢谢了! 我的信箱是<a href=mailto: [email protected] class=link>[email protected]</a>。不好你就说吗!不可能你说好我又说不好,你不说好我又说好的,^_ </td></tr> <!--游戏功效--> <tr><td colspan=2></td></tr> <tr><td colspan=2> [<a name=5 style=color: BLUE;>游戏功效</a>] <a href=#0 class=link>TOP</a> </td></tr> <tr><td colspan=2> 因为是搞笑游戏,所以能使你心情愉快、青春焕发,间接增加找对象的成功率; 因为不用做纸团了,减少了浪费和污染,从而美化了世界环境; 相信还有很多功效,请大家帮我找。 Ha ha. </td></tr> </table> </div> </td> </tr> <tr> <td><button id=btnAsb accesskey=a title=从每个类别词汇中随机抽取一个单词,组成一个句子class=btnDelighted>开始搭配<u>A</u></button></td> <td colspan=3><input type=text id=txtSentence style=width: 100%></td> </tr> </table> <hr style=color: BLUE> <!--提交表单--> <form id=frmWords method=POST action= style=display: NONE;> <%For m_iCount = 0 To (m_iPartCnt - 1)%> <input type=text name=txtWords<%= m_iCount%>> <%Next%> <input type=text name=txtSenPart> <input type=text name=txtOpWay> </form> <!--版权--> <div align=CENTER> <div> © <span class=fontEng2>2001 China Sentin Sci. & Tech. Co., Ltd.</span> <span class=fontEng2>All Rights Reserved.</span> </div> <div> <span class=fontEng2>Authored by</span> <a href=mailto: [email protected] class=link>Recon</a></span> <a href=http://recon.top263.net/ class=link>http://recon.top263.net/</a> </div> </div> </body> </html> <% '以下是服务器端脚本 '用到的函数和过程 '************************ '函数名:SaveFile '功能:将某类词汇保存到文件中 '输入:1、iSenPart :表示词汇分类的数字。整型 ' 可能的值有: ' 0:主语 ' 1:程度状语 ' 2:地点状语 ' 3:谓语 '输出:对文件操作后的状态值。整型 ' 可能的值有: ' 0:操作成功 ' 1:操作失败 '************************ Function SaveFile(iSenPart) Dim fsoMain, tsfWords Dim iCount, iWrdCnt Dim iOpStatus '------------------------------------------ '常变量说明 'fsoMain :FSO对象 'tsfWords :TEXTSTREAM对象 'iCount :计数器。整型 'iWrdCnt :某类词汇单词的数目。整型 'iOpStatus :文件操作完毕后的状态。整型 '------------------------------------------ Set fsoMain = Server.CreateObject(SCRIPTING.FILESYSTEMOBJECT) Set tsfWords= fsoMain.CreateTextFile(m_strFilePath & m_astrFileName(iSenPart), True) tsfWords.WriteLine([ & m_astrSenPart(iSenPart) & 部分]) '如果该类别至少有一个单词 If IsEmpty(m_astrWords(iSenPart)) = False Then iWrdCnt = UBound(m_astrWords(iSenPart)) 1 For iCount = 0 To (iWrdCnt - 1) tsfWords.WriteLine(m_astrWords(iSenPart)(iCount)) Next End If tsfWords.Close iOpStatus = 0 SaveFile = iOpStatus End Function '************************ '函数名:LoadFile '功能:从文件中载入某类词汇 '输入:1、iSenPart :表示词汇分类的数字。整型 ' 可能的值有: ' 0:主语 ' 1:程度状语 ' 2:地点状语 ' 3:谓语 '输出:对文件操作后的状态值。整型 ' 可能的值有: ' 0:操作成功 ' 1:操作失败 '************************ Function LoadFile(iSenPart) Dim fsoMain, tsfWords Dim strLoaded Dim iOpStatus '------------------------------------------ '常变量说明 'fsoMain :FSO对象 'tsfWords :TEXTSTREAM对象 'strLoaded :某类词汇所有单词构成的字符串。字符串型 'iOpStatus :文件操作完毕后的状态。整型 '------------------------------------------ Set fsoMain = Server.CreateObject(SCRIPTING.FILESYSTEMOBJECT) If fsoMain.FileExists(m_strFilePath & m_astrFileName(iSenPart)) = True Then '如果存在纪录文件 strLoaded = Set tsfWords= fsoMain.OpenTextFile(m_strFilePath & m_astrFileName(iSenPart), 1) tsfWords.SkipLine Do While tsfWords.AtEndOfStream = False strLoaded = strLoaded & tsfWords.ReadLine & , Loop If strLoaded <> Then strLoaded = Left(strLoaded, Len(strLoaded) - 1) m_astrWords(iSenPart) = Split(strLoaded, ,) Else m_astrWords(iSenPart) = Empty End If tsfWords.Close iOpStatus = 0 Else '如果不存在纪录文件 iOpStatus = 1 End If LoadFile = iOpStatus End Function %> <% '以下是服务器端脚本 '用于测试的函数和过程 Sub Show(strDef) Response.Write strDef & : & Eval(strDef) & <br> End Sub Sub ShowMethod() Response.Write Request Method: & Request.ServerVariables(REQUEST_METHOD) & <br> End Sub Sub ShowForm() Dim iCount Dim strProp iCount = 0 Response.Write *********Form Information******<br> For Each strProp In Request.Form iCount = iCount 1 Response.Write iCount & . & strProp & : & Request.Form(strProp) & <br> Next Response.Write *********Form End**************<br> End Sub %> |
分享:ASP 3.0高级编程(十二) 4.2.3 服务器端包含指令的例子本节提供了一些示例页面,可以用来对各种服务器端包含语句进行实验。打开示例网页的子目录Chapter04,显示SSI Directives and the ASP Server Object&rdqu