6 Replies - 874 Views - Last Post: 08 November 2010 - 02:03 PM Rate Topic: -----

#1 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,315
  • Joined: 12-January 10

I need help fixing 2 errors

Posted 07 November 2010 - 01:06 PM

Error 1:

Error 1 Method must have a return type BankingAccountUnit5X\Record.cs 26 17


shows up on ****** section


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BankingAccountUnit5X
{
    public class Record
    {
        public int AccountNumber {get;set;}
        public string Account { get; set; }

        public decimal Amount { get; set; }

        public string Type {get; set;}

        public decimal startingBalance{get;set;}

        public decimal Balance{get;set;}

        public Record()
            : this(0,string.Empty, 0M, string.Empty, 0M, 0M)
        {
        }

     *********  public  RecordSerializable(int accNumValue,string accountValue, decimal amountValue, string typeValue, decimal startValue, decimal balanceValue)
        {
            AccountNumber = accNumValue;
            Account = accountValue;
            Amount = amountValue;
            Type = typeValue;
            startingBalance = startValue;
            Balance = balanceValue;
        }

           
    }
}



Error 2:

Error 1 The type or namespace name 'Record' could not be found (are you missing a using directive or an assembly reference?) AccountReader\AccountReader\MainForm.cs 103 32 AccountReader


shows up in %%%%%%%%%%% section



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;
using System.IO;

namespace AccountReader
{
    public partial class MainForm : Form
    {

        private StreamReader fileReader;


        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void openFile_Click(object sender, EventArgs e)
        {
            DialogResult result;
            string filename;

            using (OpenFileDialog fileChooser = new OpenFileDialog())
            {
                result = fileChooser.ShowDialog();
                filename = fileChooser.FileName;
            }

            if (result == DialogResult.OK)
            {


                if (filename == string.Empty)
                    MessageBox.Show("Invlaid file name");
                else
                {
                    try
                    {
                        FileStream input = new FileStream(filename, FileMode.Open, FileAccess.Read);

                        fileReader = new StreamReader(input);

                    }
                    catch (IOException)
                    {
                        MessageBox.Show("Error reading file");
                    }
                }
            }
        

        }

        private void showRecordsBtn_Click(object sender, EventArgs e)
        {
            Func<string,bool> accountChooser;




            Button senderButton = (Button)sender;
            switch (senderButton.Text)
            {
                case "Savings Records":
                   
                    break;

                case "Checking Records":

                    break;
                    
                default:
                    break;

            }

            try
            {
                savingsRTXT.Text = "Savings accounts are:\n";
                var recordQuery =
                    from line in fileReader.Lines()
                    let record = line.Split(',') as string[]
                    where accountChooser(record[1])
          %%%%%%%%%%%%%%%%%%%    select new Record
                    {
                        AccountNumber = Convert.ToInt32(record[0]),
                        Account = record[1],
                        Amount = Convert.ToDecimal(record[2]),
                        Type = record[3],
                        startingBalance = Convert.ToDecimal(record[4]),
                        Balance = Convert.ToDecimal(record[5]),
                    };

                foreach (var typeRecord in recordQuery)
                {
                    savingsRTXT.AppendText(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\n", typeRecord.AccountNumber, typeRecord.Account, typeRecord.Amount,
                        typeRecord.Type, typeRecord.startingBalance, typeRecord.Balance));
                }
            }
            catch (IOException)
            {
                MessageBox.Show("Can't read file");
            }
        }


        

        private void checkingBtn_Click(object sender, EventArgs e)
        {

        }

        private void exitBtn_Click(object sender, EventArgs e)
        {
            fileReader.Close();
            Application.Exit();
        }//end show button
    }
}//end class Mainform

public static class StreamReaderExtensions
{

    public static IEnumerable<string> Lines(this StreamReader source)
    {
        if (source == null)
            throw new ArgumentNullException("StreamReader is null");

        source.BaseStream.Seek(0, SeekOrigin.Begin);

        string line;

        while ((line = source.ReadLine()) != null)
        {
            yield return line;
        }
    }
}




my main program

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;
using System.Collections;
using System.IO;


namespace BankingAccountUnit5X
{
    public partial class MainForm : Form
    {
        Account selectedAccount;
        Account selectedAccountChecking;
        Account selectedAccountSavings;
        ArrayList ar = new ArrayList();
        Account[] pAccounts = new Account[6];
        private List<Account> accounts = new List<Account>() { new SavingsAccount(200), new SavingsAccount(100), new SavingsAccount(100), new SavingsAccount(1), new CheckingAccount(100) };
        
        private string getItem;
        decimal bal;

        decimal transFee = 3.50M;
        decimal intRate;

        private StreamWriter filewriter;
        protected int inCount = 6;

        public MainForm()
        {
            InitializeComponent();
            fillCombo();
        }

        public enum textIndices
        {
            ACCOUNTNUMBER,
            ACCOUNT,
            AMOUNT,
            TYPE,
            STARTINGBALANCE,
            BALANCE
        }




