Hi , i'm new in C# although it was a subject taught in school , but we did not learn things as far up as this.
I was tasked to design a form where i am able to click a button and it will generate a random number on screen .
The project is to make a form for a Lucky draw system.
upon multiple clicks , the number should not be repeated. The number will be displayed through a label.
Once the number is displayed , i will also need to show the ticket's name holder too.
I am currently only able to generate new numbers but it will repeat thou.
i want it to be non-repeatable upon multiple clicks in the same button.
by using
Stack numberCheck = new Stack();
Random randomNumber = new Random();
bool exists = false;
//generates a number then checks if it has already been made
exists = numberCheck.Contains(number);
number = randomNumber.Next(1, 50);
if (exists == true)
{
//shrink this code down later by making a function of your own
//which can also be used above too
number = randomNumber.Next(1, 50);
exists = numberCheck.Contains(number);
if (exists == true)
{
number = randomNumber.Next(number, 50);
exists = numberCheck.Contains(number);
}
}
else
{
textBox3.Text = number.ToString();
}
but the number will still repeat .
can someone help me please? and also teach me on how to draw out data from an access database.
Such as when ticket number is generated , the ticket's holder name will also appear .
i am currently only able to add the access file as an data source but have no idea how to go about
drawing data out from the ticket number.
the ticket holder's name will be displayed in a textbox.
Thanks very much for all the help , please keep it as simple as possible as i'm only a beginner in C#.
All help will be deeply appreciated.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Hi gerrylowry , thanks for the help , it is deeply appreciated , but i still have no rough idea of how about doing this , such as what do i have to use.
Possibly can you give me like codes to study on or give me a draft codes to generate the non-repeating random numbers through the click of a button , so that i can edit it and implement it into my work.
dim sGuid as string
sGuid = System.Guid.NewGuid.ToString()
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
FWIW, your peers here at forums.asp.net are here, voluntarily, to help you help yourself and to guide you ... but you have to do some of the work ... if you want someone to simply write the code for you, you might want to ask excellent programmers like Paul
Lintion for their rates ... Paul and others, myself included will help you ... but you too must put forth the effort.
Note: when you find examples, experiment with them using vs2010 and/or LINQPad 4*.
g.
* if you do not have LINQPad 4:
TOOLS ... get yourself a FREE copy of LINQPad 4 (http://linqpad.net) .. Joe Albahari's LINQPad 4 is an awesome programmer's scratch pad that enables you to quickly check out code snippets you find in books and on web sites
plus LINQPad also lets you rapidly experiment with c# ideas before committing them to vs2010.
LINQPad 4 supports c#, F#, SQL, vb.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Hi , thanks guys for your help , it is all very appreciated .
I have tried doing the work myself by exploring and such however my C# skills are very LIMITED , that is why i need help with it.
The codes that i have posted , even i myself do not understand them , i've searched over the net for the codes , however they are not activated through the use of a button , that is why i seek help .
Even sites that you guys have referred me to , i've read it over 5 times each including all the codes and yet i still have no idea how to implement it into an button to show it in an textbox or a label.
princebebe
Member
14 Points
8 Posts
Generating None repeating random numbers and getting data from access
Feb 29, 2012 03:51 AM|LINK
Hi , i'm new in C# although it was a subject taught in school , but we did not learn things as far up as this.
I was tasked to design a form where i am able to click a button and it will generate a random number on screen .
The project is to make a form for a Lucky draw system.
upon multiple clicks , the number should not be repeated. The number will be displayed through a label.
Once the number is displayed , i will also need to show the ticket's name holder too.
I am currently only able to generate new numbers but it will repeat thou.
i want it to be non-repeatable upon multiple clicks in the same button.
by using
Stack numberCheck = new Stack();
Random randomNumber = new Random();
bool exists = false;
//generates a number then checks if it has already been made
exists = numberCheck.Contains(number);
number = randomNumber.Next(1, 50);
if (exists == true)
{
//shrink this code down later by making a function of your own
//which can also be used above too
number = randomNumber.Next(1, 50);
exists = numberCheck.Contains(number);
if (exists == true)
{
number = randomNumber.Next(number, 50);
exists = numberCheck.Contains(number);
}
}
else
{
textBox3.Text = number.ToString();
}
but the number will still repeat .
can someone help me please? and also teach me on how to draw out data from an access database.
Such as when ticket number is generated , the ticket's holder name will also appear .
i am currently only able to add the access file as an data source but have no idea how to go about
drawing data out from the ticket number.
the ticket holder's name will be displayed in a textbox.
Thanks very much for all the help , please keep it as simple as possible as i'm only a beginner in C#.
All help will be deeply appreciated.
gerrylowry
All-Star
20577 Points
5721 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 04:10 AM|LINK
@ princebebe
http://msdn.microsoft.com/en-us/library/system.random.aspx
study the above page.
g.
gerrylowry
All-Star
20577 Points
5721 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 04:20 AM|LINK
@ princebebe
tip: make ONE question for each topic you post to any forum, including forums.asp.net ... FWIW
see Home/ASP.NET Forums/Data Access/Access Databases and AccessDataSource Control
short answer: http://msdn.microsoft.com/en-us/library/ms186197.aspx
"Data Access (How Do I in C#)"
http://msdn.microsoft.com/en-us/library/ms171893.aspx
"Walkthrough: Connecting to Data in an Access Database (Windows Forms)"
g.
princebebe
Member
14 Points
8 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 05:00 AM|LINK
Hi gerrylowry , thanks for the help , it is deeply appreciated , but i still have no rough idea of how about doing this , such as what do i have to use.
Possibly can you give me like codes to study on or give me a draft codes to generate the non-repeating random numbers through the click of a button , so that i can edit it and implement it into my work.
Thanks!
venkatmca008
Participant
1810 Points
341 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 05:25 AM|LINK
hi..please try this...
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
gerrylowry
All-Star
20577 Points
5721 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 05:30 AM|LINK
@ princebebe
FWIW, your peers here at forums.asp.net are here, voluntarily, to help you help yourself and to guide you ... but you have to do some of the work ... if you want someone to simply write the code for you, you might want to ask excellent programmers like Paul Lintion for their rates ... Paul and others, myself included will help you ... but you too must put forth the effort.
at the link that i gave you, there is example code: http://msdn.microsoft.com/en-us/library/system.random.aspx
their example: "creates a single random number generator ... to generate sequences of random numbers within different ranges.
Have you read the "Random Class" page http://msdn.microsoft.com/en-us/library/system.random.aspx?
Note: when you find examples, experiment with them using vs2010 and/or LINQPad 4*.
g.
* if you do not have LINQPad 4:
TOOLS ... get yourself a FREE copy of LINQPad 4 (http://linqpad.net) .. Joe Albahari's LINQPad 4 is an awesome programmer's scratch pad that enables you to quickly check out code snippets you find in books and on web sites plus LINQPad also lets you rapidly experiment with c# ideas before committing them to vs2010.
LINQPad 4 supports c#, F#, SQL, vb.
gerrylowry
All-Star
20577 Points
5721 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 05:33 AM|LINK
@ venkatmca008
FWIW, while GUIDs are random*, imho, i would not classify them as numbers.
g.
* http://en.wikipedia.org/wiki/Globally_unique_identifier
http://msdn.microsoft.com/en-us/library/system.guid.aspx
venkatmca008
Participant
1810 Points
341 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 06:26 AM|LINK
hi..please refer this...
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=892&lngWId=1
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
princebebe
Member
14 Points
8 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 06:36 AM|LINK
Hi , thanks guys for your help , it is all very appreciated .
I have tried doing the work myself by exploring and such however my C# skills are very LIMITED , that is why i need help with it.
The codes that i have posted , even i myself do not understand them , i've searched over the net for the codes , however they are not activated through the use of a button , that is why i seek help .
Even sites that you guys have referred me to , i've read it over 5 times each including all the codes and yet i still have no idea how to implement it into an button to show it in an textbox or a label.
princebebe
Member
14 Points
8 Posts
Re: Generating None repeating random numbers and getting data from access
Feb 29, 2012 06:53 AM|LINK
Hi venkat , how do i use the above codes?
dim sGuid as string
sGuid = System.Guid.NewGuid.ToString()
where do i implement it into?
into the current codes that i have?