sassur Posted January 16, 2004 Posted January 16, 2004 In PHP you can do this $name = "Fredrik"; $var = "name"; echo ${$var}; and the output will be Fredrik Now I wonder if you can do somethins similar in C# or VB.NET? --- Sassur Quote
Bodybag Posted January 16, 2004 Posted January 16, 2004 dim s as string= "John" response.write (s) Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
sassur Posted January 19, 2004 Author Posted January 19, 2004 dim s as string= "John" response.write (s) For a starter thats classic VB I asked about C# or VB.NET. And thats not what I asked for. I know how to define a variable and print it to the page. Quote
bungpeng Posted January 19, 2004 Posted January 19, 2004 In VBScript, we can use "ESCAPE" and "EXECUTE", but I not sure whether VB.NET can use it. Quote
samsmithnz Posted January 19, 2004 Posted January 19, 2004 Its almost exactly the same in C#. string s = "John"; response.write (s); Quote Thanks Sam http://www.samsmith.co.nz
sassur Posted January 19, 2004 Author Posted January 19, 2004 Its almost exactly the same in C#. string s = "John"; response.write (s); But as I said i the previous post, that isn't what I'm asking for. Trying to explain better: $name1 = "Fredrik"; $name2 = "Andreas"; $var = "name1"; echo $var . " = " . ${$var}; echo "<br>"; $var = "name2"; echo $var . " = " . ${$var}; echo "<br>"; and the output will be name1 = Fredrik name2 = Andreas Quote
Bodybag Posted January 20, 2004 Posted January 20, 2004 dim s1 as string = "jack" dim s2 as string = "Daniels" label1.text = "i drink " & s1 & " " & s2 & "<br>" Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
samsmithnz Posted January 20, 2004 Posted January 20, 2004 Am I the only one that doesn't understand what you're asking for exactly? Quote Thanks Sam http://www.samsmith.co.nz
Bodybag Posted January 20, 2004 Posted January 20, 2004 I am a little lost myself. Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
sassur Posted January 20, 2004 Author Posted January 20, 2004 It look's more complicated then it is. The key to it is the variable $var I will try to explane each line by it self $name1 = "Fredrik"; initiates $name1 to Fredrik $name2 = "Andreas"; initiates $name2 to Andreas $var = "name1"; initiates $var to name1 echo $var . " = " . ${$var}; this will print : name1 = Fredrik take a look at ${$var}, that code means: the variable with the name in variable $var therefore ${$var} equels the variable $name1 echo "<br>"; prints "<br>" $var = "name2"; set $var to name2 echo $var . " = " . ${$var}; name1 = Andreas now the variable $var conatins name2 therefore ${$var} equels the variable $name2 echo "<br>"; prints "<br>" Hoppes this makes it a little clearer. Quote
Administrators PlausiblyDamp Posted January 20, 2004 Administrators Posted January 20, 2004 Not sure if you can do it exactly the way you say but you could achieve something similar with a collection. Dim vars As New Collections.Specialized.StringDictionary vars.Add("Name1", "Frederik") vars.Add("Name2", "Andreas") Dim name As String = "Name1" Response.writeline(vars(name) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sassur Posted January 20, 2004 Author Posted January 20, 2004 Not sure if you can do it exactly the way you say but you could achieve something similar with a collection. Dim vars As New Collections.Specialized.StringDictionary vars.Add("Name1", "Frederik") vars.Add("Name2", "Andreas") Dim name As String = "Name1" Response.writeline(vars(name) Thanks, but not exactly that. It seams that you cant use the Eval function to achieve what I want, but i havenät looked into it very deeply. Quote
samsmithnz Posted January 20, 2004 Posted January 20, 2004 Why do you need to print the variable names? Quote Thanks Sam http://www.samsmith.co.nz
Administrators PlausiblyDamp Posted January 20, 2004 Administrators Posted January 20, 2004 Could you give us a reason why you need to do it that way? There may be a better alternative in ASP.Net. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
iebidan Posted January 20, 2004 Posted January 20, 2004 I don't see the use for what you're asking, seems to me like more memory consumption, if I want to copy the value of 1 variable into another variable I'll do something really simple string name1 = "Superman"; string name2 = "Batman"; name1 = name2; There you go, I assigned the value of the second variable into the first one, what's the result ? "BATMAN", why do things the hard way?????, this is exactly the same thing you're doing Quote Fat kids are harder to kidnap
samsmithnz Posted January 20, 2004 Posted January 20, 2004 I don't see the use for what you're asking, seems to me like more memory consumption, if I want to copy the value of 1 variable into another variable I'll do something really simple string name1 = "Superman"; string name2 = "Batman"; name1 = name2; There you go, I assigned the value of the second variable into the first one, what's the result ? "BATMAN", why do things the hard way?????, this is exactly the same thing you're doing I think he's trying to print the actual name of the variable too. Thats the main difference. Quote Thanks Sam http://www.samsmith.co.nz
vbFace Posted January 20, 2004 Posted January 20, 2004 Sounds like the orig. example is a pseudo-pointer in php. No pointers in VB.NET I believe. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.