Solved

Creating Output Text File with Unique Name

Posted on 2002-04-05
3
140 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now