Hey folks.

I'm tying to carry out a simply task of writing a variable double value to a label on my form. The label is called 'lblTotalSeats'. Here's my code below:

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;

namespace ABCDEFG
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
        }

        private void TotalSeats()
        {
            double totalSeats = 240;
            string numberOfSeats = totalSeats.ToString();
            lblTotalSeats.Text = numberOfSeats;
        }
    }
}

My code doesn't throw up any errors when I run it but the value of 240 doesn't display on my label 'lblTotalSeats'.

Any suggestions what I'm doing wrong? I've tried varying it so the method is called "private string TotalSeats(out numberOfSeats) but to no avail too.

I know it's quite simple but as a beginner and a new student to GUI programming, I'm struggling.

Thanks

You have to call that function somewhere in the program. I'll leave it up to you to figure that one out.

Thanks PseudoRandom. I knew it was something obvious. I'd moved the code for the TotalSeats method to the MainForm_Load method but knew that that was wrong. Your pointer has sorted out a problem I've been trying to tackle for over an hour!

Thank you

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;

namespace Assignment_3
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            TotalSeats();
        }

        private void TotalSeats()
        {
            double totalSeats = 240;
            string numberOfSeats = totalSeats.ToString();
            lblTotalSeats.Text = numberOfSeats;
        }
    }
}
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.