#137999 - 2005-04-14 08:05 PM
Help with code that's erroring in two diff scripts but same environment!!
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
This block of code and it's associated UDFs works great for writing the "testcomputer" entry into my "test" mysql DB:
Code:
$ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;" $objConn = DBConnOpen($ConnDSN) ? "Error @ERROR: @SERROR" sleep 2 $sql = "INSERT INTO computer(name) VALUES('testcomputer')"
DBExecuteSQL($objConn,$sql) ? "Error @ERROR: @SERROR" sleep 2
DBConnClose($objConn) ? "Error @ERROR: @SERROR" sleep 2
but when i add the EXACT same code (copy/paste) into another kix file, it gives me an undefined variable reference to $ConnDSN??? The purpose of this experiment was to try and get some of NTDOC's COMPINFO.KIX file to write some of the variables collected into a db. When that failed, I went back to my test.kix file (code above), it ran fine so I copied and pasted that exact code WITH UDFs to COMPINFO.KIX in place of the HTML generation and it gives me those undeclared variables error. Can anyone shed any light on this for me?
Edited by thepip3r (2005-04-14 08:08 PM)
|
|
Top
|
|
|
|
#138000 - 2005-04-14 08:44 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Sounds to me like you have SetOption("explicit","ON") in the script.
Quote:
SETOPTION Action SetOption can be used to configure certain options of the KiXtart script engine.
Syntax SETOPTION("option", "value")
Parameters Option Option to set. Value Value for the option. The options and possible values are described in the following table: ASCII ON, OFF Default console output is in Unicode. Setting the ASCII option to ON changes the output to ASCII, so you can output extended characters, such as line characters. CaseSensitivity ON, OFF By default, all string comparisons are case-insensitive. Setting the CaseSensitivity option to ON configures KiXtart to make string comparisons case-sensitive. DisableDebugging ON Disables debugging (effectively disables the DEBUG ON command). Note that debugging can not be re-enabled. Explicit ON, OFF When you enable the Explicit option, you must explicitly declare all variables using the Dim, Global, or ReDim statements. If you attempt to use an undeclared variable name, an error occurs. Use the Explicit option to avoid incorrectly typing the name of an existing variable.
|
|
Top
|
|
|
|
#138002 - 2005-04-14 09:18 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
It forces you to be a better programmer. With it ON any misspelled variable will caught just like the one you saw. Only explicitly declared variable are legal.
|
|
Top
|
|
|
|
#138003 - 2005-04-14 09:34 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Ok so if this is my script code:
Code:
Break On call "@ScriptDir\info.udf"
Dim $SO Global $StartTime $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $StartTime=@TICKS
Global $,$ADMIN,$ADSite,$AllDesktop,$AllStartMenu,$CPU,$CSD,$CommonAppData,$ConnDSN,$CurrentIP, $CurrentOS,$DNSHostName,$Date,$Desktop,$Dimm,$DomainMemberOf,$Favorites,$FreeSpace,$FullName, $HKCUSMWCV,$HKCUSMWNTCV,$HKLMSCCS,$HKLMSMWCV,$HKLMSMWCVAP,$HKLMSMWNTCV,$HomeDirectory,$HomeDrive, $HostComment,$HostName,$IE,$InstallDate,$Item,$LogonServer,$Patch,$BU,$MAC, $MaxPWAge,$McAfeeInfo,$Mhz,$NAVInfo,$NT2KXP,$NoNAVFound,$objConn,$OfficeApps,$OpenFile, $PWAge,$PassExpires,$ProdType,$Ram,$ST,$ScriptRunTime,$Server,$SoftWareLog,$StartMenu,$StopTime, $SystemLog,$SystemUpTime,$Time,$UserComment,$UserID,$MyVideoInfo,$MyCDInfo,$MyBIOSInfo,$sSrvc, $sTrgt,$ServiceName,$State,$StartMode,$SMSSite,$UserList,$LT,$MDAC,$NMPath,$NMApp,$VMWUser, $VMWPath,$VMWVer,$VMWToolsVer,$CVMVer,$CVMMapper,$CVMMapperVer,$ATVPN,$SMSFound,$SAPVersion, $HTMLLog,$ImageLocation,$MySoftware,$Explorer,$MyImage,$PList,$SList,$HDList,$SUList,$NetFrameVer
$ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;" $objConn = DBConnOpen($ConnDSN) ? "Error @ERROR: @SERROR" sleep 2 $sql = "INSERT INTO computer(name) VALUES('testcomputer')"
DBExecuteSQL($objConn,$sql) ? "Error @ERROR: @SERROR" sleep 2
DBConnClose($objConn) ? "Error @ERROR: @SERROR" sleep 2
can you tell me why i'm getting a duplicate definition error for $objConn? fyi, it runs fine with Explicit Off...
|
|
Top
|
|
|
|
#138004 - 2005-04-14 09:46 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
$objConn is being used as a paramater to function so it can not be declared.
Remove $objConn from your Global declares.
Code:
Break On Call @ScriptDir+'\'+'info.udf' Dim $SO Global $StartTime $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $StartTime=@TICKS Global $,$ADMIN,$ADSite,$AllDesktop,$AllStartMenu,$CPU,$CSD,$CommonAppData,$ConnDSN,$CurrentIP, $CurrentOS,$DNSHostName,$Date,$Desktop,$Dimm,$DomainMemberOf,$Favorites,$FreeSpace,$FullName, $HKCUSMWCV,$HKCUSMWNTCV,$HKLMSCCS,$HKLMSMWCV,$HKLMSMWCVAP,$HKLMSMWNTCV,$HomeDirectory,$HomeDrive, $HostComment,$HostName,$IE,$InstallDate,$Item,$LogonServer,$Patch,$BU,$MAC, $MaxPWAge,$McAfeeInfo,$Mhz,$NAVInfo,$NT2KXP,$NoNAVFound,$OfficeApps,$OpenFile, $PWAge,$PassExpires,$ProdType,$Ram,$ST,$ScriptRunTime,$Server,$SoftWareLog,$StartMenu,$StopTime, $SystemLog,$SystemUpTime,$Time,$UserComment,$UserID,$MyVideoInfo,$MyCDInfo,$MyBIOSInfo,$sSrvc, $sTrgt,$ServiceName,$State,$StartMode,$SMSSite,$UserList,$LT,$MDAC,$NMPath,$NMApp,$VMWUser, $VMWPath,$VMWVer,$VMWToolsVer,$CVMVer,$CVMMapper,$CVMMapperVer,$ATVPN,$SMSFound,$SAPVersion, $HTMLLog,$ImageLocation,$MySoftware,$Explorer,$MyImage,$PList,$SList,$HDList,$SUList,$NetFrameVer $ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;" $objConn = DBConnOpen($ConnDSN) ? "Error : " + @ERROR + " " + @SERROR Sleep 2 $sql = "INSERT INTO computer(name) VALUES('testcomputer')" DBExecuteSQL($objConn,$sql) ? "Error : " + @ERROR + " " + @SERROR Sleep 2 DBConnClose($objConn) ? "Error : " + @ERROR + " " + @SERROR Sleep 2
|
|
Top
|
|
|
|
#138006 - 2005-04-14 10:29 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If you use DIM instad of GLOBAL for $objConn does it still complain about a duplicate definition? If not, that may be a bug.
Is $objConn used any other place in your code outside of what was posted? Like in a UDF? If it is, are you using GLOBAL $objConn inside a UDF? or subscript?
|
|
Top
|
|
|
|
#138007 - 2005-04-14 10:43 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
If I do Code:
dim $objConn i get an error message saying that $objConn is a duplicate definition. and yes, $objConn is "dimmed" in some of the UDFs included:
Code:
Function DBConnOpen($objConn, optional $ConnTimeout, optional $CmdTimeout)
Dim $objConn, $adStateOpen
$dbconnopen='' $adStateOpen=1
if vartype($ConnTimeout) $ConnTimeout=val($ConnTimeout) else $ConnTimeout=15 endif
if vartype($CmdTimeout) $CmdTimeout=val($CmdTimeout) else $CmdTimeout=30 endif
$ConnDSN=trim($ConnDSN) if not $ConnDSN exit 87 endif
$objConn = CreateObject("ADODB.Connection") if @ERROR exit @ERROR endif
$objConn.ConnectionTimeout = $ConnTimeout if @ERROR exit @ERROR endif
$objConn.CommandTimeout = $CmdTimeout if @ERROR exit @ERROR endif
$objConn.Open($ConnDSN) if @ERROR exit @ERROR endif
if not $objConn.State=$adStateOpen $objConn='' $DBConnOpen='' exit @ERROR endif $DBConnOpen=$objConn exit 0
EndFunction
Function DBConnClose($objConn) Dim $adStateOpen $adStateOpen = 1 If vartype($objConn)=9 If $objConn.State = $adStateOpen $objConn.Close() if @ERROR exit @ERROR endif EndIf $objConn='' else exit 87 endif $DBConnClose=@ERROR EndFunction
function DBExecuteSQL($objConn, $sql, optional $cmdType) dim $cmdCommand, $rsRecordset dim $adCmdUnspecified, $adCmdText, $adCmdTable, $adCmdStoredProc, $adCmdUnknown, $adCmdFile, $adCmdTableDirect
$adCmdUnspecified = -1 $adCmdText = 1 $adCmdTable = 2 $adCmdStoredProc = 4 $adCmdUnknown = 8 $adCmdFile = 256 $adCmdTableDirect = 512
if vartype($cmdType) $cmdType=val($cmdType) else $cmdType=$adCmdText endif
if vartype($objConn)<>9 or $sql='' exit 87 endif
$cmdCommand = CreateObject('ADODB.Command') if @ERROR exit @ERROR endif
$cmdCommand.ActiveConnection = $objConn if @ERROR exit @ERROR endif
$cmdCommand.CommandType = $cmdType if @ERROR exit @ERROR endif
$cmdCommand.CommandText = $sql if @ERROR exit @ERROR endif
$rsRecordset=$cmdCommand.Execute() $cmdCommand='' $rsRecordset=''
if @ERROR exit @ERROR endif
$DBExecuteSQL=0 exit 0
endfunction
|
|
Top
|
|
|
|
#138008 - 2005-04-14 11:27 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
one more quick question though, SQL doesn't like backslashes "\" is there a backslash stripping function in the UDFs? If so I couldn't find one on the UDF forum.
I've tried using strip($LogonServer,'\','all') but it doesn't seem to be working cuz i'm printing the var after the strip function and it still shows the full UNC pathname...
Code:
DIM $sql,$objConn $ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;" $objConn = DBConnOpen($ConnDSN) ? "Error @ERROR: @SERROR" sleep 2 $ = Strip($LogonServer,'\','all') ? $LogonServer ;$sql = "INSERT INTO computer(name,LastLogonTime,LastLogonDate,LogonServer,Domain,CurrentIP,MACAddress,SerialNumber,OSType) VALUES('$HostName','$Time','$Date','$LogonServer','$DomainMemberOf','$CurrentIP','$MAC','','$ProdType')" $sql = "INSERT INTO computer(name,LastLogonTime,LastLogonDate,LogonServer) VALUES('$HostName','$Time','$Date','\')"
|
|
Top
|
|
|
|
#138009 - 2005-04-14 11:34 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
nm, it worked like this:
Code:
DIM $sql,$objConn,$var $ConnDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=test;PASSWORD='';OPTION=3;" $objConn = DBConnOpen($ConnDSN) ? "Error @ERROR: @SERROR" sleep 2
$LogonServer = Strip('$LogonServer','\','all') ? $LogonServer ;$sql = "INSERT INTO computer(name,LastLogonTime,LastLogonDate,LogonServer,Domain,CurrentIP,MACAddress,SerialNumber,OSType) VALUES('$HostName','$Time','$Date','$LogonServer','$DomainMemberOf','$CurrentIP','$MAC','','$ProdType')" $sql = "INSERT INTO computer(name,LastLogonTime,LastLogonDate,LogonServer) VALUES('$HostName','$Time','$Date','\')"
DBExecuteSQL($objConn,$sql) ? "Error @ERROR: @SERROR" sleep 5
DBConnClose($objConn) ? "Error @ERROR: @SERROR" sleep 5Code:
thanx for the help guys
Edited by thepip3r (2005-04-14 11:35 PM)
|
|
Top
|
|
|
|
#138010 - 2005-04-15 01:28 AM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The only thing I can think of at the moment is that you have a quoting problem that is exposing two "dim $objConn" definition to the same scope. If you have a missing or extra quote then one of the funcion keyboard may be imncluded in the string which makes KiX parser think you "Dim'ed" the variable twice.
|
|
Top
|
|
|
|
#138011 - 2005-04-15 01:35 AM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
What is "Strip"? There are several ways to parse strings and remove characters. SUBSTR, JOIN/SPLIT
|
|
Top
|
|
|
|
#138012 - 2005-04-15 04:51 PM
Re: Help with code that's erroring in two diff scripts but same environment!!
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
strip() is a UDF I found that extracts characters from a string based off of certain specified parameters. But after using it, I saw that it did just was it said it did and totally concatenated everything into one big string so I then ended up using replace() which worked exactly like I wanted it to where it replaced every backslash with any character i specified...
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 756 anonymous users online.
|
|
|