Member Avatar for Griff0527

I am working on a project of converting VB code to C# code and I am lost as to how to read data from a prompt in C#.

Here is the snippet I am concerned with fixing, but below I will post the entire code.

private void Button1_Click(System.Object sender, System.EventArgs e)
        {
            string Prompt = null;
            decimal[] Tests1 = null;
            NumTest1 = Convert.ToInt16(txtTest1.Text);
            Array.Resize(ref Tests1, NumTest1);
            short i = 0;
            Prompt = "Please enter grade scores one at a time";
            for (i = 0; i <= Tests1.Length; i++)
            {
                Tests1[i] = Convert.ToInt16(Prompt.ToString);
                Total1 = Total1 + Tests1[i];
                textBox1.Text = Convert.ToString((Total1) / NumTest1);
                if (string.IsNullOrEmpty(textBox1.Text))
                {
                    textBox1.Text = "0";
                }
            }

        }

Below this is the entire code, it has a total of 5 errors, all relating to what I am trying to accomplish of reading data from a InputBox / Prompt. If someone can help me figure out the first one, I will be able to correct the other four errors.

To better understand the code, this program is supposed to read a class name, the number of tests in a class, then when the user clicks on the button, read the number of tests being input so it can calculate the average for that class. Also, there is another button (button 5) which calculates the overall average of all classes entered. I believe I have the code 99% correct, except I cannot test it due to not being able to figure out the InputBox in C#.

