473,804 Members | 4,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a variable name as the value of another variable.

Hi,

Something I've never come across before and has given me a headache.
I have a txt file with content similar to below I want to read in each
line do a split on the = and then create a variable with the name of
the first value and the value of the second. I'm fine with the
splitting etc but I haven't got a clue of how to set the variable name
to the value on another variable?

any ideas anyone?

Variable1=Value 1
Variable2=Value 2
etc etc

Oct 11 '07 #1
6 4433
rd*********@hot mail.co.uk wrote:
Hi,

Something I've never come across before and has given me a headache.
I have a txt file with content similar to below I want to read in each
line do a split on the = and then create a variable with the name of
the first value and the value of the second. I'm fine with the
splitting etc but I haven't got a clue of how to set the variable name
to the value on another variable?

any ideas anyone?

Variable1=Value 1
Variable2=Value 2
etc etc
Why do you need dynamic variable names? If you could explain the necessity,
perhaps we could suggest an alternative, such as a Dictionary object.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 11 '07 #2
Your variables have to be declared before you can execute your code. How
would you be able to create a variable named, for example, Variable1 until
the program is executed and you actually encounter it.

You could create an array of 2 element arrays! The first element could
contain the name of Variable1, and the second element could contain the
value.

If this doesn't help, you might want to expand on your question.

Regards,
"Bondo" Joe

<rd*********@ho tmail.co.ukwrot e:
Hi,

Something I've never come across before and has given me a headache.
I have a txt file with content similar to below I want to read in each
line do a split on the = and then create a variable with the name of
the first value and the value of the second. I'm fine with the
splitting etc but I haven't got a clue of how to set the variable name
to the value on another variable?

any ideas anyone?

Variable1=Value 1
Variable2=Value 2
etc etc

Oct 11 '07 #3

"jp2code" <poojo.com/mailwrote in message
news:uJ******** ******@TK2MSFTN GP06.phx.gbl...
Your variables have to be declared before you can execute your code. How
would you be able to create a variable named, for example, Variable1 until
the program is executed and you actually encounter it.
Actually, the VBS Execute statement allows you to execute script code,
passed to it in a variable. It is possible to dynamically construct
variable declarations, assignments, functions, etc, and then run the
generated code in the same context as the static part of the script.

That part is easy; coming up with a valid and compelling reason to use this
is the challenge. In the case of dynamically declared variables, what good
are they, unless they're referenced elsewhere in the code (and if that was
the case, they really wouldn't be all that dynamic, would they?

As for the OP, if the .txt file contains legal VBS assignments, why split,
why not just execute the whole file? Otoh, allowing unknown script to be
executed on your server is pretty low on the list of safe and sane things
for your site to facilitate.

In almost all cases there are better design options to be had by using
arrays or a dictionary... in fact, the overwhelming majority of reasons
people think they want to write self-modifying code are really, really lame.
So to the OP, consider all options first; use Execute as a last resort.
-Mark

You could create an array of 2 element arrays! The first element could
contain the name of Variable1, and the second element could contain the
value.

If this doesn't help, you might want to expand on your question.

Regards,
"Bondo" Joe

<rd*********@ho tmail.co.ukwrot e:
>Hi,

Something I've never come across before and has given me a headache.
I have a txt file with content similar to below I want to read in each
line do a split on the = and then create a variable with the name of
the first value and the value of the second. I'm fine with the
splitting etc but I haven't got a clue of how to set the variable name
to the value on another variable?

any ideas anyone?

Variable1=Valu e1
Variable2=Valu e2
etc etc


Oct 12 '07 #4
Mark J. McGinty wrote:
In almost all cases there are better design options to be had by using
arrays or a dictionary... in fact, the overwhelming majority of
reasons people think they want to write self-modifying code are
really, really lame. So to the OP, consider all options first; use
Execute as a last resort.
..
.... and [also to the OP] the reason why Execute should be avoided? Because
every use of Execute in your code causes a new instance of the vbscript
compiler to be spawned, impairing performance and utilizing extra server
resources.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 12 '07 #5

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcomwrote in message
news:OG******** ******@TK2MSFTN GP04.phx.gbl...
Mark J. McGinty wrote:
>In almost all cases there are better design options to be had by using
arrays or a dictionary... in fact, the overwhelming majority of
reasons people think they want to write self-modifying code are
really, really lame. So to the OP, consider all options first; use
Execute as a last resort.
.
... and [also to the OP] the reason why Execute should be avoided? Because
every use of Execute in your code causes a new instance of the vbscript
compiler to be spawned, impairing performance and utilizing extra server
resources.
....spawns a new instance of the vbscript compiler? Ooook... sounds
serious... I wonder if it spawns the vbscript linker too?

I don't suppose you have a link about this? I'd like to read more, but
can't seem to find anything on google.
-Mark

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Oct 13 '07 #6
Mark J. McGinty wrote:
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcomwrote in message
news:OG******** ******@TK2MSFTN GP04.phx.gbl...
>Mark J. McGinty wrote:
>>In almost all cases there are better design options to be had by
using arrays or a dictionary... in fact, the overwhelming majority
of reasons people think they want to write self-modifying code are
really, really lame. So to the OP, consider all options first; use
Execute as a last resort.
.
... and [also to the OP] the reason why Execute should be avoided?
Because every use of Execute in your code causes a new instance of
the vbscript compiler to be spawned, impairing performance and
utilizing extra server resources.

...spawns a new instance of the vbscript compiler? Ooook... sounds
serious... I wonder if it spawns the vbscript linker too?

I don't suppose you have a link about this? I'd like to read more,
but can't seem to find anything on google.

Google for Eric Lippert's "famous" "Eval is Evil" blog entry (Fabulous
Adventures in Coding)

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 13 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
40656
by: Fuzzyman | last post by:
Pythons internal 'pointers' system is certainly causing me a few headaches..... When I want to copy the contents of a variable I find it impossible to know whether I've copied the contents *or* just created a new pointer to the original value.... For example I wanted to initialize a list of empty lists.... a=, , , , ] I thought there has to be a *really* easy way of doing it - after a
22
3158
by: Tom Moroow | last post by:
Hi, I'm pretty new to javascript and was wondering how you would piece together a variable name and then assign it a value. I want to create a hidden field and assign it a value based on the value of another variable Right now it looks like: ("document.all.SM_MARK_10" + dateNumber + ".value") where dateNumber is an already defined integer. What I want is to say
10
13745
by: sam | last post by:
Hi, I m wondering why I can't declare reference variable for default value in a function argument variable? eg. class A { void f(string &str="");
6
2953
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the script created them. It used things like parentnode, insertBefore, appendChildNode,... Any ideas/direction is appreciated.
8
5971
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1; this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ApplicantName", dataset.Tables.Columns.DataType, 50,
10
2099
by: connyledin | last post by:
Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file: http://esnips.com/webfolder/b71bfe95-d363-4dd3-bfad-39999a9e36d0 What i have the biggest problems with now is between line 8 and 23. How i can move the character trough the game. Other parts of the game that have with the movement to do is between line 83-114 and...
5
2281
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve this but it's clear that I'm misunderstanding $variable persistence. I posted a similar enquiry over at alt.php.mysql, but I guess this is a more appropriate forum because the problems I'm having relate to PHP. Any help appreciated. ...
32
2571
by: Joe | last post by:
I am just starting to use Object Oriented PHP coding, and I am seeing quite often the following (this example taken from a wiki): $wakka =& new Wakka($wakkaConfig); What exactly is the =&, and why is it different from = ?
19
1956
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { switch (((Sale)e.Row.DataItem).SzPN) {
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10593
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.