David has attended:
Excel VBA Advanced course
Access VBA course
Access vba code
Could someone explain howthe code below work. I can't understand various bits such as 'Open file for Binary', 'Get #1', 'Print #2' etc. Any help in deciphering this greatly appreciated
Sub output_sc4_file_east_west(mode, scenario)
'macro to read text file and create an SC4 text file
Dim FileContents As String
txt_filename = Left(CurrentDb.Name, Len(CurrentDb.Name) - 4) & "_" & scenario & ".txt"
sc4_filename = Left(CurrentDb.Name, Len(CurrentDb.Name) - 4) & "_" & scenario & "_" & mode & ".SC4"
airport = Left(CurrentProject.Name, 3)
'open txt file and read contents
Open txt_filename For Binary As #1
FileContents = Space(FileLen(txt_filename))
Get #1, , FileContents
Close #1
'remove quotation marks from txt file contents and define sc4 header info
sc4contents = Replace(FileContents, """", "")
sc4header = "ROUTEFILE," & airport & "_" & StrConv(mode, vbProperCase) & "_Routes.rta" & vbCrLf & "SPREADFILE,Departures_Spread.SPD" & vbCrLf & "PRDFILEDIRECTORY,N:\CAEP_NOx_Sample_Problem\INM_PRD_Files"
'create sc4 file
Open sc4_filename For Output As #2
Print #2, sc4header & vbCrLf & sc4contents
Close #2
'delete sc4 txt file
Kill txt_filename
End Sub
RE: access vba code
Hi David
Thanks for the question
As discused, I will investigate and get back to you within the next few days
Regards
Stephen