To speed up some very repetitive coding I want to extract a string value from a variable name,
e.g. extract the word "Area" from a field defined
Dim mstrArea as String
Exactly what is it you want? Do you want the names of your variables to be parsed by VB? This won't work unless you write some sort of an add-in that can parse your project files at design time....
Greetings,
Rick
Call SetComboBox(Combo1, "2"
Call SetComboBox(Combo2, "C"
End Sub
'Set a combo box to a particular item
Public Sub SetComboBox(ByVal cboBox As ComboBox, ByVal strValue As String)
Dim lngCtr As Long
For lngCtr = 0 To cboBox.ListCount
If cboBox.List(lngCtr) = strValue Then
cboBox.ListIndex = lngCtr
Exit For
End If
Next
End Sub
No, you can not programmatically extract a portion of the a variable declaration in your run-time code. That is called "self-modifying code" and that approach went out in the 1960's.
What you can do is write an Add-In to IDE that treats your source code as data. I have written a couple of those, but it well beyond the scope of this forum to get into it.
I believe that Dan Appleman has some "how-to" information. His URL is
WeLL! I was just going to say... [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
Er...it wasn't. Or at least wasn't mean to be. I genuinely wanted to know if you thought add-ins in general were beyond the scope of this VB5&6 forum (and if so, why), or whether you meant the particular add-ins that you had written and referred to.
My only excuse ist that, absent body language and intonation, intent is so easily construed.
I do believe that a tutorial on the writing of Add-Ins is beyond the scope of this forum. I have yet to see the topic covered in under 40 pages. The reason I suggested Dan Appleman is that, when I got in a bind writing a similar add-in to the one required for hammy's situation, I called Desaware, Dan's company, and got help from one of his programmers.
If you're only dealing with strings, you could do this by adding them to a collection object, using the keyname in place of the variable name. This would let you achieve what you're after, but only for strings.
Failing that, if you need to move beyond strings, I would declare a new object that holds the value in a variant property, and then use collections with that...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.