        private void message()
        {
            MessageBox.Show("Please enter a deposit amount\n or pick an amount from the checking or savings boxes.\n Click savings or checking button.\n"  + "Then hit submit after you entered amounts.");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.accountTypeCBox.Items.Add("Checking");
            this.accountTypeCBox.Items.Add("Savings");
            this.accountTypeCBox.SelectedIndex = 0;
            this.TransTypeCBox.Items.Add("Credit");
            this.TransTypeCBox.Items.Add("Debit");
            this.TransTypeCBox.SelectedIndex = 0;
            this.amountTxt.Text = "0.00";

            message();




        }


        public string[] getValues()
        {
            string[] values = new string[inCount];
            values[(int)textIndices.ACCOUNTNUMBER] = accountNumberTXT.Text;
            values[(int) textIndices.ACCOUNT] = accountTypeCBox.Text;
            values[(int)textIndices.AMOUNT] = amountTxt.Text;
            values[(int)textIndices.TYPE] = TransTypeCBox.Text;
            values[(int)textIndices.STARTINGBALANCE] = startingBalanceTxt.Text;
            values[(int)textIndices.BALANCE] = balanceLbl.Text;

            return values;
        }


        private void fillCombo()
        {
            foreach (Account a in accounts)
            {
                if (a is SavingsAccount) this.savingsCB.Items.Add(a.GetBalance);
                else if (a is CheckingAccount) this.checkingCB.Items.Add(a.GetBalance);
            } //here, you check for the different types of account and add them to the combo box accordingly. The
            //same principle can be used for retrieving information
        }

        private void submitBtn_Click(object sender, EventArgs e)
        {
            string[] values = getValues();

            Record record = new Record();

            if(values[(int) textIndices.ACCOUNTNUMBER] != string.Empty)
            {
                try
                {
                    int accountNumber = Int32.Parse(values[(int)textIndices.ACCOUNTNUMBER]);

                    if (accountNumber > 0)
                    {
                        record.Account = values[(int)textIndices.ACCOUNT];
                        record.Amount = decimal.Parse(values[(int)textIndices.AMOUNT]);

                        record.Type = values[(int)textIndices.TYPE];
                        record.startingBalance = decimal.Parse(values[(int)textIndices.STARTINGBALANCE]);
                        record.Balance = decimal.Parse(values[(int)textIndices.BALANCE]);

                        filewriter.WriteLine(record.Account + "," + record.Amount + "," + record.Type = "," + record.startingBalance + "," + record.Balance);
                    }
                

                else
                {
                    MessageBox.Show("Invalide account");
                }
                }
                catch(IOException)
                {
                    MessageBox.Show("Error wrting to file");
                }
        }

            decimal newBalance = 0;

            switch (accountTypeCBox.Text)
            {
                case "Checking":
                    selectedAccount = selectedAccountChecking;
                    feeLbl.Text = transFee.ToString();
                    break;
                case "Savings":
                    selectedAccount = selectedAccountSavings;
                    break;
            }

            switch (TransTypeCBox.Text)
            {
                case "Credit":
                    newBalance = selectedAccount.Credit(decimal.Parse(amountTxt.Text));

                    break;
                case "Debit":
                    newBalance = selectedAccount.Debit(decimal.Parse(amountTxt.Text));
                    break;
            } // end switch


            balanceLbl.Text = newBalance.ToString();





        }

        private void createSavingsBtn_Click(object sender, EventArgs e)
        {


            intRate = 0.40M;
            bal = decimal.Parse(startingBalanceTxt.Text);
            try
            {
                if (bal == 0)
                {
                    selectedAccountSavings = new SavingsAccount(intRate);
                    balanceLbl.Text = bal.ToString();


                }
                else
                {
                    selectedAccountSavings = new SavingsAccount(bal, intRate);

                    balanceLbl.Text = bal.ToString();
                }
            }
            catch (FormatException fe)
            {
                MessageBox.Show("Must be numeric input ", fe.ToString());
            }
        }

        private void createCheckingBtn_Click(object sender, EventArgs e)
        {
            bal = decimal.Parse(startingBalanceTxt.Text);

            try
            {

                if (bal == 0)
                {
                    selectedAccountChecking = new CheckingAccount(transFee);
                    balanceLbl.Text = bal.ToString();

                }
                else
                {
                    selectedAccountChecking = new CheckingAccount(bal, transFee);

                    balanceLbl.Text = bal.ToString();


                }
            }
            catch (FormatException fe)
            {
                MessageBox.Show("Must be numeric input ", fe.ToString());
            }

        }



        private void savingsCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = savingsCB.SelectedIndex;
            Object selectedItem = savingsCB.SelectedItem;

            
            startingBalanceTxt.Text = selectedItem.ToString();
        }

        private void checkingCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = checkingCB.SelectedIndex;
            Object selectedItem = checkingCB.SelectedItem;

          
            startingBalanceTxt.Text = selectedItem.ToString();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
            DialogResult result;

            string fileName;