One last thing, I am using Visual Studio 2010 Ultimate.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace Griffin_GPA_Calc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        double FirstNum;
        double SecondNum;
        double ThirdNum;
        double FourthNum;
        int NumTest1;
        int NumTest2;
        int NumTest3;
        int NumTest4;
        decimal Total1;
        decimal Total2;
        decimal Total3;

        decimal Total4;


        private void Button1_Click(System.Object sender, System.EventArgs e)
        {
            string Prompt = null;
            decimal[] Tests1 = null;
            NumTest1 = Convert.ToInt16(txtTest1.Text);
            Array.Resize(ref Tests1, NumTest1);
            short i = 0;
            Prompt = "Please enter grade scores one at a time";
            for (i = 0; i <= Tests1.Length; i++)
            {
                Tests1[i] = Convert.ToInt16(Prompt.ToString);
                Total1 = Total1 + Tests1[i];
                textBox1.Text = Convert.ToString((Total1) / NumTest1);
                if (string.IsNullOrEmpty(textBox1.Text))
                {
                    textBox1.Text = "0";
                }
            }

        }


        private void Button2_Click(System.Object sender, System.EventArgs e)
        {
            string Prompt = null;
            decimal[] Tests2 = null;
            NumTest2 = Convert.ToInt16(txtTest2.Text);
            Array.Resize(ref Tests2, NumTest2);
            short j = 0;
            Prompt = "Please enter grade scores one at a time";
            for (j = 0; j <= Tests2.Length; j++)
            {
                Tests2[j] = Interaction.InputBox(Prompt);
                Total2 = Total2 + Tests2[j];
                textBox2.Text = Convert.ToString((Total2) / NumTest2);
                if (string.IsNullOrEmpty(textBox2.Text))
                {
                    textBox2.Text = "0";
                }
            }

        }


        private void Button3_Click(System.Object sender, System.EventArgs e)
        {
            string Prompt = null;
            decimal[] Tests3 = null;
            NumTest3 = Convert.ToInt16(txtTest3.Text);
            Array.Resize(ref Tests3, NumTest3);
            short k = 0;
            Prompt = "Please enter grade scores one at a time";
            for (k = 0; k <= Tests3.Length; k++)
            {
                Tests3[k] = Interaction.InputBox(Prompt);
                Total3 = Total3 + Tests3[k];
                textBox3.Text = Convert.ToString((Total3) / NumTest3);
                if (string.IsNullOrEmpty(textBox3.Text))
                {
                    textBox3.Text = "0";
                }
            }

        }


        private void Button4_Click(System.Object sender, System.EventArgs e)
        {
            string Prompt = null;
            decimal[] Tests4 = null;
            NumTest4 = Convert.ToInt16(txtTest4.Text);
            Array.Resize(ref Tests4, NumTest4);
            short l = 0;
            Prompt = "Please enter grade scores one at a time";
            for (l = 0; l <= Tests4.Length; l++)
            {
                Tests4[l] = Interaction.InputBox(Prompt);
                Total4 = Total4 + Tests4[l];
                textBox4.Text = Convert.ToString((Total4) / NumTest4);
                if (string.IsNullOrEmpty(textBox4.Text))
                {
                    textBox4.Text = "0";
                }
            }

        }


        private void Button5_Click(System.Object sender, System.EventArgs e)
        {
            textBox5.Text = Convert.ToString(((Convert.ToInt32(textBox1.Text) * (Convert.ToInt32(txtTest1.Text))) + 
                            (Convert.ToInt32(textBox2.Text) * (Convert.ToInt32(txtTest2.Text))) + (Convert.ToInt32(textBox3.Text) * 
                            (Convert.ToInt32(txtTest3.Text))) + (Convert.ToInt32(textBox4.Text) * (Convert.ToInt32(txtTest4.Text))))
                            / ((Convert.ToInt32(txtTest1.Text)) + (Convert.ToInt32(txtTest2.Text)) + (Convert.ToInt32(txtTest3.Text))
                            + (Convert.ToInt32(txtTest4.Text))));

        }

        private void Button6_Click(System.Object sender, System.EventArgs e)
        {
            FirstNum = 0;
            SecondNum = 0;
            ThirdNum = 0;
            FourthNum = 0;
            Total1 = 0;
            Total2 = 0;
            Total3 = 0;
            Total4 = 0;
            NumTest1 = 0;
            NumTest2 = 0;
            NumTest3 = 0;
            NumTest4 = 0;
            txtClass1.Text = "Class 1";
            txtClass2.Text = "Class 2";
            txtClass3.Text = "Class 3";
            txtClass4.Text = "Class 4";
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            txtTest1.Text = "0";
            txtTest2.Text = "0";
            txtTest3.Text = "0";
            txtTest4.Text = "0";

        }


        private void Button7_Click(System.Object sender, System.EventArgs e)
        {
            StreamWriter StreamToWrite = null;
            StreamToWrite = new StreamWriter("C:\\vb10sbs\\GPA\\grades.txt");
            StreamToWrite.Write(txtClass1.Text + "\n" + txtTest1.Text + "\n" + textBox1.Text + "\n" + 
                                txtClass2.Text + "\n" + txtTest2.Text + "\n" + textBox2.Text + "\n" + 
                                txtClass3.Text + "\n" + txtTest3.Text + "\n" + textBox3.Text + "\n" +
                                txtClass4.Text + "\n" + txtTest4.Text + "\n" + textBox4.Text);
            StreamToWrite.Close();
            System.Environment.Exit(0);
        }

        private void ToolStripMenuItem1_Click(System.Object sender, System.EventArgs e)
        {
            StreamReader StreamToRead = null;
            StreamToRead = new StreamReader("C:\\vb10sbs\\GPA\\grades.txt");
            txtClass1.Text = StreamToRead.ReadLine();
            txtTest1.Text = StreamToRead.ReadLine();
            textBox1.Text = StreamToRead.ReadLine();
            txtClass2.Text = StreamToRead.ReadLine();
            txtTest2.Text = StreamToRead.ReadLine();
            textBox2.Text = StreamToRead.ReadLine();
            txtClass3.Text = StreamToRead.ReadLine();
            txtTest3.Text = StreamToRead.ReadLine();
            textBox3.Text = StreamToRead.ReadLine();
            txtClass4.Text = StreamToRead.ReadLine();
            txtTest4.Text = StreamToRead.ReadLine();
            textBox4.Text = StreamToRead.ReadLine();
            StreamToRead.Close();
        }

        private void ToolStripMenuItem2_Click(System.Object sender, System.EventArgs e)
        {
            StreamWriter StreamToWrite = null;
            StreamToWrite = new StreamWriter("C:\\vb10sbs\\GPA\\grades.txt");
            StreamToWrite.Write(txtClass1.Text + "\n" + txtTest1.Text + "\n" + textBox1.Text + "\n" +
                                txtClass2.Text + "\n" + txtTest2.Text + "\n" + textBox2.Text + "\n" +
                                txtClass3.Text + "\n" + txtTest3.Text + "\n" + textBox3.Text + "\n" +
                                txtClass4.Text + "\n" + txtTest4.Text + "\n" + textBox4.Text);
            StreamToWrite.Close();
        }


        private void ResetToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
        {
            button6.PerformClick();
        }

        private void ExitToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
        {
            button7.PerformClick();
        }

        private void Form1_FormClosing(System.Object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            StreamWriter StreamToWrite = null;
            StreamToWrite = new StreamWriter("C:\\vb10sbs\\GPA\\grades.txt");
            StreamToWrite.Write(txtClass1.Text + "\n" + txtTest1.Text + "\n" + textBox1.Text + "\n" +
                                txtClass2.Text + "\n" + txtTest2.Text + "\n" + textBox2.Text + "\n" +
                                txtClass3.Text + "\n" + txtTest3.Text + "\n" + textBox3.Text + "\n" +
                                txtClass4.Text + "\n" + txtTest4.Text + "\n" + textBox4.Text);
            StreamToWrite.Close();
        }


        private void Form1_Load(System.Object sender, System.EventArgs e)
        {
            StreamReader StreamToRead = null;
            StreamToRead = new StreamReader("C:\\vb10sbs\\GPA\\grades.txt");
            txtClass1.Text = StreamToRead.ReadLine();
            txtTest1.Text = StreamToRead.ReadLine();
            textBox1.Text = StreamToRead.ReadLine();
            txtClass2.Text = StreamToRead.ReadLine();
            txtTest2.Text = StreamToRead.ReadLine();
            textBox2.Text = StreamToRead.ReadLine();
            txtClass3.Text = StreamToRead.ReadLine();
            txtTest3.Text = StreamToRead.ReadLine();
            textBox3.Text = StreamToRead.ReadLine();
            txtClass4.Text = StreamToRead.ReadLine();
            txtTest4.Text = StreamToRead.ReadLine();
            textBox4.Text = StreamToRead.ReadLine();
            StreamToRead.Close();

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                textBox1.Text = "0";
            }
            if (string.IsNullOrEmpty(textBox2.Text))
            {
                textBox2.Text = "0";
            }
            if (string.IsNullOrEmpty(textBox3.Text))
            {
                textBox3.Text = "0";
            }
            if (string.IsNullOrEmpty(textBox4.Text))
            {
                textBox4.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest1.Text))
            {
                txtTest1.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest2.Text))
            {
                txtTest2.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest3.Text))
            {
                txtTest3.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest4.Text))
            {
                txtTest4.Text = "0";
            }


        }
    }
}

