-
Aug 26th, 2009, 10:20 AM
#1
Thread Starter
Hyperactive Member
Accessing a Variable Value
This may sound odd, but I want to be able to dynamically access a variable value.
I have a bunch of variables that correspond to bookmarks in word templates. Not all bookmarks are in all of the templates and some bookmarks are deleted under different circumstances. Well, instead of writing 4 lines of code for each book mark, I would like to be able to pull the list of bookmarks from a table for the template and the corresponding variable name. Validate the contents of the variable , i.e., strAddress = "100 Main" or strAddress = "DELETE" If DELETE then the bookmark is deleted, if not the Bookmark is updated with the value from the variable.
I have not been successful in locating the correct syntax to access the strAddress value from a variable.
VarName (Is the vailable name that is getting looked up from the table)
VarName = strAddress
I need the value in strAddress. There should be something like an index that can be accessed to find the value of strAddress from the Varname
I was thinking something like FunctionName.Variable(VarName).value but it isnt close. There must be somthing.
Thanks
Swoozie
Somedays you just should not get out of bed.
-
Aug 26th, 2009, 11:50 AM
#2
Re: Accessing a Variable Value
There isn't a built-in way to do what you want I'm afraid.
The closest I can think of at the moment is to use a Select Case (which you could put into a function), eg:
Code:
Dim strValue as String
Select Case VarName
Case "strAddress"
strValue = strAddress
Case "strName"
strValue = strName
...
End Select
-
Aug 27th, 2009, 06:35 AM
#3
Addicted Member
Re: Accessing a Variable Value
Hi Swoozie,
If you know in advanced which action to you want to perform than u can think
about the scripting.dictionary object.
There u can store your bookmarks and the proper actions as an item.
Do run this code u need a reference to the "Microsoft Scripting Runtime" if not found in the reference list, add the scrrun.dll (found in the windows32 directory)
best regards
TheOnly
PS: Be careful to call the correct dictionary object, word have also one
Code:
Public Sub dicTest()
Dim dicBmkVar As Scripting.Dictionary
Dim v As Variant
Set dicBmkVar = New Scripting.Dictionary
dicBmkVar.Add Key:="FirstBmk", Item:="Delete"
dicBmkVar.Add Key:="SecondBmk", Item:="New"
dicBmkVar.Add Key:="ThirdBmk", Item:="SQL"
dicBmkVar.Add Key:="ForthBmk", Item:="DBM"
Debug.Print "items Count: " & dicBmkVar.Count
Debug.Print dicBmkVar.Item("SecondBmk")
Debug.Print dicBmkVar("ThirdBmk")
For Each v In dicBmkVar.Keys
Debug.Print dicBmkVar.Item(v)
Next v
-
Sep 2nd, 2009, 02:50 PM
#4
Thread Starter
Hyperactive Member
Re: Accessing a Variable Value
Okay, let me see if I understand the concept.
I would "store" the values of the variables in a scripting dictionary object?
then grab the values based on the variable name from the scripting dictionary object?
thanks,
Susan
Swoozie
Somedays you just should not get out of bed.
-
Sep 2nd, 2009, 03:19 PM
#5
Re: Accessing a Variable Value
Something like
vb Code:
VarName = ActiveDocument.Bookmarks("strAddress").Range.Text
?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 3rd, 2009, 09:10 AM
#6
Thread Starter
Hyperactive Member
Re: Accessing a Variable Value
No, that is backwards. I want to dynamically read the value of varname.
i.e., we dim the variables ToAddress, CCAddress
we set the variables
toAddress = Mark
CCAddress = George
I want to read the value in these dynalmically,
i.e., varname(toaddress).value
I swear this is do able but I cant think how.
Swoozie
Somedays you just should not get out of bed.
-
Sep 3rd, 2009, 09:36 AM
#7
Re: Accessing a Variable Value
Originally Posted by swoozie
No, that is backwards. I want to dynamically read the value of varname.
i.e., we dim the variables ToAddress, CCAddress
we set the variables
toAddress = Mark
CCAddress = George
I want to read the value in these dynalmically,
i.e., varname(toaddress).value
I swear this is do able but I cant think how.
If you are storing it in a variable then call it directly. for example
vb Code:
Dim ToAddress
toAddress = Mark
'~~> This will give you the value...
Msgbox toAddress
Hope I have understood your query correctly...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 3rd, 2009, 01:11 PM
#8
Thread Starter
Hyperactive Member
Re: Accessing a Variable Value
i dont want to call it directly. let me try to explain it better.
I have several word templates that are set up slightly differently for the letter type. I want to beable to write one little section of code to populate these templates and each also goes to 1 to 4 recipients. The letter is different depending on the recipient. So I have variables that match up with the bookmarks I used for the recipients. Since not all letters have the same bookmarks I want to store int a table template, recipienttype, variable so i will look up the variable, check the value of the variable and act on the bookmark accordingly, so I do not have to use a very large if and case statement.
I want to access the value of a variable by use of another variable
Swoozie
Somedays you just should not get out of bed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|