Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

text file creation

Posted on 2001-06-25
6
Medium Priority
?
130 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
[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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

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