Variable scope problem

Results 1 to 2 of 2

Thread: Variable scope problem

  1. #1
    Bas de Gier Guest

    Default Variable scope problem

    Hi there,<BR>I&#039ve got an ASP-page in which I read out a posted form (method = post). I put all filled in data of the form into variables using something like:<BR>dim varname<BR>varname = Request.Form("textField1")<BR><BR>In the same script I put an event handler procedure (sub) of a button:<BR>Sub BtnOK_onclick<BR>...<BR>end sub<BR><BR>In this sub I want to use the variable "varname" (to write the content to a database) but somehow the scope of that variabele is of someway that causes the fact that I can&#039t reach it in de subroutine.<BR>I&#039m pretty inexperienced in ASP but I can&#039t imagine this is impossible.<BR>Any help would be very welcome,<BR>Thanx,<BR>Bas<BR><BR><BR><BR>Full script:<BR>&#060;SCRIPT LANGUAGE=vbscript RUNAT=Server&#062;<BR>&#039Fill variables<BR>dim browser<BR>browser = Request.Form("textBrowser")<BR>dim platform<BR>platform = Request.Form("textPlatform")<BR>dim titel<BR>titel = Request.Form("textTitel")<BR>dim voornaam<BR>voornaam = Request.Form("textVoornaam")<BR>dim tussenvoegsel<BR>tussenvoegsel = Request.Form("textTussenvoegsel")<BR>dim achternaam<BR>achternaam = Request.Form("textAchternaam")<BR>dim initialen<BR>initialen = Request.Form("textInitialen")<BR>dim geslacht<BR>geslacht = Request.Form("textGeslacht")<BR>dim straatnaam<BR>straatnaam = Request.Form("textStraatnaam")<BR>dim huisnummer<BR>huisnummer = Request.Form("textHuisnummer")<BR>dim postcode<BR>postcode = Request.Form("textPostcode")<BR>dim plaatsnaam<BR>plaatsnaam = Request.Form("textPlaatsnaam")<BR>dim land<BR>land = Request.Form("textLand")<BR>dim telefoon1<BR>telefoon1 = Request.Form("textTelefoon1")<BR>dim telefoon2<BR>telefoon2 = Request.Form("textTelefoon2")<BR>dim fax<BR>fax = Request.Form("textFax")<BR>dim email<BR>email = Request.Form("textEmail")<BR>dim taal<BR>taal = Request.Form("selectTaal")<BR>dim paswoord<BR>paswoord = Request.Form("textpaswoord")<BR><BR>Sub BtnOK_onclick<BR>Response.Write "&#060;TITLE&#062;Achternaam: " & achternaam & "&#060;/TITLE&#062;"<BR>&#039Open database connection of WebVisitor<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>Set objCmd = Server.CreateObject("ADODB.Command")<BR>strConnect Webvisitor = Application("cnWebvisitor_ConnectionString")<BR>ob jConn.ConnectionString = strConnectWebvisitor<BR>objConn.CursorLocation = adUseClient<BR>objConn.Open<BR>&#039Make command object for stored procedure<BR>objCmd.ActiveConnection = objConn<BR>objCmd.CommandType = adCmdStoredProc<BR>objCmd.CommandText = "spAddUser"<BR><BR>&#039Set all parameters of stored procedure<BR>set parCustLastName = objCmd.CreateParameter ("@CustLastName", adVarChar, adParamInput, 50, achternaam)<BR>set parPrefix = objCmd.CreateParameter ("@Prefix", adVarChar, adParamInput, 50, tussenvoegsel)<BR>set parInitials = objCmd.CreateParameter ("@Initials", adVarChar, adParamInput, 50, initialen)<BR>set parTitle = objCmd.CreateParameter ("@Title", adVarChar, adParamInput, 50, titel)<BR>set parGender = objCmd.CreateParameter ("@Gender", adVarChar, adParamInput, 50, geslacht)<BR>set parCustFirstName = objCmd.CreateParameter ("@CustFirstName", adVarChar, adParamInput, 50, voornaam)<BR>set parStreet = objCmd.CreateParameter ("@Street", adVarChar, adParamInput, 50, straatnaam)<BR>set parSNumber = objCmd.CreateParameter ("@SNumber", adVarChar, adParamInput, 50, huisnummer)<BR>set parPCode = objCmd.CreateParameter ("@PCode", adVarChar, adParamInput, 50, postcode)<BR>set parCity = objCmd.CreateParameter ("@City", adVarChar, adParamInput, 50, plaatsnaam)<BR>set parCountry = objCmd.CreateParameter ("@Country", adVarChar, adParamInput, 50, land)<BR>set parLanguage = objCmd.CreateParameter ("@Language", adVarChar, adParamInput, 50, taal)<BR>set parUsername = objCmd.CreateParameter ("@Username", adVarChar, adParamInput, 50, gebruikersnaam)<BR>set parPassword = objCmd.CreateParameter ("@Password", adVarChar, adParamInput, 50, paswoord)<BR>set parPhone1 = objCmd.CreateParameter ("@Phone1", adVarChar, adParamInput, 50, telefoon1)<BR>set parPhone2 = objCmd.CreateParameter ("@Phone2", adVarChar, adParamInput, 50, telefoon2)<BR>set parFax = objCmd.CreateParameter ("@Fax", adVarChar, adParamInput, 50, fax)<BR>set parEmail = objCmd.CreateParameter ("@Email", adVarChar, adParamInput, 50, email)<BR>set parBrowser = objCmd.CreateParameter ("@Browser", adVarChar, adParamInput, 50, browser)<BR>set parPlatform = objCmd.CreateParameter ("@Platform", adVarChar, adParamInput, 50, platform)<BR>&#039These fields are not yet in use and therefore set to null <BR>set parCompanyID = objCmd.CreateParameter ("@CompanyID", adVarChar, adParamInput, 50, null)<BR>set parComment = objCmd.CreateParameter ("@Comment", adVarChar, adParamInput, 50, null) <BR>&#039Append all parameters <BR>objCmd.Parameters.Append parCustLastName<BR>objCmd.Parameters.Append parPrefix<BR>objCmd.Parameters.Append parInitials<BR>objCmd.Parameters.Append parTitle<BR>objCmd.Parameters.Append parGender<BR>objCmd.Parameters.Append parCustFirstName<BR>objCmd.Parameters.Append parStreet<BR>objCmd.Parameters.Append parSNumber<BR>objCmd.Parameters.Append parPCode<BR>objCmd.Parameters.Append parCity<BR>objCmd.Parameters.Append parCountry<BR>objCmd.Parameters.Append parLanguage<BR>objCmd.Parameters.Append parUsername<BR>objCmd.Parameters.Append parPassword<BR>objCmd.Parameters.Append parPhone1<BR>objCmd.Parameters.Append parPhone2<BR>objCmd.Parameters.Append parFax<BR>objCmd.Parameters.Append parEmail<BR>objCmd.Parameters.Append parBrowser<BR>objCmd.Parameters.Append parPlatform<BR>objCmd.Parameters.Append parCompanyID<BR>objCmd.Parameters.Append parComment<BR>&#039Execute stored procedure<BR>objCmd.Execute<BR>&#039Close Command & Connection<BR>objCmd.Close <BR>objConn.Close<BR>&#039Clear memory<BR>objCmd = Nothing<BR>objConn = Nothing <BR>End Sub<BR>&#060;/SCRIPT&#062;

  2. #2
    Join Date
    Dec 1969
    Posts
    572

    Default RE: Variable scope problem

    If your varname is being set correctly, I don&#039t see why it shouldn&#039t be available inside of any sub or function within the same page. Try changing &#039dim varname&#039 to &#039private varname&#039, but I don&#039t think it matters.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •