VBS InputBox,没有文件扩展名的输出
VBS InputBox, Output without file extension
我有两个提示,请用户填写。
目标是,用户填写两个提示,输出应该是两者的组合作为文件名。
例如,用户在第一个 InputBox "Ryan" 和第二个 InputBox "Smith" 中键入。因此输出应该是一个名为 "Ryan_Smith" 的文件,但没有文件扩展名。
目前它保存在一个 "edit.txt" 输出文件中,因为我不知道如何按照我的意愿完成它。
Sub MyInputBox()
Do
firstNameInput = InputBox("First Name")
Loop Until firstNameInput <> ""
Do
lastNameInput = InputBox("Second Name")
Loop Until lastNameInput <> ""
RootFolder = Ws.ExpandEnvironmentStrings("%USERPROFILE%\Desktop")
MyFile = RootFolder & "\Edit.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileStream = fso.OpenTextFile(MyFile,ForAppending,True)
fileStream.WriteLine "First Name: " & firstNameInput
fileStream.WriteLine "Second Name: " & lastNameInput
fileStream.WriteLine String(30,"*")
fileStream.Close
End Sub
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
您可以根据自己的目的使用 CreateTextFile。
例如:
Sub MyInputBox()
dim WshShell, firstNameInput, lastNameInput, fso, fileStream, MyFile, RootFolder
set WshShell = WScript.CreateObject("WScript.Shell")
Do
firstNameInput = InputBox("First Name")
Loop Until firstNameInput <> ""
Do
lastNameInput = InputBox("Second Name")
Loop Until lastNameInput <> ""
RootFolder = WshShell.ExpandEnvironmentStrings("%USERPROFILE%\Desktop")
MyFile = RootFolder & "\" & firstNameInput & "_" & lastNameInput
' ^------------------------------------^----- Notice this filename creation
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileStream = fso.CreateTextFile(MyFile)
fileStream.Close
set WshShell = nothing
set fso = nothing
set fileStream = nothing
End Sub
call MyInputBox()
我有两个提示,请用户填写。
目标是,用户填写两个提示,输出应该是两者的组合作为文件名。
例如,用户在第一个 InputBox "Ryan" 和第二个 InputBox "Smith" 中键入。因此输出应该是一个名为 "Ryan_Smith" 的文件,但没有文件扩展名。
目前它保存在一个 "edit.txt" 输出文件中,因为我不知道如何按照我的意愿完成它。
Sub MyInputBox()
Do
firstNameInput = InputBox("First Name")
Loop Until firstNameInput <> ""
Do
lastNameInput = InputBox("Second Name")
Loop Until lastNameInput <> ""
RootFolder = Ws.ExpandEnvironmentStrings("%USERPROFILE%\Desktop")
MyFile = RootFolder & "\Edit.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileStream = fso.OpenTextFile(MyFile,ForAppending,True)
fileStream.WriteLine "First Name: " & firstNameInput
fileStream.WriteLine "Second Name: " & lastNameInput
fileStream.WriteLine String(30,"*")
fileStream.Close
End Sub
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
您可以根据自己的目的使用 CreateTextFile。
例如:
Sub MyInputBox()
dim WshShell, firstNameInput, lastNameInput, fso, fileStream, MyFile, RootFolder
set WshShell = WScript.CreateObject("WScript.Shell")
Do
firstNameInput = InputBox("First Name")
Loop Until firstNameInput <> ""
Do
lastNameInput = InputBox("Second Name")
Loop Until lastNameInput <> ""
RootFolder = WshShell.ExpandEnvironmentStrings("%USERPROFILE%\Desktop")
MyFile = RootFolder & "\" & firstNameInput & "_" & lastNameInput
' ^------------------------------------^----- Notice this filename creation
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileStream = fso.CreateTextFile(MyFile)
fileStream.Close
set WshShell = nothing
set fso = nothing
set fileStream = nothing
End Sub
call MyInputBox()