Advertisement
DrAungWinHtut

Questions from File and Testing

Mar 4th, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace _2022030201_CS_Array_Tutorial
  13. {
  14.     public partial class frmArray : Form
  15.     {
  16.         int iQno = 0;
  17.         string[] saQA = new string[100];
  18.         int iTotalQuestion = 0;
  19.         int iTotalMarks = 0;
  20.         string[] saSplit = new string[6];
  21.  
  22.         public frmArray()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void btnTest_Click(object sender, EventArgs e)
  28.         {
  29.             if (iQno < iTotalQuestion ) //0 1 2      3
  30.             {
  31.                 saSplit = saQA[iQno].Split('$');
  32.                 txtNumber.Text = saSplit[0];
  33.                 txtQuestion.Text = saSplit[1];
  34.                 txtAns1.Text = saSplit[2];
  35.                 txtAns2.Text = saSplit[3];
  36.                 txtAns3.Text = saSplit[4];
  37.                 //txtCorrectAnswer.Text = saSplit[5];
  38.                 iQno++;
  39.             }
  40.             else
  41.             {
  42.                 MessageBox.Show("Exam Questions Over");
  43.             }
  44.            
  45.         }
  46.  
  47.         private void frmArray_Load(object sender, EventArgs e)
  48.         {
  49.             string sLine = string.Empty;
  50.             StreamReader sr = new StreamReader("questions.txt");
  51.             while((sLine = sr.ReadLine()) != null && (sLine != ""))
  52.             {
  53.                 saQA[iTotalQuestion ] = sLine;
  54.                 iTotalQuestion ++;
  55.             }
  56.            
  57.            
  58.             saSplit = saQA[iQno].Split('$');
  59.             txtNumber .Text = saSplit[0];
  60.             txtQuestion .Text = saSplit[1];
  61.             txtAns1.Text = saSplit[2];
  62.             txtAns2.Text = saSplit[3];
  63.             txtAns3 .Text = saSplit[4];
  64.             //txtCorrectAnswer .Text =saSplit[5];
  65.             iQno++;
  66.  
  67.             txtNumber.Enabled = false;
  68.             txtQuestion .Enabled = false;
  69.             txtAns1 .Enabled = false;
  70.             txtAns2.Enabled = false;
  71.             txtAns3.Enabled = false;
  72.             txtTotalMarks.Enabled = false;
  73.         }
  74.  
  75.         private void button1_Click(object sender, EventArgs e)
  76.         {
  77.             string sAns = txtCorrectAnswer .Text;
  78.             if(sAns == saSplit [5])
  79.             {
  80.                 iTotalMarks += 10;
  81.                 txtTotalMarks .Text = iTotalMarks .ToString();
  82.             }
  83.         }
  84.     }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement