Login | |
|
 |
RE: File Creation - 12/20/2005 1:28:02 PM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
Not knowing what is in or how the SCR files are structured, I would say read up on "CreateTextFile" and then use input boxes and "writeline" to create your file. Search this board, it is an easy starter script to do. Good luck! Ask for help and we will assist. Cybex
_____________________________
Common sense is not so common.
|
|
| |
|
|
|
 |
RE: File Creation - 12/27/2005 10:31:12 AM
|
|
 |
|
| |
Navarre
Posts: 90
Score: 0
Joined: 10/19/2005
Status: offline
|
Thanks for the help, but being the giant spaz that I am, I think I put it together wrong. Here is the script that I ended up with, if I made a mistake (which I more than likely did), can you let me know where I went wrong. ' ############################################################################ ''# mcomms.vbs - commandline tool to create .SCR files ' ============================================================================ ' <your std header, copyright, comments, documentation here> ' ############################################################################ Option Explicit ''< variables must be declared before use ' ############################################################################ ''# main - back to OS with return value of selected function ' ---------------------------------------------------------------------------- ' reorder/(un)comment to select code to run (doMain will be production code; ' test functions can be removed when all is done) ' ############################################################################ WScript.Quit Function doMain00() Dim nRVal : nRVal = 1 Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" ) Dim dicMarkers : Set dicMarkers = CreateObject( "Scripting.Dictionary" ) Dim sText0 : sText0 = oFS.OpenTextFile( "comms.000" ).ReadAll() Dim sText1 : sText1 = oFS.OpenTextFile( "comms.001" ).ReadAll() Dim oRE : Set oRE = New RegExp Dim oMTS Dim oMT Dim sKey oRE.Pattern = "§\w+§" ' get (all) words between §s oRE.Global = True Set oMTS = oRE.Execute( sText0 ) For Each oMT In oMTS dicMarkers.Add oMT.Value, "" Next For Each sKey In dicMarkers.Keys WScript.Echo "dicMarkers( """ + sKey + """ ) = """"" Next dicMarkers( "§HOST§" ) = "123.123.123.123" dicMarkers( "§DomUser§" ) = "niamod/resu" dicMarkers( "§PassW§" ) = "secret" dicMarkers( "§ShopNum§" ) = "04" For Each sKey In dicMarkers.Keys sText0 = Replace( sText0, sKey, dicMarkers( sKey ) ) Next If sText0 = sText1 Then WScript.Echo "ok" Else WScript.Echo "failure" WScript.Echo sText0 End If End Function ' ============================================================================ ''= doMain01 - testing args ' ============================================================================ Function doMain01() Dim nRVal : nRVal = 1 Dim dicMarkers : Set dicMarkers = CreateObject( "Scripting.Dictionary" ) Dim nIdx Dim sKey dicMarkers.Add "§HOST§" , "" dicMarkers.Add "§DomUser§", "" dicMarkers.Add "§PassW§" , "" dicMarkers.Add "§ShopNum§", "" If 4 = WScript.Arguments.Count Then For nIdx = 0 To 3 Select Case nIdx Case 0 dicMarkers( "§HOST§" ) = WScript.Arguments( nIdx ) Case 1 dicMarkers( "§DomUser§" ) = WScript.Arguments( nIdx ) Case 2 dicMarkers( "§PassW§" ) = WScript.Arguments( nIdx ) Case 3 dicMarkers( "§ShopNum§" ) = WScript.Arguments( nIdx ) End Select Next nRVal = 1 For Each sKey In dicMarkers.Keys WScript.Echo "dicMarkers( """ + sKey + """ ) = """ + dicMarkers( sKey ) + """" Next Else WScript.Echo "Usage: mcomms.vbs <host>, <domuser>, <passw>, <shop>" End If doMain01 = nRVal End Function
|
|
| |
|
|
|
 |
RE: File Creation - 1/1/2006 6:30:39 PM
|
|
 |
