Click here to Skip to main content
11,932,048 members (55,064 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# VS2010
Hey guys!

I'd like to write in a textbox a string and then give it a a value like "2". (Case 2Smile | :)
After this, I'd like to press a button and after a random script get one of the sentences i wrote. How can I achieve this?

Something like:

If button is clicked:
new case?!
new random(1,x)

Switch (x)
case 1:

case 2:

I am a newbie at this.. If I can help you to further understand my thought I'll do my best... Thanks Smile | :)
Posted 13-Dec-12 13:49pm
Matt T Heffron 13-Dec-12 18:55pm
So it *seems* you want:
repeat {input a string and associate it with a (unique?)number} some number of times.
on button click:
pick one of the previously input strings at random and display it

Is that your problem?
Filipe Luna 13-Dec-12 19:09pm
Exactly! How can I do that?
jibesh 13-Dec-12 19:12pm
did you start writing the code? if not please start writing and paste the code where you stuck and what part of the code you dont understand. we dont code! we solve error!!
Sergey Alexandrovich Kryukov 13-Dec-12 19:13pm
There is no scripting here. C# is not a scripting language, .NET is not a scripting platform...
Filipe Luna 13-Dec-12 19:15pm
I just want to create a string, give it an int value and then randomly generate an int value and use it to get the string.
And another thing i needed to do would be to somehow save the generated strings after closing the program...
Sergey Alexandrovich Kryukov 13-Dec-12 20:23pm
How is this "I just want" related to the issue? First of all, this is not scripting, everything else goes next. :-)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can use a dictionary to associate ints with strings. Then you can look them up from there. So make the int the key, store the string, keep track of the ints you created, and look them up. A dictionary is perhaps a slightly complex container to learn about at this stage, but that's how you'd do it
Filipe Luna 13-Dec-12 19:34pm
Thanks again Chris!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In C# you have set of Collection classes where you can store and retrieve data using a key or index.

refer these links to know more about Collection classes.[^][^]

Define any of the collection class in your application to deal with the strings when the application is running.

to restore the strings for later use you must save the file before closing the application and read the file while loading your application. check this for working on .txt files.[^]
Filipe Luna 13-Dec-12 19:34pm
I'll have to do some more reading! Thank you for sharing this with me :)
jibesh 13-Dec-12 19:36pm
Yes.. thats how you have to start... more reading.. more knowledge :) good luck
Filipe Luna 13-Dec-12 19:46pm
Thanks man.. I'm just very new to this and quite ambitious :p

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100