For those wondering, yes this is an assignment for my college course, and yes it is due tonight. I am continuing to search the web, but everything says there is not a way to use an InputBox / Prompt object, but they all reference earlier versions of Visual Studio as well.

You say you have 5 errors but you don't tell us what they are...
You set the Prompt string within each button function and then place it in each element of the array - I'm not sure why.

Prompt = "Please enter grade scores one at a time";
for (i = 0; i <= Tests1.Length; i++)
            {
                Tests1[i] = Convert.ToInt16(Prompt.ToString);
                Total1 = Total1 + Tests1[i];
                textBox1.Text = Convert.ToString((Total1) / NumTest1);
                if (string.IsNullOrEmpty(textBox1.Text))
                {
                    textBox1.Text = "0";
                }
            }

problem one is this: Tests1 = Convert.ToInt16(Prompt.ToString); - This is should be ToString();
You're trying to convert a string ("Please enter grade scores one at a time") to an integer.
That won't work.

From a readability perspective you've capitalised all of your variables which is normally reserved for classes. Variables conventionally begin with a lowercase letter.

Post up your errors, explain why you need to convert the prompt string to an int and we'll see if we can help you more.

commented: Direct answer that made me think for myself to find one of my many errors, leading me to further investigate the rest. This poster does not give the "easy" answer, but instead expects you to LEARN from your mistakes. +2
Member Avatar for Griff0527

