Mr.Minecrafter
Mr.Minecrafter

Reputation: 11

Add value from InputBox to objFSO.OpenTextFile in VBScript

My Question

I keep getting an error here, the objective of this program is to read a file type I made (.ptaf Plain Text Archive Format) but it keeps returning this error:

Variable is undefined: "Input"

The Code

 Option Explicit

Const conForReading = 1

'Declare variables
Dim objFSO, objReadFile, contents

Problem Area

'Input
Input = InputBox("Please enter the path of the file you want to open:", _
    "Open Plain Text Archive File File")

'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile("C:\MyArchives\"& Input.Value , 1, False)

End Of Problem Area

'Read file contents
contents = objReadFile.ReadAll

'Close file
objReadFile.close

'Display results
wscript.echo contents

'Cleanup objects
Set objFSO = Nothing
Set objReadFile = Nothing

     Thanks,
     -------
         Mr.Minecrafter
         --------------

Upvotes: 1

Views: 962

Answers (2)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38745

You need to Dim the variable Input (and follow @AshReva's advice - Input is not an object).

Upvotes: 1

DevelopmentIsMyPassion
DevelopmentIsMyPassion

Reputation: 3591

Just try below

Set objReadFile = objFSO.OpenTextFile("C:\MyArchives\"& Input, 1, False)

Upvotes: 1

Related Questions