2
Answers

Please guide me where is the error

Ask a question
siri

siri

12y
1.5k
1
Below code is not working Properly Displaying questions wrong. if i choose 10Questions  displaying one by one  Ex: 1,2,4,7,10 only after that iam getting the result page . 3,5,6,8,9, questions are missing . I am Retrieving data from text file.

   public partial class SimilarWords : Form
    {
        int _time, _chars, _qns;
        int ansCount = 0, Count = 0, wrngCount;
        string ans;
        static IList<string> flashWords;
        static string[] text;
        DateTime dt1, dt2;
        ComCode cc = new ComCode();
        public SimilarWords()
        {
            InitializeComponent();
        }
        public void Options_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Label lt = new Label();
                Button bt = (Button)sender;
                if (ans.Equals(bt.Text))
                {
                    ++ansCount;
                }
                Count++;
                if (Count == this._qns)
                {
                    this.Hide();
                    dt2 = DateTime.Now;
                    TimeSpan ts = dt2 - dt1;
                    wrngCount = (_qns) - ansCount;
                    new SimilarTestResults(_qns, _time, _chars, ansCount, wrngCount, Convert.ToInt32(ts.TotalSeconds)).Show();
                    return;
                }
                SimilarText();
            }
            catch (Exception ex)
            {               
            }
        }
        private void SimilarText()
        {
            try
            {       timer1.Enabled = true;
                    timer1.Interval = _time;
                    Random random = new Random();
                    var number = random.Next(0, flashWords.Count);
                    text = flashWords[number].Split(' ');
                    flashWords.RemoveAt(number);
                    PnlSml2.Visible = true;
                    PnlSml3.Visible = false;
                    cc.Shuffle(text);
                    Label[] lbl = new Label[3];
                    lbl[0] = lblSml1;
                    lbl[1] = lblSml2;
                    lbl[2] = lblSml3;
                    for (int i = 0; i < 3; i++)
                    {
                        if (text[i].ToString().StartsWith("@"))
                        {
                            ans = text[i].ToString().Substring(1);
                            lbl[i].Text = text[i].ToString().Substring(1);
                        }
                        else
                            lbl[i].Text = text[i].ToString();
                    }
                    lblQn.Text = (this.Count + 1) + "/" + (_qns).ToString();
                }
                catch (Exception ex) { Console.Write(ex.Message.ToString()); }
            }
        private void SimilarWords_Load(object sender, EventArgs e)
        {
            PnlSml2.Visible = false;
            cmbNl.SelectedIndex = 0;
            cmdNoQ.SelectedIndex = 0;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {           
            timer1.Enabled = false;
            PnlSml3.Visible = true;
        }
        private void linklblHome_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Hide();
            Form2 MyForm2 = new Form2();
            MyForm2.Show();
        }
        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                string path = "QuizFolder/";
                _time = 60000 / (Convert.ToInt32(txtsimilar.Text));
                _chars = Convert.ToInt32(cmbNl.SelectedItem.ToString());
                _qns = Convert.ToInt32(cmdNoQ.SelectedItem.ToString());
                string btnClicked = MsgBox.ShowBox("Do you Want to Continue", "Confirm");
                if (btnClicked == "0")
                {
                    dt1 = DateTime.Now;
                    FlashClass fc = new FlashClass();
                    flashWords = fc.GetRandomLines(cc.GetAppPath(path), _chars, _qns);//------->FilePathSetting
                    SimilarText();
                    btnWrong_Click();
                    btnCorrect_Click();                   
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowBox("Please Select Fields ");
            }
        }
        private void btnCorrect_Click()
        {
           btnCorrect.Click += Options_SelectedIndexChanged;  //May be Error here
        }
        private void btnWrong_Click()
        {
           btnWrong.Click += Options_SelectedIndexChanged; // May be Error here 
        }
        private void txtsimilar_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar < '0' || e.KeyChar > '9')//allow only numbers in textbox
            {
                e.Handled = true;
            }
        }
        private void btnWrong_Click(object sender, EventArgs e)
        {           
            btnWrong_Click();
        }
        private void btnCorrect_Click(object sender, EventArgs e)
        {
            btnCorrect_Click();
        }
    }

Answers (2)