Solved

ERROR: The name 'textbox1' does not exist in the current context

Posted on 2008-10-25
13
6,824 Views
Last Modified: 2013-12-17
I ma trying this simple  program in Visual Studio 2005, however I get this error...here is my code:

public static void main(String[] args)
        {
            int txtbox1;
            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = "world";
            for (int i = 0; i < 3; i++)
                textbox1.Text = w.ToString();
        }
0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 3

Accepted Solution

by:
TechSinger earned 150 total points
ID: 22805370
Your line inside the loop is - textbox1.Text = w.ToString();

Are you sure you don't want to line to be - textbox1.Text = w[i];

Since an element of w is already a string, it shouldn't need to be converted to one.
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 200 total points
ID: 22805403
try tht
public static void main(String[] args)
        {
            string txtbox1;
            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = "world";
            for (int i = 0; i < 3; i++)
                textbox1= w.ToString();
        }
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 200 total points
ID: 22805410
public static void main(String[] args)
        {
            string txtbox1;
            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = "world";
            for (int i = 0; i < 3; i++)
                textbox1+= w[i].ToString();
        }
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 3

Assisted Solution

by:TechSinger
TechSinger earned 150 total points
ID: 22806131
I didn't notice the line - int txtbox1; in your code.  I was just assuming that txtbox1 was the name of a Text control you had on a form.  The fact that you were trying to change the value of the .Text property brought me to that conclusion.

Is txtbox1 the name of a control you have?  If so, you don't need the line - int txtbox1;, because adding it your your form already gives it a definition.
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 100 total points
ID: 22806146
'textbox1' is not defined anywhere in the static function Main
you have defined  int txtbox1; the variables are different

can we try to know what you are trying to do here so that we can help you better
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 200 total points
ID: 22806901
yes ragi0017  even i mixed up the two textbox1  and  txtbox1
0
 
LVL 3

Assisted Solution

by:TechSinger
TechSinger earned 150 total points
ID: 22807693
Yep, I guess I got them mixed up too.  I still the whole problem is that you are trying to convert a String array to a String, but you are using a loop, which would indicate you are trying to show each element.  I would make the following small modification, as I mentioned in my first comment.

        {
            int txtbox1;
            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = "world";
            for (int i = 0; i < 3; i++)
                textbox1.Text = w[i];
        }

Open in new window

0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 200 total points
ID: 22807727
TechSinger  i guess purpose of loop might be  
textbox1.Text += w[i];
so textbox1.Text will be like  "Hello , world"

0
 
LVL 4

Assisted Solution

by:inox
inox earned 50 total points
ID: 22808377
it seems you have three to four problems in your code:
Your question: the textbox (if it is a textbox control which indeed has a Text property) is most likely named Textbox1 not textbox1.
Textboxcontrols are placed on a Windows-Form or on a Web-Form but:
Webforms don't have a main function.
If it is a Windows-Foms program, the code should be in the Forms code.
int txtbox1isn't used at all,
w[3]  is indexed out of range,
w.ToString(); is generally possible but likely does not return what you expect.
what was intended?
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 22818574
I tried the snippet of code provided it still thru me any error:

Error      1      An object reference is required for the nonstatic field, method, or property
Error      2      Cannot convert type 'string' to 'System.Windows.Forms.TextBox'      
Error      3      Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'      C:\Visual Studio 2005 10-08\WindowsApplication1\Form1.cs      34      28      WindowsApplication1

public static void main(String[] args)
        {
            string txtbox1;
            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = "world";
            for (int i = 0; i < 3; i++)
                textBox1+= w[i].ToString();
        }



I tried the following but an error:
Class, struct, or interface method must have a return type

Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

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

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

        public static main(String[] args)
        {
           
            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = "world";
            for (int i = 0; i < 3; i++)
                return textBox1 = w[i].ToString;
               
        }
    }



}


On the form there is a textbox called: textBox1
There is a button called: button1

The goal is to write a simple program that will print out hello, world through an array
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 100 total points
ID: 22818866
you cannot access class non static members/variables from a static method
best way will be to do that from the button click event

move your code from main to button click

            string[] w = new string[3];
            w[0] = "Hello";
            w[1] = ",";
            w[3] = " world";
            for (int i = 0; i < 3; i++)
                return textBox1.Text += w[i].ToString;
0
 
LVL 10

Author Closing Comment

by:GlobaLevel
ID: 31510017
Thanks!
0
 

Expert Comment

by:HottTheMoople
ID: 36013654
I had this error "The name 'textBoxFind' does not exist in the current context" was caused because I inadvertently toggled textBoxFind.GenerateMember to false in the Properties wind in VS at some point.  Switched it back to true.  Hope that helps anyone else looking at similar error.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question