Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use programming language to realize random roll call program

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use programming language to achieve random roll call program". The content is easy to understand and clear, hoping to help you solve your doubts. Let the editor lead you to study and learn the article "how to use programming language to implement random roll call program".

Using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; using System.Drawing; namespace Randoms {public partial class Main: Form {FileStream fs = null; StreamReader sr = null; / / StreamWriter sw = null; List names = new List (); Random rd = new Random (); int jg = 0 / / string syspath = System.Environment.CommandLine;// current program path string syspath = System.Windows.Forms.Application.StartupPath; public Main () {InitializeComponent (); / / GetData () / / get data} private void GetData () {string Namesaddress = syspath + "\\ Names.txt"; try {fs = new FileStream (Namesaddress, FileMode.Open); sr = new StreamReader (fs) / / string count=sr.ReadLine (); / / while (countlessness null) / / {/ / name.Add (count.ToString ()); / /} while (true) {string s = sr.ReadLine () If (s! = null) names.Add (s); else break;}} catch (Exception) {throw } finally {sr.Close (); fs.Close () }} / start roll call / private void button1_Click (object sender, EventArgs e) {this.button2.Enabled = true; lab.ForeColor = Color.Black If (names.Count = = 0) {this.time.Enabled = false; lab.Text = "Please Reload At First";} else {this.time.Enabled = true } / counter / private void time_Tick (object sender, EventArgs e) {int rf = names.Count; jg = rd.Next (0, rf) Lab.Text = names [jg] } / stop / private void button2_Click (object sender EventArgs e) {if (names.Count = = 0) {this.time.Enabled = false Lab.Text = "The End"; / / GetData ();} else {lab.ForeColor = Color.Blue; this.time.Enabled = false; names.RemoveAt (jg) }} / load owner / private void Main_Load (object sender, EventArgs e) {string Namesaddress = syspath + "\\ Names.txt" If (System.IO.File.Exists (Namesaddress)) {GetData ();} else {MessageBox.Show ("check whether the Names.txt file exists"); Application.Exit () }} / reload / private void button3_Click (object sender, EventArgs e) {lab.ForeColor = Color.Black; this.time.Enabled = false Lab.Text = "Load Complete"; GetData (); this.button2.Enabled = false;} these are all the contents of the article "how to use a programming language to implement a random roll call program". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report