Simple File Processing Question

Dear all,
I'm saving and opening Files using FSO. When the File path is 'hard coded' thus:

Set fsoStream = fso.CreateTextFile("c:\ApplicationArchive\MyApplicationSettings.STP", True)

everything works fabulously.

However, what I want to be able to do is to get the path and filename from the user via a 'Save File As' Dialog box, and use that in the fsoStream expression to create the file.

I've tried the following but it doesn't work:

Text1.Text= "c:\ApplicationArchive\MyApplicationSettings.STP" 'captured from user via Dialog box
Dim FileString as String
FileString = Chr(34) & Text1.Text & Chr(34)
Set fsoStream = fso.CreateTextFile(FileString, True)

What am I doing wrong? How can I use the returned path and filename in a variable to create the file using FSO?

Thanks
DoctorNashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
You don't need the Quotes

Text1.Text= "c:\ApplicationArchive\MyApplicationSettings.STP" 'captured from user via Dialog box
Dim FileString as String
'Leave out the quotes
FileString = text1.text
Set fsoStream = fso.CreateTextFile(FileString, True)

What am I doing wrong? How can I use the returned path and filename in a variable to create the file using FSO?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JacamarCommented:

FileString = Chr(34) & Text1.Text & ".STP" & Chr(34)
0
vbwizardryCommented:
Here is a sample program it will give you an idea of how to do save as in you application.
You need
Form
TextBox Name=txtPath
CommandBotton Name=cmdSave
CommonDialog controll Name=dlgDialog
Include Microsoft Scripting Runtime

Option Explicit
Private Const csFilter As String = "Stp (*.stp)|*.stp"
Private oFs As FileSystemObject

Private Sub cmdSave_Click()
Const ErrorSource = "Error in Form1: Sub cmdSave_Click"
Dim oTextWriter As TextStream

    On Error GoTo cmdSave_Click_ErrHandler
    txtPath.Text = vbNullString
    dlgDialog.CancelError = True
    dlgDialog.DialogTitle = "Save As..."
    dlgDialog.Filter = csFilter
    Call dlgDialog.ShowSave
    txtPath.Text = dlgDialog.FileName
    Set oTextWriter = oFs.CreateTextFile(txtPath.Text, True)
    ' do your code here
    dlgDialog.InitDir = oFs.GetParentFolderName(txtPath.Text)

    Exit Sub
cmdSave_Click_ErrHandler:
End Sub

Private Sub Form_Load()
    dlgDialog.InitDir = App.Path
    Set oFs = New FileSystemObject
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set oFs = Nothing
End Sub
0
DoctorNashAuthor Commented:
PaulHews, Thanks for your accurate and to-the-point response. Full Marks to you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.