Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

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
0
DoctorNash
Asked:
DoctorNash
1 Solution
 
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
 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now