Can anyone tell me why a programmer would put this code in?

DK8

Registered User.
Local time
Today, 15:30
Joined
Apr 19, 2007
Messages
72
The programmer before me apparently put in some code, didn't document it and I have no idea why. The specific part I don't understand is why someone would hard code a date in for 2006? How would someone suggest changing from hard coded to system date or something like that? Thanks!

\Code snippet:

intLen = Len(Dir$("T:\" & strPathPrefix & "\2006\" & Format(DATE, "MMDD") & "\" & "PAYMENTS\" & varFileName & " "))

/code
 
They either believed that other dates wouldn't be required, they were lazy, or they expected to go back and change it again when the year changed.

I've seen all of those before.
 
any suggestions?

Thank for the quick response, any suggestions on how you would go about replacing the year 2006?
 
Well, you could have a form to select the date, call an input box for them to input it, or store the current allowed date in its own table and use a DLookup to assign it at run time.
 
looks like they were planning on using local dlookup, but

I found this code after your last post:

\code snippet

varFileName = LocalDLookup("FileName", "BLANK FILE PROCESSING", "[ClientNumber]= " & .Fields("EMPLOYER NUMBER").Value & " ")

/code

But how can I tell what table she was planning to store the allowed date in?

Can anyone answer this?
 
BLANK FILE PROCESSING is the table in the DLookup.
 
thanks again

I am new to VBA and am so thankful you guys are so knowledgeable.
 
Can someone please review my code change

I have removed the hardcoding for the year 2006 and replaced it with \YYYY\ because this is the folder for the current year which the file will be found in.

New code:

intLen = Len(Dir$("T:\" & strPathPrefix & Format(DATE, "\YYYY\" & "\MMDD\") & "\" & "CDLS\" & varFileName & " "))

Old code:

intLen = Len(Dir$("T:\" & strPathPrefix & "\2006\" & "\MMDD\") & "\" & "CDLS\" & varFileName & " "))

Thanks in advance to anyone who may be able to tell me if the format change I made is correct.
 
Paste this in a module and run it... it will show you what you have. Then you can adjust it until you get what you desire.

Public Function test()

Dim strtest As String
Dim strPathPrefix As String
Dim varFileName As Variant

strPathPrefix = "temp"
varFileName = "testfilename.txt"

strtest = "T:\" & strPathPrefix & "\2006\" & Format(Date, "MMDD") & "\" & "PAYMENTS\" & varFileName & " "
MsgBox strtest


strtest = ("T:\" & strPathPrefix & Format(Date, "\YYYY\" & "\MMDD\") & "\" & "CDLS\" & varFileName & " ")
MsgBox strtest

End Function
 
thanks much

I'm working on tweaking it now, thank you!
 
DK,
As a tip... the use of quotes (") opens a section of text and the ampersand (&) adds a variable that has been declared elsewhere. The difference is when the quotes are used in a function like in the case of Format, which is the function used to format a date... the quotes here are used to specify how you want to show the date. You could look at format in the help menu for more detail.

So you probably want something like this...

strtest = ("T:\" & strPathPrefix & "\" & Format(Date, "YYYY") & "\" & Format(Date, "MMDD") & "\" & "CDLS\" & varFileName & " ")
MsgBox strtest
 
... because I know that someone will correct me... you would actually simplify
the end from

& "\" & "CDLS\"

to

& "\CDLS\"
 
thanks again

I am grateful for your help once again. If anyone else has suggestions, please let me know.
 
intLen = Len(Dir$("T:\" & strPathPrefix & "\" & Format(Date, "YYYY") & "\" & Format(Date, "MMDD") & "\CDLS\" & varFileName))

This should be exactly what you are after.
As Bob suggests you shouldn't hardcode the value - the previous guy was probably being lazy.
I am presuming that there is a line that then says intLen > 0 ... which would tell you if the file exists and is greater than zero bytes.
What more do you want?
By the way... if you just ask for answers you will never learn!!
 
There isn't code yet to test if the file exists and it's file length, thanks for mentioning such. There is only code to test for zero length files. By the way, isn't asking questions the best way to learn, especially if you're new to programming, like I am? Take care,
 
Sorry DK.. .you are right... you should ask questions. I guess I was responding like that because I figured I had already given you enough info to go on... "If anyone else has suggestions, please let me know"

All I meant to say was that if you Only ask questions you won't learn... you need to ask questions and then experiment yourself in order to understand the answers.

My understanding of your code is that it checks the directory to see if the file exists, and the len function checks the number of bytes. So the following line will just assign the intLen with the number of bytes for the file. Hence the reason that I figured that your code would then check that it was greater than zero bytes in order to load or manipulate the file in some way.

intLen = Len(Dir$("T:\" & strPathPrefix & "\" & Format(Date, "YYYY") & "\" & Format(Date, "MMDD") & "\CDLS\" & varFileName))

On it's own I can't see what other value this line of code would have?!
 
The code is testing files to see if they are either payment files or change files and then putting them in the appropriate folders. Then our process takes over to process the files. From that point it's adding a record to email to a client and to inform then that a payment file or change file is attached to the email. If that makes any sense to you, I don't know, maybe only if you work here. Thanks for your time.
 

Users who are viewing this thread

Back
Top Bottom