JasonEnsor
Programmer
Hi Guys,
I have been looking back on one of my projects from a few weeks ago and decided to try to update it, using the Dictionary which I was introduced to recently by StrongM. My aim is to reduce the amount of code repeated in my application.
My project consists of a userform, which holds a multipage tab. The multipage has a tab for each day of the week, on each tab a listbox has been placed. My application searches through an excel spreadsheet looking at a date column, for every date, it extracts the day value and places that on the multipage tab corresponding to the day. E.g today is Tue 29 Oct, so the data will appear on the Tuesday tab. Each listbox is named lst & Day name, so Tuesday is lstTuesday.
So my issue arises when I try to reduce the code by using a case statement for each day of the week then by calling a procedure and passing in the listbox and creating the dictionary.
My userform uses code like this
Then my PopulateDiaryList uses
I know it won't work in it's current state as I have hardcoded "Monday" in, however the whole thing dies before I get to that point. it tells me "Invalid Use of New Keyword". What am I doing wrong? as I have copied this from my other project which used the new keyword on the dictionary and that worked.
I could go back to my project being full of redundant code, but this really reduces my code down to a few pages which I would rather for maintainability purposes as it prevents having to alter vast amounts of code for each day of the week.
Any Thoughts?
Many Thanks
J.
Regards
J.
I have been looking back on one of my projects from a few weeks ago and decided to try to update it, using the Dictionary which I was introduced to recently by StrongM. My aim is to reduce the amount of code repeated in my application.
My project consists of a userform, which holds a multipage tab. The multipage has a tab for each day of the week, on each tab a listbox has been placed. My application searches through an excel spreadsheet looking at a date column, for every date, it extracts the day value and places that on the multipage tab corresponding to the day. E.g today is Tue 29 Oct, so the data will appear on the Tuesday tab. Each listbox is named lst & Day name, so Tuesday is lstTuesday.
So my issue arises when I try to reduce the code by using a case statement for each day of the week then by calling a procedure and passing in the listbox and creating the dictionary.
My userform uses code like this
Code:
Select Case (dayValue)
Case "Monday"
Call PopulateDiaryList(frmDiary.lstMonday)
Case "Tuesday"
Call PopulateDiaryList(frmDiary.lstTuesday)
etc...
Then my PopulateDiaryList uses
Code:
Sub PopulateDiaryList(lst As MSForms.ListBox)
Dim ListInformation As New Dictionary
With lst
.ColumnCount = colCount
.ColumnWidths = colWidths
.AddItem
.List(ListInformation("Monday"), 0) = currentDate ' Date
.List(ListInformation("Monday"), 1) = ModuleCode ' Module Code
.List(ListInformation("Monday"), 2) = ModuleTitle ' Module Title
.List(ListInformation("Monday"), 3) = StartTime ' Start time
.List(ListInformation("Monday"), 4) = EndTime ' End time
.List(ListInformation("Monday"), 5) = Site ' Site
.List(ListInformation("Monday"), 6) = Room ' Room
.List(ListInformation("Monday"), 7) = SupportWorker ' Support Worker
.List(ListInformation("Monday"), 8) = InterpElecNote ' Interpeter/Electronic
.List(ListInformation("Monday"), 9) = ClaimAt & vbTab & TypeOfSupport
End With
ListInformation("Monday") = ListInformation("Monday") + 1
End Sub
I know it won't work in it's current state as I have hardcoded "Monday" in, however the whole thing dies before I get to that point. it tells me "Invalid Use of New Keyword". What am I doing wrong? as I have copied this from my other project which used the new keyword on the dictionary and that worked.
I could go back to my project being full of redundant code, but this really reduces my code down to a few pages which I would rather for maintainability purposes as it prevents having to alter vast amounts of code for each day of the week.
Any Thoughts?
Many Thanks
J.
Regards
J.