?
Solved

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

Posted on 2008-10-25
13
Medium Priority
?
6,927 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 600 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 800 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 800 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
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

 
LVL 3

Assisted Solution

by:TechSinger
TechSinger earned 600 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 400 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 800 total points
ID: 22806901
yes ragi0017  even i mixed up the two textbox1  and  txtbox1
0
 
LVL 3

Assisted Solution

by:TechSinger
TechSinger earned 600 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 800 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 200 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 400 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

762 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