Hoe maak ik invulvelden in een vbs script?

Status
Niet open voor verdere reacties.

Tijger81

Gebruiker
Lid geworden
2 jan 2010
Berichten
397
Wie kan mij helpen?
Ik heb nog nooit met vbs gewerkt, maar heb iets gevonden op internet, zie code.

Nu probeer ik een invulschermpje te maken waarop ik:
- een pad kan invullen: bijv: C:\book

Als er vervolgens op de invoerknop wordt gedrukt, gebeurt er:
- het pad (in dit geval: C:\book) wordt als text geplaatst in een bestaand txt bestand bijv: C:\test.txt.

Dit is wat ik heb gevonden, maar het is er nog lang niet:
Option Explicit

Dim Message, result
Dim Title, Text1, Text2

' Define dialog box variables.
Message = "Please enter a path"
Title = "WSH sample user input - by G. Born"
Text1 = "User input canceled"
Text2 = "You entered:" & vbCrLf

' Ready to use the InputBox function
' InputBox(prompt, title, default, xpos, ypos)
' prompt: The text shown in the dialog box
' title: The title of the dialog box
' default: Default value shown in the text box
' xpos/ypos: Upper left position of the dialog box
' If a parameter is omitted, VBScript uses a default value.

result = InputBox(Message, Title, "C:\Windows", 100, 100)

' Evaluate the user input.
If result = "" Then ' Canceled by the user
WScript.Echo Text1
Else
Plaats getypte pad (C:\book) in C:\test.txt (zoiets???)
End If

'*** End

Wie kan mij ondersteuning bieden?
 
Laatst bewerkt:
Ben al verder gekomen. Hij plaatst nu tekst in het txt bestandje. Er komt =result in te staan. Alleen niet de tekst die ingevuld wordt in het invulschermpje.

Option Explicit

Dim Message, result
Dim Title, Text1, Text2

' Define dialog box variables.
Message = "Please enter a path"
Title = "WSH sample user input - by G. Born"
Text1 = "User input canceled"
Text2 = "You entered:" & vbCrLf

' Ready to use the InputBox function
' InputBox(prompt, title, default, xpos, ypos)
' prompt: The text shown in the dialog box
' title: The title of the dialog box
' default: Default value shown in the text box
' xpos/ypos: Upper left position of the dialog box
' If a parameter is omitted, VBScript uses a default value.

result = InputBox(Message, Title, "C:\Windows", 100, 100)

' Evaluate the user input.
If result = "" Then ' Canceled by the user
WScript.Echo Text1
Else
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' The following line contains constants for the OpenTextFile
' format argument, which is not used in the code below.
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, MyFile, FileName, TextLine

Set fso = CreateObject("Scripting.FileSystemObject")

' Open the file for output.
FileName = "c:\book\test.txt"

Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)

' Write to the file.
MyFile.WriteLine "=result" (Hier zit het probleem ergens denk ik)
MyFile.Close

' Open the file for input.
Set MyFile = fso.OpenTextFile(FileName, ForReading)

' Read from the file and display the results.
Do While MyFile.AtEndOfStream <> True
TextLine = MyFile.ReadLine
Document.Write TextLine & "<br />"
Loop
MyFile.Close
End If

'*** End

Wie weet raad? Oja ik zit in de verkeerde topic, foutje
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan