Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey guys!

I'd like to write in a textbox a string and then give it a a value like "2". (Case 2:)
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:
x=0

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 :)
Posted
Comments
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...
--SA
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...

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
 
Share this answer
 
Comments
Filipe Luna 13-Dec-12 19:34pm    
Thanks again Chris!
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.
http://msdn.microsoft.com/en-us/library/ms172181(v=vs.80).aspx[^]
http://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.80).aspx[^]

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.
http://www.csharp-examples.net/filestream-open-file/[^]
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900