Solved

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

Posted on 2008-10-25
13
6,725 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
  • 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now