Hi
Im using windows form applicaton
and try using a method that returns a value and have a parmeterlist input.

I try to creat a program that converts a number of kilobytes (KB) to byte. The program's user to specify the number of KiB and the program will print the same number of bytes.
For conversion of KB to change the program should call a separate method that you have defined. The method is via its parameter list to load KiB number, convert the number of KB to the corresponding value in bytes and return that value.

Any idea

Recommended Answers

What idea have you tried already? We would like to see it, so we can help you better.

Jump to Post

As I understand you well, the user inputs in a textbox a number of KB after clicking a button the program calculates the number of bytes and puts the result in another textbox. Correct?
If answer is yes, then in your calc method, you should multiply by 1024, instead of …

Jump to Post

All 6 Replies

What idea have you tried already? We would like to see it, so we can help you better.

Thanks Sir
Her is my solution but I got error,I hope you can help me.

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

        private void btnconverter_Click(object sender, EventArgs e)
        {
            int kib = 0 ;
             kib = Convert.ToInt32(txtKib.Text);
             txtResult.Text = Convert.ToString(calc(kib));



        }
        private int calc(int numberOfKib);
        {
            return  numberOfKib/1024
        }

As I understand you well, the user inputs in a textbox a number of KB after clicking a button the program calculates the number of bytes and puts the result in another textbox. Correct?
If answer is yes, then in your calc method, you should multiply by 1024, instead of dividing.

Yes you understan me very well
But I got those error?

Error 1 Invalid token '{' in class, struct, or interface member declaration

Error 2 Invalid token '1024' in class, struct, or interface member declaration

Remove the ; on line 17
Add a ; on line 19, after 1024

Thank you very much Sir its work now:)

Be a part of the DaniWeb community

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