Solved

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

Posted on 2008-10-25
13
6,874 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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