hericles,
I was trying to place the data from the Prompt into each element of the array, not the string itself. I am trying to do this so that the numbers entered into the prompt can be used for calculations to determine an average.

The form has a textBox in which the user inputs the number of tests, then upon clicking a button, an InputBox opens allowing the user to enter the number of scores which they input in the textBox.


I will go through and change my variables to lowercase for readability. I appreciate you pointing that out to me.
What I am trying to do is capture the string from the prompt and convert it to an integer so that mathematical functions can be performed based on the number input.

The error I am getting is: Error The best overloaded method match for 'System.Convert.ToInt16(object)' has some invalid arguments. (On line 41) because my syntax is all jacked up from "guessing" at different solutions. I also get "Argument 1: cannot convert from 'method group' to 'object', on this same line. Again, I know this is because the way I wrote the code is not functional.

The other three errors I receive are all: "The name 'Interaction' does not exist in the current context" on lines 69, 91, and 113 in which my "original attempt" also failed by using;

Tests2[j] = Interaction.InputBox(Prompt);

instead of;

Tests1[i] = Convert.ToInt16(Prompt.ToString);

Does this help explain my issue more clearly? Any advice on how to pull the string data from the prompt and store it in the array as an int so that it can be used in calculations would be much appreciated.

Member Avatar for Griff0527

testing with

Tests1[i] = Convert.ToInt16(Prompt.ToString());
Member Avatar for Griff0527

hericles,
I am not intending to read the prompt "Please enter grades one at a time" into an integer. My intent is to convert the users numerical response into an integer and utilize it for the calculations.
I was able to edit the code and get it to compile based on your earlier post, pointing out my error in ToString(). When I click on any of the buttons, nothing visibly happens. I am now wondering if I must write a separate function for C# to create the InputBox. I am going to work on writing an InputBox function to try to make the buttons function. Perhaps during that coding, I will figure out the proper object to "read" instead of "prompt".

Member Avatar for Griff0527

I was able to correct my code and make the InputBox function work, and work properly. However, I cannot get the code to catch the exception that is thrown when "button1" is clicked without any data being input into txtTest1.
I have NOT tried to add CATCH to the other buttons yet as I will add it once I have figured out button1_Click not catching the exception.

The code in Question is between lines 73 and 101.

