Link to home
Start Free TrialLog in
Avatar of Winchesters
Winchesters

asked on

Variable File Names

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.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

You can use the Format function:
sFile = "AAA" & format(date,"mmdd") & ".txt"
Or this way:
Dim fn As String

fn = "AAA" & Format(Month(Now), "00") & Format(Day(Now), "00") & ".txt"
Open fn For Output As #1 '
Avatar of wsh2
wsh2

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 ----->
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial