Solved

Variable File Names

Posted on 2000-03-31
4
130 Views
Last Modified: 2010-05-02
We are trying to use VB to develop a small program to populate a series of small data files used by another legacy application.  Does anyone know how to create the data file (file name) to include the date?  For example, a file name for a file created on 3/31 would be AAA0331.txt; a file created on 4/1 would be AAA0401.txt etc.
0
Comment
Question by:Winchesters
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2673011
You can use the Format function:
sFile = "AAA" & format(date,"mmdd") & ".txt"
0
 
LVL 4

Expert Comment

by:gcs001
ID: 2673026
Or this way:
Dim fn As String

fn = "AAA" & Format(Month(Now), "00") & Format(Day(Now), "00") & ".txt"
Open fn For Output As #1 '
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2673305
I like to add the Last digit of the year in my file names.. ie. Format = AAAymmdd

<----- Code Begin ----->

Dim dteWork As Date
dteWork = #12/31/1998#

Dim intYear As Integer
intYear = Year(dteWork)
intYear = intYear - ((intYear \ 10) * 10)

Dim strFileName as String
strFileName = "AAA" _
   & Format(intYear, "0") _
   & Format(Month(dteWork), "00") _
   & Format(Day(dteWork), "00") _
   & ".txt"

Dim intFileNumber
intFileNumber = Freefile
Open strFileName For Write as intFileNumber

<----- Code End ----->
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 2673381
You could also use:

strFileName = "AAA" _
   & Right(Year(dteWork), 1) _
   & Format(Month(dteWork), "00") _
   & Format(Day(dteWork), "00") _
   & ".txt"
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…

803 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