Jeg bruger kommandoen i et VB-Script program, jeg har "plukket" lidt i det, måske kan det give dig inspiration
dim printer(2), valg
on error resume next set stwofil = GetObject(, "Word.Application") if err.number > 0 then Call odoc.save (True, False) set stwofil = CreateObject ("Word.Application") end if err.clear on error goto 0
Set nyefil = stwofil.Documents.Add(her skrives stien på en word-skabelon) printer(1) = "\\W86110\HPT614Q15" printer(2) = "\\W86110\HPT614Q16"
hvis man skal definere HVILKEN printer så er det vel det der \\W86110\HPT614Q15 som bestemmer hvilken printer det er. Men det skal vel ændres alt efter hvilken printer man har?
on error resume next set stwofil = GetObject(, "Word.Application") if err.number > 0 then Call odoc.save (True, False) set stwofil = CreateObject ("Word.Application") end if err.clear on error goto 0
1. klip "programstumpen" ud 2. indsæt den i et almindeligt tekstdokument (f.eks.wordpad) 3. indsæt dine printernavne istedet for mine 4. gem den som test.vbs 5. du har nu et VBS-program, som ændrer din standard-printer at det er via en Word-kommando er ligegyldigt...med mindre du ikke har word på din pc 6. du kan så bruge dine egne programmer, standardprinteren er ændret
Jeg har afprøvet programmet på min pc, det ændrede min standardprinter !!!!
jeg har indsat det i en funktion på en hjemmeside. Det eneste der nu driller er en advarsel om at funktionen køres (activex object) og jeg har aktiveret alt i browserens indstillinger for activexes...
Jeg forsøger at benytte et andet program end word til at lave et objekt. men det lykkedes ikke rigtig. jeg har forsøgt med notepad.application og wordpad.application men lader lader ikke til at virke.
Hvis du vil lave et notepad dokument, kan du bruge efterfølgende program. Her laver du et almindeligt tekstdokument. MEN DER ER IKKE NOGEN FORM FOR FORMATTERING !!
dim fso, autECLPSObj, rp, gl Set fso = CreateObject("Scripting.FileSystemObject") Const ForReading = 1, ForWriting = 2, ForAppending = 8
'*******ny txt dokument set rp = fso.CreateTextFile("c:\rapp.txt", True)
'***************læser en gl. fil og tilføjer til slut i filen 'set gl = fso.OpenTextFile("i:\div\godkendelser\arkiv\data.txt", ForAppending)
rp.writeLine "Dette er en ny linie" rp.close
------------------------------------------ Her er en detaljeret beskrivelse:
Creating Files There are three ways to create an empty text file (sometimes referred to as a "text stream").
The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using this method in VBScript:
Dim fso, f1 Set fso = CreateObject("Scripting.FileSystemObject") Set f1 = fso.CreateTextFile("c:\testfile.txt", True) To use this method in JScript, use this code:
var fso, f1; fso = new ActiveXObject("Scripting.FileSystemObject"); f1 = fso.CreateTextFile("c:\\testfile.txt", true); The second way to create a text file is to use the OpenTextFile method of the FileSystemObject object with the ForWriting flag set. In VBScript, the code looks like this example:
Dim fso, ts Const ForWriting = 2 Set fso = CreateObject("Scripting. FileSystemObject") Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True) To create a text file using this method in JScript, use this code:
var fso, ts; var ForWriting= 2; fso = new ActiveXObject("Scripting.FileSystemObject"); ts = fso.OpenTextFile("c:\\test.txt", ForWriting, true); A third way to create a text file is to use the OpenAsTextStream method with the ForWriting flag set. For this method, use the following code in VBScript:
Dim fso, f1, ts Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateTextFile ("c:\test1.txt") Set f1 = fso.GetFile("c:\test1.txt") Set ts = f1.OpenAsTextStream(ForWriting, True) In JScript, use the code in the following example:
var fso, f1, ts; var ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject"); fso.CreateTextFile ("c:\\test1.txt"); f1 = fso.GetFile("c:\\test1.txt"); ts = f1.OpenAsTextStream(ForWriting, true); Adding Data to the File Once the text file is created, add data to the file using the following three steps:
Open the text file.
Write the data.
Close the file.
To open an existing file, use either the OpenTextFile method of the FileSystemObject object or the OpenAsTextStream method of the File object.
To write data to the open text file, use the Write, WriteLine, or WriteBlankLines methods of the TextStream object, according to the tasks outlined in the following table.
Task Method Write data to an open text file without a trailing newline character. Write Write data to an open text file with a trailing newline character. WriteLine Write one or more blank lines to an open text file. WriteBlankLines
To close an open file, use the Close method of the TextStream object.
Note The newline character contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the next line (carriage return/line feed). Be aware that the end of some strings may already have such nonprinting characters.
The following VBScript example demonstrates how to open a file, use all three write methods to add data to the file, and then close the file:
Sub CreateFile() Dim fso, tf Set fso = CreateObject("Scripting.FileSystemObject") Set tf = fso.CreateTextFile("c:\testfile.txt", True) ' Write a line with a newline character. tf.WriteLine("Testing 1, 2, 3.") ' Write three newline characters to the file. tf.WriteBlankLines(3) ' Write a line. tf.Write ("This is a test.") tf.Close End Sub This example demonstrates how to use the three methods in JScript:
function CreateFile() { var fso, tf; fso = new ActiveXObject("Scripting.FileSystemObject"); tf = fso.CreateTextFile("c:\\testfile.txt", true); // Write a line with a newline character. tf.WriteLine("Testing 1, 2, 3.") ; // Write three newline characters to the file. tf.WriteBlankLines(3) ; // Write a line. tf.Write ("This is a test."); tf.Close(); } Reading Files To read data from a text file, use the Read, ReadLine, or ReadAll method of the TextStream object. The following table describes which method to use for various tasks.
Task Method Read a specified number of characters from a file. Read Read an entire line (up to, but not including, the newline character). ReadLine Read the entire contents of a text file. ReadAll
If you use the Read or ReadLine method and want to skip to a particular portion of data, use the Skip or SkipLine method. The resulting text of the read methods is stored in a string which can be displayed in a control, parsed by string functions (such as Left, Right, and Mid), concatenated, and so forth.
The following VBScript example demonstrates how to open a file, write to it, and then read from it:
Sub ReadFiles Dim fso, f1, ts, s Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") Set f1 = fso.CreateTextFile("c:\testfile.txt", True) ' Write a line. Response.Write "Writing file <br>" f1.WriteLine "Hello World" f1.WriteBlankLines(1) f1.Close ' Read the contents of the file. Response.Write "Reading file <br>" Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading) s = ts.ReadLine Response.Write "File contents = '" & s & "'" ts.Close End Sub This code demonstrates the same in JScript:
function ReadFiles() { var fso, f1, ts, s; var ForReading = 1; fso = new ActiveXObject("Scripting.FileSystemObject"); f1 = fso.CreateTextFile("c:\\testfile.txt", true); // Write a line. Response.Write("Writing file <br>"); f1.WriteLine("Hello World"); f1.WriteBlankLines(1); f1.Close(); // Read the contents of the file. Response.Write("Reading file <br>"); ts = fso.OpenTextFile("c:\\testfile.txt", ForReading); s = ts.ReadLine(); Response.Write("File contents = '" + s + "'"); ts.Close(); }
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.