Advice?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace Griffin_GPA_Calc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int numTest1;
        int numTest2;
        int numTest3;
        int numTest4;
        decimal total1;
        decimal total2;
        decimal total3;
        decimal total4;

        public static DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            label.Text = promptText;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            textBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text;
            return dialogResult;
        }


        private void button1_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                decimal[] tests1 = null;
                numTest1 = Convert.ToInt16(txtTest1.Text);
                Array.Resize(ref tests1, numTest1);
                short i = 0;

                for (i = 0; i <= tests1.Length - 1; i++)
                {

                    string value = string.Empty;
                    DialogResult result = InputBox("Test Scores", "Please enter your test scores one at a time:", ref value);
                    tests1[i] = Convert.ToInt16(value);
                    total1 = total1 + tests1[i];
                    textBox1.Text = Convert.ToString((total1) / numTest1);
                    if (string.IsNullOrEmpty(textBox1.Text))
                    {
                        throw new InvalidOperationException("Enter a number of tests for Class 1");

                    }
                }
            }
            catch (InvalidOperationException ioEX)
            {
                MessageBox.Show(ioEX.Message);
            }
            }


        private void button2_Click(System.Object sender, System.EventArgs e)
        {
            decimal[] tests2 = null;
            numTest2 = Convert.ToInt16(txtTest2.Text);
            Array.Resize(ref tests2, numTest2);
            short j = 0;
            for (j = 0; j <= tests2.Length - 1; j++)
            {
                string value = string.Empty;
                DialogResult result = InputBox("Test Scores", "Please enter your test scores one at a time:", ref value);
                tests2[j] = Convert.ToInt16(value);
                total2 = total2 + tests2[j];
                textBox2.Text = Convert.ToString((total2) / numTest2);
                if (string.IsNullOrEmpty(textBox2.Text))
                {
                    textBox2.Text = "0";
                }
            }

        }


        private void button3_Click(System.Object sender, System.EventArgs e)
        {
            decimal[] tests3 = null;
            numTest3 = Convert.ToInt16(txtTest3.Text);
            Array.Resize(ref tests3, numTest3);
            short k = 0;
            for (k = 0; k <= tests3.Length - 1; k++)
            {
                string value = string.Empty;
                DialogResult result = InputBox("Test Scores", "Please enter your test scores one at a time:", ref value);
                tests3[k] = Convert.ToInt16(value);
                total3 = total3 + tests3[k];
                textBox3.Text = Convert.ToString((total3) / numTest3);
                if (string.IsNullOrEmpty(textBox3.Text))
                {
                    textBox3.Text = "0";
                }
            }

        }


        private void button4_Click(System.Object sender, System.EventArgs e)
        {
            decimal[] tests4 = null;
            numTest4 = Convert.ToInt16(txtTest4.Text);
            Array.Resize(ref tests4, numTest4);
            short l = 0;
            for (l = 0; l <= tests4.Length - 1; l++)
            {
                string value = string.Empty;
                DialogResult result = InputBox("Test Scores", "Please enter your test scores one at a time:", ref value);
                tests4[l] = Convert.ToInt16(value);
                total4 = total4 + tests4[l];
                textBox4.Text = Convert.ToString((total4) / numTest4);
                if (string.IsNullOrEmpty(textBox4.Text))
                {
                    textBox4.Text = "0";
                }
            }

        }


        private void button5_Click(System.Object sender, System.EventArgs e)
        {
            textBox5.Text = Convert.ToString(((Convert.ToInt32(textBox1.Text) * (Convert.ToInt32(txtTest1.Text))) + 
                            (Convert.ToInt32(textBox2.Text) * (Convert.ToInt32(txtTest2.Text))) + (Convert.ToInt32(textBox3.Text) * 
                            (Convert.ToInt32(txtTest3.Text))) + (Convert.ToInt32(textBox4.Text) * (Convert.ToInt32(txtTest4.Text))))
                            / ((Convert.ToInt32(txtTest1.Text)) + (Convert.ToInt32(txtTest2.Text)) + (Convert.ToInt32(txtTest3.Text))
                            + (Convert.ToInt32(txtTest4.Text))));

        }

        private void button6_Click(System.Object sender, System.EventArgs e)
        {
            //firstNum = 0;
            //secondNum = 0;
            //thirdNum = 0;
            //fourthNum = 0;
            total1 = 0;
            total2 = 0;
            total3 = 0;
            total4 = 0;
            numTest1 = 0;
            numTest2 = 0;
            numTest3 = 0;
            numTest4 = 0;
            txtClass1.Text = "Class 1";
            txtClass2.Text = "Class 2";
            txtClass3.Text = "Class 3";
            txtClass4.Text = "Class 4";
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            txtTest1.Text = "0";
            txtTest2.Text = "0";
            txtTest3.Text = "0";
            txtTest4.Text = "0";

        }


       private void button7_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ToolStripMenuItem1_Click(System.Object sender, System.EventArgs e)
        {
            StreamReader StreamToRead = null;
            StreamToRead = new StreamReader("C:\\vb10sbs\\GPA\\grades.txt");
            txtClass1.Text = StreamToRead.ReadLine();
            txtTest1.Text = StreamToRead.ReadLine();
            textBox1.Text = StreamToRead.ReadLine();
            txtClass2.Text = StreamToRead.ReadLine();
            txtTest2.Text = StreamToRead.ReadLine();
            textBox2.Text = StreamToRead.ReadLine();
            txtClass3.Text = StreamToRead.ReadLine();
            txtTest3.Text = StreamToRead.ReadLine();
            textBox3.Text = StreamToRead.ReadLine();
            txtClass4.Text = StreamToRead.ReadLine();
            txtTest4.Text = StreamToRead.ReadLine();
            textBox4.Text = StreamToRead.ReadLine();
            StreamToRead.Close();
        }

        private void ToolStripMenuItem2_Click(System.Object sender, System.EventArgs e)
        {
            StreamWriter StreamToWrite = null;
            StreamToWrite = new StreamWriter("C:\\vb10sbs\\GPA\\grades.txt");
            StreamToWrite.Write(txtClass1.Text + "\n" + txtTest1.Text + "\n" + textBox1.Text + "\n" +
                                txtClass2.Text + "\n" + txtTest2.Text + "\n" + textBox2.Text + "\n" +
                                txtClass3.Text + "\n" + txtTest3.Text + "\n" + textBox3.Text + "\n" +
                                txtClass4.Text + "\n" + txtTest4.Text + "\n" + textBox4.Text);
            StreamToWrite.Close();
        }


        private void ResetToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
        {
            button6.PerformClick();
        }

        private void ExitToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
        {
            button7.PerformClick();
        }

        private void Form1_FormClosing(System.Object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            StreamWriter StreamToWrite = null;
            StreamToWrite = new StreamWriter("C:\\vb10sbs\\GPA\\grades.txt");
            StreamToWrite.Write(txtClass1.Text + "\n" + txtTest1.Text + "\n" + textBox1.Text + "\n" +
                                txtClass2.Text + "\n" + txtTest2.Text + "\n" + textBox2.Text + "\n" +
                                txtClass3.Text + "\n" + txtTest3.Text + "\n" + textBox3.Text + "\n" +
                                txtClass4.Text + "\n" + txtTest4.Text + "\n" + textBox4.Text);
            StreamToWrite.Close();
        }


        private void Form1_Load(System.Object sender, System.EventArgs e)
        {
            StreamReader StreamToRead = null;
            StreamToRead = new StreamReader("C:\\vb10sbs\\GPA\\grades.txt");
            txtClass1.Text = StreamToRead.ReadLine();
            txtTest1.Text = StreamToRead.ReadLine();
            textBox1.Text = StreamToRead.ReadLine();
            txtClass2.Text = StreamToRead.ReadLine();
            txtTest2.Text = StreamToRead.ReadLine();
            textBox2.Text = StreamToRead.ReadLine();
            txtClass3.Text = StreamToRead.ReadLine();
            txtTest3.Text = StreamToRead.ReadLine();
            textBox3.Text = StreamToRead.ReadLine();
            txtClass4.Text = StreamToRead.ReadLine();
            txtTest4.Text = StreamToRead.ReadLine();
            textBox4.Text = StreamToRead.ReadLine();
            StreamToRead.Close();

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                textBox1.Text = "0";
            }
            if (string.IsNullOrEmpty(textBox2.Text))
            {
                textBox2.Text = "0";
            }
            if (string.IsNullOrEmpty(textBox3.Text))
            {
                textBox3.Text = "0";
            }
            if (string.IsNullOrEmpty(textBox4.Text))
            {
                textBox4.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest1.Text))
            {
                txtTest1.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest2.Text))
            {
                txtTest2.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest3.Text))
            {
                txtTest3.Text = "0";
            }
            if (string.IsNullOrEmpty(txtTest4.Text))
            {
                txtTest4.Text = "0";
            }


        }

    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.