|
| |
ehvbs
Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
|
Hi Navarre, in addition to the HOST item in my code you need three more items DOMUSER, PASSW, and SHOPNUM. So: (1) Take the HTML code for HOST <tr><td>Host</td><td><input id = "sleHost" type = "TEXT"></td></tr> and add <tr><td>Dom/Usr</td> <td><input id = "sleDomUsr" type = "TEXT"></td></tr> <tr><td>Password</td> <td><input id = "slePassW" type = "TEXT"></td></tr> <tr><td>Shop number</td><td><input id = "sleShopNum" type = "TEXT"></td></tr> (2) Check the .hta - does it look right? (3) Take the GetValue code for HOST If "" = Trim( sleHost.Value ) Then sleHost.Value = "123.123.123.123" and add If "" = Trim( sleDomUsr.Value ) Then sleDomUsr.Value = "niamod/resu" If "" = Trim( slePassW.Value ) Then slePassW.Value = "secret" If "" = Trim( sleShopNum.Value ) Then sleShopNum.Value = "04" (4) Check the .hta - no syntax errors? (5) Add the three new Values to the call and the definition of doTempl() doTempl( sleHost.Value ) doTempl sleHost.Value, sleDomUsr.Value, slePassW.Value, sleShopNum.Value By getting rid of the () you correct the blunder I'm really ashamed of: Parameters to Subs must not be put into (). "doTempl( sleHost.Value )" my look like a simple Sub call, but is a Sub call with the single parameter "sleHost.Value" promoted to Const: that shound be written as "doTempl (sleHost.Value)". Sub doTempl( sHost ) Sub doTempl( sHost, sDomUsr, sPassW, sShopNum ) (6) Check the .hta - no syntax errors? (7) Use the new paramters - change dicMarkers.Add "§HOST§" , sHost dicMarkers.Add "§DomUser§", "niamod/resu" ' will be replaced dicMarkers.Add "§PassW§" , "secret" ' will be replaced dicMarkers.Add "§ShopNum§", "04" ' will be replaced to dicMarkers.Add "§HOST§" , sHost dicMarkers.Add "§DomUser§", sDomUsr dicMarkers.Add "§PassW§" , sPassW dicMarkers.Add "§ShopNum§", sShopNum (6) Check the .hta - expected results in comms.scr, if you put some new values in the SingleLineEditControls?
|
|
| |
|
|
|
 |
RE: File Creation - 1/1/2006 8:06:52 PM
|
|
 |
|
| |
Navarre
Posts: 90
Score: 0
Joined: 10/19/2005
Status: offline
|
Have I put this together correctly as I keep getting object require slehost. <html> <head> <hta:application id = "mcomms" /> <title>tbox</title> <meta http-equiv = "content-script-type" content = "text/vbscript"/> <script language = "VBScript" type = "text/vbscript" > '<![CDATA[ Option Explicit ''= read/write access TEXTs, call doTempl with marker value(s) ' ============================================================================ Sub doIt() Dim sleHost : Set sleHost = document.getElementById( "sleHost.Value" ) If "" = Trim( sleHost.Value ) Then sleHost.Value = "123.123.123.123" If "" = Trim( sleDomUsr.Value ) Then sleDomUsr.Value = "niamod/resu" If "" = Trim( slePassW.Value ) Then slePassW.Value = "secret" If "" = Trim( sleShopNum.Value ) Then sleShopNum.Value = "04" doTempl sleHost.Value, sleDomUsr.Value, slePassW.Value, sleShopNum.Value End Sub ''= read Template, replace markers, write result ' ============================================================================ Sub doTempl( sHost, sDomUsr, sPassW, sShopNum ) Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" ) Dim dicMarkers : Set dicMarkers = CreateObject( "Scripting.Dictionary" ) Dim sDir : sDir = Mid( document.url, Len( "file://" ) + 1 ) sDir = oFS.GetParentFolderName( sDir ) + "\" Dim sText0 : sText0 = oFS.OpenTextFile( sDir + "comms.000" ).ReadAll() Dim oTSRes : Set oTSRes = oFS.CreateTextFile( sDir + "comms.scr" ) Dim sKey dicMarkers.Add "§HOST§" , sHost dicMarkers.Add "§DomUser§", sDomUsr dicMarkers.Add "§PassW§" , sPassW dicMarkers.Add "§ShopNum§", sShopNum For Each sKey In dicMarkers.Keys sText0 = Replace( sText0, sKey, dicMarkers( sKey ) ) Next oTSRes.Write sText0 oTSRes.Close End Sub ''= refreshes the HTA page, which includes re-running any Windows_Onload code ' ============================================================================ Sub reloadHTA() location.reload( True ) End Sub ']]> </script> </head> <body> <table border = "1"> <tr><td>Host</td><td><input id = "sleHost" type = "TEXT"></td></tr> </table> <br /> <table border = "1"> <tr><td>Domain User</td><td><input id = "sleDomUser" type = "TEXT"></td></tr> </table> <br /> <table border = "1"> <tr><td>Password</td><td><input id = "sleHost" type = "TEXT"></td></tr> </table> <br /> <table border = "1"> <tr><td>Shop Number</td><td><input id = "sleHost" type = "TEXT"></td></tr> </table> <br /> <o:p> </o:p></p> <input type = "BUTTON" value = "Do It Now" onclick = "doIt()"> <hr /> <o:p> </o:p></p> <input type = "BUTTON" value = "Reload This Thing" onclick = "reloadHTA()"> </body> </html>
|
|
| |
|
|
|
 |
