Hi Everyone,
A transient, virtual hobo, with only enough skill to be highly dangerous. You all know the type, as evidenced here:
The code I'm attaching, far below, does not work (shocker). It attempts to dynamically assign values to the properties? of my variable (of type ProjectRegions) via a loop that feeds it the property name and the property value. Thus,
1. Is it possible to accomplish this dynamically, kind of like 'variable variables' in PHP?
2. I am currently using a Select Case, but it consumes hundreds of lines. Should I stick with that?
#1 would be funner and shorter. Thanks for any assistance.
A transient, virtual hobo, with only enough skill to be highly dangerous. You all know the type, as evidenced here:
The code I'm attaching, far below, does not work (shocker). It attempts to dynamically assign values to the properties? of my variable (of type ProjectRegions) via a loop that feeds it the property name and the property value. Thus,
- 1st time through:
projectRegion.projectName = "Dismantle hampster wheel that is my job". - 2nd time through:
projectRegion.projectNumber = "42". - 3rd time through:
projectRegion.projectDescription = "A futile endeavor". - nth time through:
projectRegion.[regionName] = regionValue
1. Is it possible to accomplish this dynamically, kind of like 'variable variables' in PHP?
2. I am currently using a Select Case, but it consumes hundreds of lines. Should I stick with that?
#1 would be funner and shorter. Thanks for any assistance.
Code:
Public Type ProjectRegions
projectName As Integer
projectNumber As String
projectDescription As String
End Type
Dim projectRegion As ProjectRegions
Sub getProjects()
'Assume currentExcelRegion and currentExcelRegionValue change each time through the loop
For count = 1 To 1000
projectRegion = saveProjectRegions(currentExcelRegion, currentExcelRegionValue)
Next
MsgBox "My project number is: " & projectRegion.projectNumber
MsgBox "My project description is: " & projectRegion.projectDescription
End Sub
Public Function saveProjectRegions(regionName, regionValue) As ProjectRegions
projectRegion.[regionName] = regionValue 'This doesn't work, not that I expected it to
saveProjectRegions = projectRegion
End Function
Last edited: