Solved

Creating Output Text File with Unique Name

Posted on 2002-04-05
3
146 Views
Last Modified: 2010-05-02
Hello,

I need very simple explanations. I am experimenting with VB and can get easily confused.

I am creating a simple app that creates a text file for me. I am trying to figure out how to get my app to create a filename via my input rather than hard coding the filename. I tried to use the following but it just prints everything between the quotes. Do you have a suggestion on how to do this? As you will see, the OPEN command is erroneous. I would like to put the value in a text box and then have that be the filename.

Private Sub Command1_Click()
    Dim IntFile As Integer
    IntFile = FreeFile
    Open "C:\Batch\Dat\(Text1.Text).DAT" For Append As #IntFile
        Print #IntFile, "ConvertType=" & CStr(Combo1.Text)
        Print #IntFile, "ConvertFrom=" & CStr(Combo2.Text)
        Print #IntFile, "ConvertTo=" & CStr(Combo3.Text)
        Print #IntFile, "FromDatabase=" & CStr(Text2.Text)
        Print #IntFile, "FromUserID=" & CStr(Text3.Text)
        Print #IntFile, "FromPassword=" & CStr(Text4.Text)
        Print #IntFile, "FromChecked=" & CStr(Text5.Text)
        Print #IntFile, "ToDatabase=" & CStr(Text6.Text)
        Print #IntFile, "SearchValue=" & CStr(Text7.Text)
        Print #IntFile, "Convert=" & CStr(Combo4.Text)
        Print #IntFile, "Start"
    Close #IntFile
End Sub

Eventually, I want to add browsing capability that will ask for the source file. The FromDatabase would be the default property for the ToDatabase and for the Text filename. For instance, if my FromDatabase filename is ABC.NSF the Output filename would be ABC.PST and the text file would be named ABC.DAT.

Thank you in advance,

John
0
Comment
Question by:jhieb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 55 total points
ID: 6921912
YOu need to remove the reference to Text1.Text from within the quotes, e.g.:

Open "C:\Batch\Dat\(Text1.Text).DAT" For Append As #IntFile

Becomes

Open "C:\Batch\Dat\" & Text1.Text & ".DAT" For Append As #IntFile
0
 
LVL 1

Author Comment

by:jhieb
ID: 6921916
I was just getting ready to add a PS. Also, if the file exists how to I tell it to overwrite it?
0
 
LVL 20

Expert Comment

by:hes
ID: 6921928
as bhess said
Open "C:\Batch\Dat\" & Text1.Text & ".DAT" For Append As #IntFile
to overrite change to
Open "C:\Batch\Dat\" & Text1.Text & ".DAT" For Output As #IntFile
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question