Solved

text file creation

Posted on 2001-06-25
6
124 Views
Last Modified: 2010-05-02
I need to create a text file using visual basic code under an specific path.(without using file system objects)
I also need to create a folder each time the program is used. For example the first time the application is loaded I need to create a folder with the following name
 
test1

the second time

test2

and so on

Any help is welcome.
0
Comment
Question by:PMC
6 Comments
 
LVL 20

Accepted Solution

by:
hes earned 50 total points
ID: 6224936
Try using this

NumTimes = GetSetting("Your program Name", "Startup", "Times", "0")
     
NumTimes = NumTimes + 1
SaveSetting "Your Program Name", "Startup", "Times", NumTimes

When ready to save it

MkDir "Path to where you want it\test" & Numtimes
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6224940
To make a file without fso, simply open it and close it (and print to it inbetween as needed):

Open MyFullPathAndFileName for Output as #1
Print #1, TextToPrint; ' ";" suppresses carriage return
Close #1

To make a folder:

MkDir FolderName


To update a counter for the foldername, you make want to add a registry or .ini file entry, or you could read all folder names in the desired directory, find the highest numbered one, then increment and create.

0
 
LVL 5

Expert Comment

by:jklmn
ID: 6225039
Option Explicit
'OK, every time the form is loaded, you add a text file.
'you need set myFile = "text*.txt" or similar:-)
Private Sub Form_Load()
Dim fileName As String, myPath As String, myFile As String, myFile1 As String, myFile2 As String
Dim s1 As String, n1 As Integer, n2 As Integer, maxN As Integer
myPath = "c:\test\"
myFile = "test*.txt"
n1 = InStr(myFile, "*")
myFile1 = Mid(myFile, 1, n1 - 1)
myFile2 = Mid(myFile, n1 + 1)
fileName = Dir(myPath & myFile)
Do Until fileName = ""
n2 = InStr(fileName, ".")
s1 = Mid(fileName, n1, n2 - n1)
If maxN < Val(s1) Then
maxN = Val(s1)
End If
Print s1
   fileName = Dir
Loop
Open myPath & myFile1 & CStr(maxN + 1) & myFile2 For Output As #1
Print #1, "something"
Close #1
Print myPath & myFile1 & CStr(maxN + 1) & myFile2
End Sub
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Expert Comment

by:Mikkil
ID: 6225642
PMC,

You know what you are doing, but would an extension change be a help especially if the files differ only in time of creation e.g. test.001, test.002 etc ?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139795
Hi PMC@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept hes's comment(s) as an answer.

PMC@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7178888
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

813 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

12 Experts available now in Live!

Get 1:1 Help Now