Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

text file creation

Posted on 2001-06-25
6
Medium Priority
?
131 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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Independent Software Vendors: 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

877 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