Moving an array element to a variable.
-
Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks
-
Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks
I tried it:
public static string\[\] Trux\_Info = new string\[20\]; public static string port\_in = ""; private void button1\_Click(object sender, EventArgs e) { Trux\_Info\[0\] = "Hello"; Trux\_Info\[1\] = "There"; Trux\_Info\[2\] = "This"; Trux\_Info\[3\] = "Is"; Trux\_Info\[4\] = "A"; Trux\_Info\[5\] = "Test"; port\_in = Trux\_Info\[3\]; MessageBox.Show(port\_in); }
It show "Is" - which is what I would expect. So, there is something you aren't telling us. Give us a cut-down-but-still-not-working sample of the code that isn't doing it's job, and tell us what it is doing instead.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks
Griff is right. There's something you're not telling us. What IS it doing and what are you EXPECTING it to do?? We also need to see a more complete code snippet showing the offending code.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Moving an array element to a variable. When I started I didn't think just taking an element and copying to a variable was such a hassle. OK, I have a string array defined as: public static string[] Trux_Info = new string[20]; and I have a varaible define as public static string port_in = ""; Now I thought that something like port_in = Trux_Info[3] would work. It didn't. I tried Trux_Info.GetValue(3). It didn't work right. I know Trux_Info has info I can print to screen\file and the right info is there. I even passed the array across child, parent and back to a different child, the info is there. I really need this element to go to this single variable, because after this happens then the processing can begin. Any and all suggestion are appreciated. Thanks
Ok It's one of those things where another of section of code was causing the problem. It had nothing to do with the array. Problem fixed array transfered properly. Say it with me now, ROOKIE!!!!!!!!!!!!!! I do appreciate the expediant answers. Consider this line/thread closed Thanks L.