using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace คิดเกรด { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { double t; t = double.Parse(textBox1.Text); มันจะแสดงerrorในส่วนของตรงนี้ if (t >= 79) textBox2.Text = "คุณได้เกรด : 4"; else if (t >= 69) textBox2.Text = "คุณได้เกรด : 3"; else if (t >= 59) textBox2.Text = "คุณได้เกรด : 2"; else if (t >= 49) textBox2.Text = "คุณได้เกรด : 1"; else textBox2.Text = "คุณได้เกรด : 0"; } private void button3_Click(object sender, EventArgs e) { this.Close(); } private void button2_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); } } }
try { double.Parse(textBox1.Text); } catch { message.show("ไม่สามารถแปลงเป็น ตัวเลขได้"); return; } double t; t = double.Parse(textBox1.Text); if (t >= 79) textBox2.Text = "คุณได้เกรด : 4"; else if (t >= 69) textBox2.Text = "คุณได้เกรด : 3"; else if (t >= 59) textBox2.Text = "คุณได้เกรด : 2"; else if (t >= 49) textBox2.Text = "คุณได้เกรด : 1"; else textBox2.Text = "คุณได้เกรด : 0";
double Num; bool isNum = double.TryParse(textBox1.Text.Trim(), out Num); if (isNum) { if (num >= 79) textBox2.Text = "คุณได้เกรด : 4"; else if (num >= 69) textBox2.Text = "คุณได้เกรด : 3"; else if (num >= 59) textBox2.Text = "คุณได้เกรด : 2"; else if (num >= 49) textBox2.Text = "คุณได้เกรด : 1"; else textBox2.Text = "คุณได้เกรด : 0"; } else { textBox2.Text = "กรอกแต่ตัวเลขดิ"; }
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (System.Char.IsNumber(e.KeyChar) == false && e.KeyChar != 8) { e.Handled = true; } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง