Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objLogFile, not Logging Input 1

Status
Not open for further replies.

ErrorLINE1CHAR1

Programmer
Dec 3, 2010
24
US
Ok guys i have searched your forums for a while and trolled search results off of here so often that i might as well join and just ask for help..

All im trying to do is create a script that when the user clicks the button, the info from the Text field is submited to a log file. it sounds SUPER easy and everything but, this is like my 3rd redo on the script build becasue i keep finding other procedures for logging, but im most comfortable with this one now. i got it to log the now() func. but any thing else is hopeless, i.e. ive tried:

DIM etc, etc, etc
strTEXT = TESTER.VALUE
etc = etc

sub TESTER_changed()
If (TESTER.value) < "" THEN
get(strTEXT) THEN
objLogfile.writeline now()
strTEXT
objlogfile.close
End If
End sub

'**********************************************************
'* None of the above work I thought it would be able to *
'* know that if the value was greater than nothing to *
'* GET that value and Log it..? *
'* So heres my last hope, ill keep updating with what I *
'* find but im a new guy to VBScript.. *
'**********************************************************

<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Log File Testing"
SCROLL="No"
SINGLEINSTANCE="Yes"
borderstyle="Thin"
minimizebutton="No"
maximizebutton="No"/>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Log Tester of HF31SCCITMU</title>

<body>
<div>Computer Name: <input type="text" maxlength="20" size="30" name="txt_computername" readonly onfocus="txt_computername.blur()"></div>
<div>Output Log Test: <input type="text" tabindex="1" value="Test Text Here" maxlength="20" size="40" name="TESTER" onfocus="TESTER.value=''"></div>
<div><button type="submit" value="Submit" onclick="VBScript:">Submit to log</button></div>

<script language="vbscript">
SUB Window_OnLoad
SET objNetwork = CreateObject("WScript.Network")
txt_computername.Value = objNetwork.ComputerName
END SUB

Function BigTest

CONST ADS_SCOPE_SUBTREE = 2
CONST ADS_SECURE_AUTHENTICATION = 1
CONST HKEY_LOCAL_MACHINE = &H80000002
CONST ForReading = 1, ForWriting = 2, ForAppending = 8
CONST TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

DIM strAdsPath
DIM fPath

SET WshShell = WScript.CreateObject("Wscript.Shell")
SET objFSO = CreateObject("Scripting.FileSystemObject")
strLogDir = "E:\DHazeleX\tester" & ".log"
strComputer = (txt_computername.value)
strTEXT = (TESTER.value)


IF (TESTER.value) = "" THEN
MsgBox "Please enter Text"
TESTER.Focus
ELSE
ON ERROR RESUME NEXT
END IF

IF objFSO.FileExists(strLogDir) THEN

SET objFile = objFso_OpenTextFile(strLogDir,ForAppending, false)
objFile.WriteLine "Primary Log Started : " & Now()
objFile.WriteLine
strTEXT
objFile.Writeline "Primary Log Ended :" & Now()
objFile.close
ELSE
fPath = strLogDir
SET objFile = objFso.CreateTextFile (fPath,ForAppending,TRUE)
objFile.WriteLine "2ndary Log Start : " & Now()
objFile.WriteLine
strTEXT
objFile.Writeline "2ndary Log Finish :" & Now()
objFile.close
END IF

END Function
</script>


</head>
</body>
</html>


The Final Script will be in a different program this is just the easiest was of building stuff for me, gotta love HTA's, dont forget to create a log file or it wont do it, i dont know how to do that either..
 
Replace this:
objFile.WriteLine
strTEXT
with this:
objFile.WriteLine strTEXT

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I believe i have tried putting it on same line as writeline
with: & Now(), >:[ i think i just realized i what putting:

objFile.writeline "strLog" & Now()

haha that I might have been why I was getting the actual input on the log of: strLog 12-3-2010 1536.
On the other logger that i have i did the new line for logging when the function started and finished so i figured it'd be the same..i.e.:
objFile.writeline now()
Function()
objFile.writeline now()
objFile.close
I'll try it here in a few, thanks for the input PHV, (stared you)
 
Why don't you read some basic vscript tutorial _and_ html's before doing this kind of thing? There are things hopeless wrong that betray...
 
Fixed it! :) only a few small mess ups haha, should have been more obvious but oh well! anyways for anyone else that ever want to know who to write a log file for what is inputed into a text Field, here you go:

<body>

<div>Computer Name: <input type="text" maxlength="50" size="30" name="txt_computername" readonly onfocus="txt_computername.blur()"></div>
<div>Output Log Test: <input type="text" tabindex="1" value="" maxlength="20" size="40" name="TESTER" onfocus="TESTER.value=''"><b></b></div>
<div><button type="submit" value="Submit" onclick="VBScript:BigTest">Contine to Console</button></div>
<div><button type="submit" value="DUAC" onclick="VBScript:Disable UAC">OFF: UAC</button></div>
<div><button type="submit" value="EUAC" onclick="VBScript:Enable UAC">ON: UAC</button></div>

<script language="vbscript">
'*****************************************************************************
'* Onload events' including, MS SAM voice object *
'*****************************************************************************
SUB Window_OnLoad

SET objNetwork = CreateObject("WScript.Network")
txt_computername.Value = objNetwork.ComputerName
TESTER.value = objNetwork.UserDomain & "\" & objNetwork.UserName & ":"
' strTalk = "Welcome? User! H! F! S! C! C!"
' SET objVoice = CreateObject("SAPI.SpVoice")
' objVoice.Speak strTalk
END SUB
'******************************************************************************
'***************************************************************
'* Logger as you may call it.. *
'***************************************************************
FUNCTION BigTest

CONST ADS_SCOPE_SUBTREE = 2
CONST ADS_SECURE_AUTHENTICATION = 1
CONST HKEY_LOCAL_MACHINE = &H80000002
CONST ForReading = 1, ForWriting = 2, ForAppending = 8
CONST TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

DIM strAdsPath
DIM fPath
DIM WScript
DIM objNetwork

SET objNetwork = CreateObject("WScript.Network")
SET WScript = CreateObject("WScript.Shell")
SET objFSO = CreateObject("Scripting.FileSystemObject")
strLogDir = "E:\Log" & ".txt"
strComputer = (txt_computername.value)
strTEXT = (TESTER.value)
strUserN = (objNetwork.UserName)

IF (TESTER.value) = "" THEN
MsgBox "Please enter Text"
TESTER.Focus
ELSE
ON ERROR RESUME NEXT

END IF

IF objFSO.FileExists(strLogDir) THEN
SET objFile = objFso_OpenTextFile(strLogDir,8, FALSE)
objFile.WriteLine "Used at: " & Now() & " by " & strUserN & " wrote: " & strTEXT & " from " & strComputer
objFile.close
ELSE
fPath = strLogDir
SET objFile = objFSO.CreateTextFile (fPath,8,FALSE)
objFile.WriteLine "Used @ : " & Now() & " by " & strUserN & " wrote: " & strTEXT & " from " & strComputer
objFile.close
END IF

END FUNCTION
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top