Solved

text file creation

Posted on 2001-06-25
6
123 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Expert Comment

by:Mikkil
Comment Utility
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
Comment Utility
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
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…

728 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

10 Experts available now in Live!

Get 1:1 Help Now