DataBlake
Well-known Member
- Joined
- Jan 26, 2015
- Messages
- 781
- Office Version
- 2016
- Platform
- Windows
Hey all.
So i have this really REALLY messy title generator that 1st takes out unnecessary information from data that will later be used in titles. Generally speaking this is aimed at specific products that are known to be lengthy in characters.
so is there a way to simplify this code to maybe look through a collection or dictionary of words and remove those from the string located in the array?
so say for instance ary2(i, 2) = "PA SERIES BY KMC WHEELS" instead of having all of these replace functions i could have one loop through a dictionary of key phrases to remove from the string, which the only part im caught up on is the actual removing the dictionary value from the string.
and then the second part which comes in later which is actually generating a title that is less than or equal to 80 characters.
how this works is i take the data and form a title from it. So i start with a string with the maximum amount of info i can include.
If that maximum amount of info is over 80 characters then i start whittling it down,
There has to be a better method though? open to suggestions
the dats is as follows: quantity - size - brand - style - "ET" - number - finish - pattern 1 - pattern 2 - "wheel rim"
sometimes pattern 2 is blank ""
example: One (1) 20x10 Contra 101C ET 20 Gloss Black 5x100 5X1.1 Wheel Rim
So i have this really REALLY messy title generator that 1st takes out unnecessary information from data that will later be used in titles. Generally speaking this is aimed at specific products that are known to be lengthy in characters.
VBA Code:
ary2(i, 2) = Replace(ary(i, x), " BY KMC WHEELS", "")
ary2(i, 2) = Replace(ary2(i, 2), " TL SERIES", "")
ary2(i, 2) = Replace(ary2(i, 2), " DA Series", "")
ary2(i, 2) = Replace(ary2(i, 2), " XC Series", "")
ary2(i, 2) = Replace(ary2(i, 2), " 1PC", "")
ary2(i, 2) = Replace(ary2(i, 2), " 2PC", "")
so is there a way to simplify this code to maybe look through a collection or dictionary of words and remove those from the string located in the array?
so say for instance ary2(i, 2) = "PA SERIES BY KMC WHEELS" instead of having all of these replace functions i could have one loop through a dictionary of key phrases to remove from the string, which the only part im caught up on is the actual removing the dictionary value from the string.
and then the second part which comes in later which is actually generating a title that is less than or equal to 80 characters.
how this works is i take the data and form a title from it. So i start with a string with the maximum amount of info i can include.
If that maximum amount of info is over 80 characters then i start whittling it down,
There has to be a better method though? open to suggestions
the dats is as follows: quantity - size - brand - style - "ET" - number - finish - pattern 1 - pattern 2 - "wheel rim"
sometimes pattern 2 is blank ""
example: One (1) 20x10 Contra 101C ET 20 Gloss Black 5x100 5X1.1 Wheel Rim
VBA Code:
'determine title length
ary2(i, 16) = "One (1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicFINISH.Item(ary2(i, 4)) & " " & ary2(i, 10) & " " & ary2(i, 11) & " Wheel Rim"
If Len(ary2(i, 16)) > 80 And Len(ary2(i, 16)) <= 84 Then
ary2(i, 16) = "One (1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicFINISH.Item(ary2(i, 4)) & " " & ary2(i, 10) & " " & ary2(i, 11) & " Wheel"
End If
If Len(ary2(i, 16)) > 80 Then
ary2(i, 16) = "One (1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicFINISH.Item(ary2(i, 4)) & " " & ary2(i, 10) & " Wheel"
End If
If Len(ary2(i, 16)) > 80 Then
ary2(i, 16) = "One (1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicSHORT.Item(ary2(i, 4)) & " " & ary2(i, 10) & " Wheel"
End If
If Len(ary2(i, 16)) > 80 Then
ary2(i, 16) = "One (1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicSHORT.Item(ary2(i, 4)) & " " & ary2(i, 10) & " Wheel"
End If
If Len(ary2(i, 16)) > 80 Then
ary2(i, 16) = "(1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicSHORT.Item(ary2(i, 4)) & " " & ary2(i, 10) & " Wheel"
End If
If Len(ary2(i, 16)) > 80 Then
ary2(i, 16) = "(1) " & ary2(i, 7) & " " & ary2(i, 2) & " " & ary2(i, 3) & " ET " & ary2(i, 8) & " " & dicSHORT.Item(ary2(i, 4)) & " " & ary2(i, 10)
End If
ary2(i, 16) = Replace(ary2(i, 16), " ", " ")
ary2(i, 16) = Replace(ary2(i, 16), " ", " ")