RE: File Creation - 1/1/2006 9:12:50 PM
|
|
 |
|
| |
Navarre
Posts: 90
Score: 0
Joined: 10/19/2005
Status: offline
|
I must be driving you up the wall. I remodified the code as you specified and when I run the HTA comes up fine, but when I click the do it button I get an 'object required' on line 20 character 4. Again I have put the full code in to make sure that I made the correct changes. <html> <head> <hta:application id = "mcomms" /> <title>tbox</title> <meta http-equiv = "content-script-type" content = "text/vbscript"/> <script language = "VBScript" type = "text/vbscript" > '<![CDATA[ Option Explicit ''= read/write access TEXTs, call doTempl with marker value(s) ' ============================================================================ Sub doIt() Dim sleHost : Set sleHost = document.getElementById( "sleHost" ) Dim sleDomUsr : Set sleDomUsr = document.getElementById( "sleDomUsr" ) Dim slePassW : Set slePassW = document.getElementById( "slePassW" ) Dim sleShopNum : Set sleShopNum = document.getElementById( "sleShopNum" ) If "" = Trim( sleHost.Value ) Then sleHost.Value = "123.123.123.123" If "" = Trim( sleDomUsr.Value ) Then sleDomUsr.Value = "niamod/resu" If "" = Trim( slePassW.Value ) Then slePassW.Value = "secret" If "" = Trim( sleShopNum.Value ) Then sleShopNum.Value = "04" doTempl sleHost.Value, sleDomUsr.Value, slePassW.Value, sleShopNum.Value End Sub ''= read Template, replace markers, write result ' ============================================================================ Sub doTempl( sHost, sDomUsr, sPassW, sShopNum ) Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" ) Dim dicMarkers : Set dicMarkers = CreateObject( "Scripting.Dictionary" ) Dim sDir : sDir = Mid( document.url, Len( "file://" ) + 1 ) sDir = oFS.GetParentFolderName( sDir ) + "\" Dim sText0 : sText0 = oFS.OpenTextFile( sDir + "comms.000" ).ReadAll() Dim oTSRes : Set oTSRes = oFS.CreateTextFile( sDir + "comms.scr" ) Dim sKey dicMarkers.Add "§HOST§" , sHost dicMarkers.Add "§DomUser§", sDomUsr dicMarkers.Add "§PassW§" , sPassW dicMarkers.Add "§ShopNum§", sShopNum For Each sKey In dicMarkers.Keys sText0 = Replace( sText0, sKey, dicMarkers( sKey ) ) Next oTSRes.Write sText0 oTSRes.Close End Sub ''= refreshes the HTA page, which includes re-running any Windows_Onload code ' ============================================================================ Sub reloadHTA() location.reload( True ) End Sub ']]> </script> </head> <body> <table border = "1"> <tr><td>Host</td> <td><input id = "sleHost" type = "TEXT"></td></tr> <tr><td>Dom/Usr</td> <td><input id = "sleHost" type = "TEXT"></td></tr> <tr><td>Password</td> <td><input id = "sleHost" type = "TEXT"></td></tr> <tr><td>Shop number</td><td><input id = "sleHost" type = "TEXT"></td></tr> </table> <o:p> </o:p></p> <input type = "BUTTON" value = "Do It Now" onclick = "doIt()"> <hr /> <o:p> </o:p></p> <input type = "BUTTON" value = "Reload This Thing" onclick = "reloadHTA()"> </body> </html> Line 20 is the If "" = Trim( sleDomUsr.Value ) Then sleDomUsr.Value = "niamod/resu" Any ideas
|
|
| |
|
|
|
 |
RE: File Creation - 1/1/2006 10:04:07 PM
|
|
 |
|
| |
Navarre
Posts: 90
Score: 0
Joined: 10/19/2005
Status: offline
|
Thanks for that, worked like a charm. On another side issue, I was just thinking of another way of it getting the correct information. Would it be possible to have it read the information from an excel sheet and then save the comms.scr file to a subdirectory based upon the store number. I believe something like that is possible, am I right in assuming this. One other thing that I am looking at doing. I am trying to find a way to rename files that get loaded onto a server every night based upon other files that get uploaded with them. For example some of the files we get are as follows - r29-dcom.txt, arr56r29.xfr r15-dcom.txt, arr22r15.xfr Now I need to rename the r29-dcom.txt and r15-dcom.txt files to have the number that the XFR files has. So after renaming them I would end up with the following. r29-dcom56.txt, arr56r29.xfr r15-dcom22.txt, arr22r15.xfr There are quite a few files that I have to do this for on an on going basis and I need a way to speed it. The big issue is that the number in the arr56r29.xfr will increment everyday until it reaches 00 and then start again, so tomorrow would be arr57r29.xfr. The only reason I ask is that I have been looking around I have found ways of changing parts of the name, extensions, or adding dates. But not based upon other files. Again thanks for your help, you have been great help. Tim Wallace
|
|
| |
|
|
|
 |
RE: File Creation - 1/2/2006 4:34:20 AM
|
|
 |
|
| |
ehvbs
Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
|
Hi Tim, This doesn't look like the 'simple thing' you started this topic with anymore! I will try to help you, but I can't promise you that I have time to spend in the near future. Just now I'm between projects, but that can change any time. My first advice: Try to split your tasks into simple subtasks and do some experimenting guided by the VBScript Docs and sample code from this forum. You may use the stategy of putting diffent Subs of (modified) sample code in one .VBS file like I proposed in my first posting, or - if you don't like the (un)comment approach - follow the proposal of mbouchard: use suitably named stand alone .VBS files (in one directory and an editor which can display more than one file at the same time). By the way - what happens, if you start a script like this: cscript //X <script.vbs> If this doesn't start a debugger, consider getting one (for your OS) from MS and install it. EXCEL If you search this forum for "excel", "excel write", "excel ado" (with or without specifying ehvbs as author) you'll get a lot of sample code for and discussion about "getting data from excel". Try to come up with a Sub that just opens your .XLS and WScript.Echos the first table row. SAVING Change Sub doTempl( sHost, sDomUsr, sPassW, sShopNum ) Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" ) Dim dicMarkers : Set dicMarkers = CreateObject( "Scripting.Dictionary" ) Dim sDir : sDir = Mid( document.url, Len( "file://" ) + 1 ) sDir = oFS.GetParentFolderName( sDir ) + "\" Dim sText0 : sText0 = oFS.OpenTextFile( sDir + "comms.000" ).ReadAll() Dim oTSRes : Set oTSRes = oFS.CreateTextFile( sDir + "comms.scr" ) Dim sKey dicMarkers.Add "§HOST§" , sHost dicMarkers.Add "§DomUser§", sDomUsr dicMarkers.Add "§PassW§" , sPassW dicMarkers.Add "§ShopNum§", sShopNum For Each sKey In dicMarkers.Keys sText0 = Replace( sText0, sKey, dicMarkers( sKey ) ) Next oTSRes.Write sText0 oTSRes.Close End Sub To Sub doTempl( sHost, sDomUsr, sPassW, sShopNum ) Dim oFS&n | | |