Solved

text file creation

Posted on 2001-06-25
6
128 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 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
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!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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