collapse collapse

* Who's Online

  • Dot Guests: 261
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: Issue with GUI with OutputLabel and OKButton  (Read 3541 times)

0 Members and 1 Guest are viewing this topic.

Offline topazfae

  • Newbie
  • *
  • Posts: 16
  • Reputation 22
    • View Profile
Issue with GUI with OutputLabel and OKButton
« on: June 27, 2012, 11:15:57 pm »
I am not sure what this error means.  the last two lines are affected -            

OKButton.Visible = false;
OutputLabel.Text = "The smallest is " + smallest " and the largest is " + largest + ".";

Error = Error   1   An object reference is required for the non-static field, method, or property 'SmallestLargestGUI.SmallestLargest.OKButton'   C:\Users\Owner\Documents\South University\ITS 2105\SmallestLargestGUI\Form1.cs   41   13   SmallestLargestGUI

Code: C++
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace SmallestLargestGUI
  11. {
  12.     public partial class SmallestLargest : Form
  13.     {
  14.         public SmallestLargest()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         int[] entries = new int[10];
  20.         int x = 0;
  21.         private void OKButton_Click(object sender, EventArgs e)
  22.         {
  23.             entries[ x] = Convert.ToInt32(InputValues.Text);
  24.             InputValues.Text = "";
  25.             ++x;
  26.             if (x == entries.Length)
  27.                 SmallLarge(entries);
  28.         }
  29.         public static void SmallLarge(int[] entries)
  30.         {
  31.             int largest = entries[0];
  32.             int smallest = entries[0];
  33.  
  34.             for (int x = 0; x < entries.Length; ++x)
  35.             {
  36.                 if (smallest > entries[ x])
  37.                     smallest = entries[ x];
  38.                 if (largest < entries[ x])
  39.                     largest = entries[ x];
  40.             }
  41.             OKButton.Visible = false;
  42.             OutputLabel.Text = "The smallest is " + smallest " and the largest is " + largest + ".";
  43.         }
  44.     }
  45. }
  46. [/code=cpp]
  47.  
« Last Edit: June 29, 2012, 07:29:46 am by Celestialkey »

Offline Nathan

  • Administrator
  • Hero Member
  • *
  • Posts: 1437
  • Reputation 1768
  • Gender: Male
  • woof woof
    • View Profile
Re: Issue with GUI with OutputLabel and OKButton
« Reply #1 on: June 28, 2012, 09:47:01 pm »
It might help by posting a zip of the entire project.
Projects:
[ Axios Engine ] [ sourcehub ]
Compilers: Microsoft Visual Studio 2008, GNU C++, FASM, MASM, VB 6/.Net.
Languages: C++, PHP, ASM, JS, VB6/.Net, BASIC, HTML, MySQL
Please buy me some books: Amazon Wishlist

Offline powerfear

  • - Secret Permissions Level 1 -
  • Jr. Member
  • **
  • Posts: 58
  • Reputation 64
  • Gender: Male
    • View Profile
Re: Issue with GUI with OutputLabel and OKButton
« Reply #2 on: June 30, 2012, 11:13:51 am »
OKButton and OuputLabel are not static while the function you are using: public static void SmallLarge(int[] entries) is static.

A static function can not access members that are not static. So make that function not static and it will work. public void SmallLarge(int[] entries)



Offline Shishka

  • - Secret Permissions Level 1 -
  • Full Member
  • ***
  • Posts: 175
  • Reputation 218
  • Gender: Male
    • View Profile
Re: Issue with GUI with OutputLabel and OKButton
« Reply #3 on: June 30, 2012, 03:14:49 pm »
Ah good catch fear, can't believe I missed that.  :(
"Everything will be gone long before me. When the first living thing was born, I was here, waiting. When the last living thing dies, my job is finished. I'll put the chairs on the tables, turn out the lights and lock the universe behind me when I leave."

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]