            using (SaveFileDialog filechooser = new SaveFileDialog())
            {
                filechooser.CheckFileExists = false;
                result = filechooser.ShowDialog();
                fileName = filechooser.FileName;
            }


            if (result == DialogResult.OK)
            {
                if (fileName == string.Empty)
                    MessageBox.Show("Invalide file name");
                else
                {
                    try
                    {
                        FileStream output = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);

                        filewriter = new StreamWriter(output);

                        saveBtn.Enabled = false;
                    }
                    catch (IOException)
                    {
                        MessageBox.Show("Error opening file");
                    }
                }
            }
        
        }

        private void exitBtn_Click(object sender, EventArgs e)//close stream writer
        {
            if (filewriter != null)
            {
                try
                {
                    filewriter.Close();
                }
                catch (IOException)
                {
                    MessageBox.Show("Can't close file");
                }
            }
            Application.Exit();
        }



    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: I need help fixing 2 errors

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: I need help fixing 2 errors

Posted 07 November 2010 - 01:16 PM

Quote

Error 1 Method must have a return type BankingAccountUnit5X

All methods must specify their return type, even if it is 'void'

Line 26
public void RecordSerializable


Your Record and main program are in entirely different namespaces. You have to qualify the use of Record or provide a reference to that namespace.


BankingAccountUnit5X.Record {blah blah}



I would assume you to know these very basic things if you wrote the rest of all this. So I guess you are piecing together bits from other people's projects and trying to make it all work together. Does that sound about right?
Was This Post Helpful? 3
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: I need help fixing 2 errors

Posted 07 November 2010 - 03:52 PM

We frown upon copy paster 'programmers' here. If you were smart enough to use try/catch blocks and using statements then not typing in a return type just doesn't make sense.

Learn how to program properly and don't just steal code from other people.
Was This Post Helpful? 1
  • +
  • -

#4 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,315
  • Joined: 12-January 10

Re: I need help fixing 2 errors

Posted 07 November 2010 - 04:21 PM

Actually I had written this prior and dumb ass me wrote it in a VB platform class so when I realized what I did -- I opened up another class and re-wrote it under C#-- I guess VS didn't understand that I was converting a VB to C# but thanks for clarifying something that is incorrect on your behalf.
So now that that is said-- any idea how to properly convert the VB class to my c#?

This is an assignment I have to do and just so you understand the assignment here it is:

part 1: modify your unit 5 project to write a sequential file

Part 2: create a second application executable called accountreader that will allow you to open data in files stored from unit 5.

as you can see it is telling me I have to write an entirely new program thus the namespace would be different.


Unless you know the entire story I suggest you don't criticize people's efforts.

This post has been edited by DarenR: 07 November 2010 - 04:28 PM

Was This Post Helpful? -2
  • +
  • -

#5 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: I need help fixing 2 errors

Posted 07 November 2010 - 04:35 PM

Two people now think the same thing, I'm sure many other people do as well. Next time post a more complete question.
Was This Post Helpful? 3
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: I need help fixing 2 errors

Posted 08 November 2010 - 07:55 AM

Quote

So now that that is said-- any idea how to properly convert the VB class to my c#?
Why do you think you did it 'improperly'? You converted a class from one language to another with only two basic over sights. With those two oversights corrected, does your program work? If it works then you did it properly.

Quote

Unless you know the entire story I suggest you don't criticize people's efforts.
Unless you tell people the whole story, how would they know it? Understand that 1,000 posts a day hit this board from lazy people asking "Plz gives me d' code 2 do xyz" and "I told x from this site, and y from that site and when I put them together it don't work: Please fix it for me". Frankly: Without a deeper explanation your question really did look just like these.

I'm assuming you -1 Sergio's comments (twice) suggesting you post a better explanation if you don't want people thinking negatively towards your work ethics. It was advice. I think throwing a -1 at him for it was a bit of a 'backlash' behavior and rather uncalled for. That type of "I'll show you" reaction will only make everyone here hesitant to help you. Nobody here is going to risk their hard-earned reputation points for someone that does something so childish. I have +1 his rep on this to offset your -1.
Was This Post Helpful? 1
  • +
  • -

#7 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,315
  • Joined: 12-January 10

Re: I need help fixing 2 errors

Posted 08 November 2010 - 02:03 PM

The reason I gave him a -1 was not what you think it was for. Not only did he not help at all in my simple question but then he went on and insulted the way I introduced the question and did it 2 times at that. If you have nothing to say that would help in answering the question whether you like the way it is asked or not, then simply don't answer. Answering the way he did with no relevant insight as to how to solve the problem to me shows a lack of respect for people learning to program and a self proclaimed "god" like attitude. tlhIn'tog your answer actually helped me when I realized I typed 2 different names as in my namespace and my constructor. That was a long day for me and I was seeing double basically so yes I don't like it when people interject their opinions or irrelevancy on subjects without any useful information. You all have to remember that you started somewhere to and also needed help.
Was This Post Helpful? -3
  • +
  • -

Page 1 of 1