Vbs How to edit a text file through inputbox

Jack

I want to make a program that edits a text file every time you open it

Here is what I have:

Dim firstNameInput
Dim lastNameInput

firstNameInput = inputbox("Please enter your name")
lastNameInput = inputbox("Enter your last name")

The rest of the code has to edit 1 specific text file: C:\Users\Me\Desktop\Edit.txt then write the name and last name on a new line

If there is anyone who could help I would be great full, thanks.

Hackoo

Try something like that to append data :

Option Explicit
Const ForAppending = 8
Dim ws,fso,RootFolder,MyFile,firstNameInput,lastNameInput,fileStream
Do
    firstNameInput = inputbox("Please enter your name")
Loop Until firstNameInput <> ""

Do
    lastNameInput = inputbox("Enter your last name")
Loop Until lastNameInput <> ""

Set Ws = CreateObject("Wscript.Shell")
RootFolder = Ws.ExpandEnvironmentStrings("%USERPROFILE%\Desktop")
MyFile = RootFolder & "\Edit.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileStream = fso.OpenTextFile(MyFile,ForAppending,True)
fileStream.WriteLine String(50,"*")
fileStream.WriteLine "First name: " & firstNameInput
fileStream.WriteLine "Last name: " & lastNameInput
fileStream.Close
ws.run DblQuote(MyFile)
'*****************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************

Another version. Just give a try !

Option Explicit
Const ForAppending = 8
Dim ws,fso,RootFolder,MyFile,firstNameInput,lastNameInput,fileStream
Dim Question,Title
Title = "Put Informations in file"
Set Ws = CreateObject("Wscript.Shell")
Call MyInputBox()
Do
    Question = MsgBox("Did you want to add another data to file",VbYesNo+VbQuestion,Title)
    If Question = VbYes Then
        Call MyInputBox()
    Else
        ws.run DblQuote(MyFile)
        Wscript.Quit()
    End If
Loop Until Question = VbNo
'********************************************************************
Sub MyInputBox()
    Do
        firstNameInput = inputbox("Please enter your name")
    Loop Until firstNameInput <> ""

    Do
        lastNameInput = inputbox("Enter your last 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 "Last name: " & lastNameInput
    fileStream.WriteLine String(30,"*")
    fileStream.Close
End Sub
'********************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'********************************************************************

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to edit/save a file through Ubuntu Terminal

From Dev

Create a vbs/batch file to edit text file and create a new text file

From Dev

How to edit multiple files through "Find results" in Sublime Text

From Dev

How to edit a line of data in text file

From Dev

Vbs Make a text file with text written in it

From Dev

Vbs How to edit a text file through inputbox

From Dev

Can vbs create bat file with line from InputBox?

From Dev

Edit whitespace in text file

From Dev

How to loop through the whole text file?

From Dev

how to save a JTable to text file through JFileChooser

From Dev

How to input a text file into an exe through cmd?

From Dev

How to edit a text file in my terminal

From Dev

How to edit a text file without readling the whole file at once

From Dev

Find and Edit Text File

From Dev

How to get VBS to read from text file?

From Dev

how to search list view item through Edit text in android

From Dev

how to detect file change VBS

From Dev

how to edit a huge text file inline

From Dev

How to save xlsx file in vbs?

From Dev

Edit text in file in python

From Dev

Vbs Make a text file with text written in it

From Dev

How to edit a text file without readling the whole file at once

From Dev

How to Edit a File Text in Perl

From Dev

How to edit data in a text file using python?

From Dev

Find and Edit Text File

From Dev

Replace text in text file using VBS

From Dev

auto edit a text file

From Dev

Python - how to read through text file for keyword

From Dev

How to i open terminal through a text file