Hey guys and gals.. just wondering if there was anyone out there kind enough to have a look at my dodgy coding and to help me make it easier for anyone apart from me to understand..
ill explain the purpose of the code...
this is a school project where we have been given a fictitious company to bring into the 21st century. the files that we have been given contain details on a cleaning schedule. the only hard part is coverting their time schedule into a readable format. currently they are operating on a letter system where the date of the service is given a letter.
for example:
A - Monday Week 1
X - Saturday Week 4
i have been given the task of converting the date letter into the format Date, Week, month
below is my code but it contains a lot of IF and THEN statements which kinda makes it look like a junior coded it. this will be handed in as a final assesment so any code to make it look as though i know what im doing would be helpful in getting me that higher grade :woot:
even some pieces of code will be welcomed...
hopefully someone can help me get rid of the day_code -> day_num or the Mnth_no -> Mnth_txt
thanks for your time
asimo
to get this to work all you need is a form with one button on it and name it Cmd_date. it prints the output to the form. (to be changed later)
'Code starts here
Dim day_code As String
Dim day_num As Integer
Dim week As Integer
Dim day As String
Private Sub Cmd_date_Click()
'get day code from the user
day_code = InputBox("please enter the letter code. The letter code needs to be between A and X and typed in uppercase", "enter day code", "A")
'Convert day code into a numerical value
If day_code = "A" Then day_num = 1
If day_code = "B" Then day_num = 2
If day_code = "C" Then day_num = 3
If day_code = "D" Then day_num = 4
If day_code = "E" Then day_num = 5
If day_code = "F" Then day_num = 6
If day_code = "G" Then day_num = 7
If day_code = "H" Then day_num = 8
If day_code = "I" Then day_num = 9
If day_code = "J" Then day_num = 10
If day_code = "K" Then day_num = 11
If day_code = "L" Then day_num = 12
If day_code = "M" Then day_num = 13
If day_code = "N" Then day_num = 14
If day_code = "O" Then day_num = 15
If day_code = "P" Then day_num = 16
If day_code = "Q" Then day_num = 17
If day_code = "R" Then day_num = 18
If day_code = "S" Then day_num = 19
If day_code = "T" Then day_num = 20
If day_code = "U" Then day_num = 21
If day_code = "V" Then day_num = 22
If day_code = "W" Then day_num = 23
If day_code = "X" Then day_num = 24
'get which week the day numerical value belongs to
If day_num < 6 Then week = 1
If day_num > 6 Then week = 2
If day_num > 12 Then week = 3
If day_num > 18 Then week = 4
'get the day
If week = 2 Then day_num = day_num - 6
If week = 3 Then day_num = day_num - 12
If week = 4 Then day_num = day_num - 18
If day_num = 1 Then day = "Monday"
If day_num = 2 Then day = "Tuesday"
If day_num = 3 Then day = "Wednesday"
If day_num = 4 Then day = "Thursday"
If day_num = 5 Then day = "Friday"
If day_num = 6 Then day = "Saturday"
'get the current date and convert it to the text equivalent
Question
asimo
Hey guys and gals.. just wondering if there was anyone out there kind enough to have a look at my dodgy coding and to help me make it easier for anyone apart from me to understand..
ill explain the purpose of the code...
this is a school project where we have been given a fictitious company to bring into the 21st century. the files that we have been given contain details on a cleaning schedule. the only hard part is coverting their time schedule into a readable format. currently they are operating on a letter system where the date of the service is given a letter.
for example:
A - Monday Week 1
X - Saturday Week 4
i have been given the task of converting the date letter into the format Date, Week, month
below is my code but it contains a lot of IF and THEN statements which kinda makes it look like a junior coded it. this will be handed in as a final assesment so any code to make it look as though i know what im doing would be helpful in getting me that higher grade :woot:
even some pieces of code will be welcomed...
hopefully someone can help me get rid of the day_code -> day_num or the Mnth_no -> Mnth_txt
thanks for your time
asimo
to get this to work all you need is a form with one button on it and name it Cmd_date. it prints the output to the form. (to be changed later)
'Code starts here
Dim day_code As String
Dim day_num As Integer
Dim week As Integer
Dim day As String
Private Sub Cmd_date_Click()
'get day code from the user
day_code = InputBox("please enter the letter code. The letter code needs to be between A and X and typed in uppercase", "enter day code", "A")
'Convert day code into a numerical value
If day_code = "A" Then day_num = 1
If day_code = "B" Then day_num = 2
If day_code = "C" Then day_num = 3
If day_code = "D" Then day_num = 4
If day_code = "E" Then day_num = 5
If day_code = "F" Then day_num = 6
If day_code = "G" Then day_num = 7
If day_code = "H" Then day_num = 8
If day_code = "I" Then day_num = 9
If day_code = "J" Then day_num = 10
If day_code = "K" Then day_num = 11
If day_code = "L" Then day_num = 12
If day_code = "M" Then day_num = 13
If day_code = "N" Then day_num = 14
If day_code = "O" Then day_num = 15
If day_code = "P" Then day_num = 16
If day_code = "Q" Then day_num = 17
If day_code = "R" Then day_num = 18
If day_code = "S" Then day_num = 19
If day_code = "T" Then day_num = 20
If day_code = "U" Then day_num = 21
If day_code = "V" Then day_num = 22
If day_code = "W" Then day_num = 23
If day_code = "X" Then day_num = 24
'get which week the day numerical value belongs to
If day_num < 6 Then week = 1
If day_num > 6 Then week = 2
If day_num > 12 Then week = 3
If day_num > 18 Then week = 4
'get the day
If week = 2 Then day_num = day_num - 6
If week = 3 Then day_num = day_num - 12
If week = 4 Then day_num = day_num - 18
If day_num = 1 Then day = "Monday"
If day_num = 2 Then day = "Tuesday"
If day_num = 3 Then day = "Wednesday"
If day_num = 4 Then day = "Thursday"
If day_num = 5 Then day = "Friday"
If day_num = 6 Then day = "Saturday"
'get the current date and convert it to the text equivalent
mnth_no = Month(Now)
If mnth_no = 1 Then Mnth_text = "January"
If mnth_no = 2 Then Mnth_text = "February"
If mnth_no = 3 Then Mnth_text = "March"
If mnth_no = 4 Then Mnth_text = "April"
If mnth_no = 5 Then Mnth_text = "May"
If mnth_no = 6 Then Mnth_text = "June"
If mnth_no = 7 Then Mnth_text = "July"
If mnth_no = 8 Then Mnth_text = "August"
If mnth_no = 9 Then Mnth_text = "September"
If mnth_no = 10 Then Mnth_text = "October"
If mnth_no = 11 Then Mnth_text = "November"
If mnth_no = 12 Then Mnth_text = "December"
'print the day, week and month to the form
Print day; ", Week "; week; ", "; Mnth_text
End Sub
Link to comment
Share on other sites
9 answers to this question
Recommended Posts