Hello
Hope someone can help me with this.
I've been practising to build a basic windows app from O'reilly HeadFirst C# book and Im stuck. I have exactly the same code as the book wrote but I can't compile it due to error with words that has got red curly underline (Words underline below). These words does not exist in current context, how can I remove this? and where did I do wrong?
Here is the code;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Navigatorchapter3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string destination = textBox1.Text;
string route2StreetToAvoid = textBox2.Text;
string route3StreettoInclude = textBox3.Text;
Navigator navigator1 = new Navigator();
navigator1.SetDestination(destination);
int distance1 = navigator1.TotalDistance();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
Navigator navigator2 = new navigator();
navigator2.SetDestination(destination);
navigator2.ModifyToAvoid(route2StreetToAvoid);
int distance2 = navigator2.TotalDistance();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
Navigator navigator3 = new navigator();
navigator3.SetDestination(destination);
navigator3.ModifyRouteToInclude();
int distance3 = navigator3.TotalDistance(route3StreetToInclude);
int shortestDistance = Math.Min(distance1, Math.Min(distance2, distance3));
}
}
}
Thanks in advance
Wahyu
Red Curly Underline
Started by sangalaki, May 19 2010 06:45 AM
5 replies to this topic
#1
Posted 19 May 2010 - 06:45 AM
|
|
|
#2
Posted 19 May 2010 - 07:47 AM
Check out if O'Reilly's code has any using statement that you don't have. Do you have a class named Navigator in your project? If not, that's why it is underlined.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#3
Posted 19 May 2010 - 07:50 AM
Also, you declared a distance1 in an event, but you are using it in another, you can't do that.
private void stuff()
{
int myVariable = 5;
}
private void anotherStuff()
{
int result = myVariable + 2; //You CAN'T do this, myVariable has to be declared inside the same event, or outside
}
int myVariable; //Like this
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics
#4
Posted 19 May 2010 - 08:37 PM
i always advice members to post your code in the code tags.Read below to know how,
1.First you Paste some code.
2.Then highlight the code with your mouse.
3.In the HTML editor click the # button.
that's it.
1.First you Paste some code.
2.Then highlight the code with your mouse.
3.In the HTML editor click the # button.
that's it.
#5
Posted 20 May 2010 - 03:04 AM
Hi Davide,
I wrote this code according to the book, can you show me where I got it wrong in the code please? Thanks
I wrote this code according to the book, can you show me where I got it wrong in the code please? Thanks
#6
Posted 20 May 2010 - 04:26 AM
Hello sangalaki,
there must be something that you are missing there, it could be here:
Also, try to read further through the book, maybe you have to add that class right after writing this code. Keep on reading, if the book tells you to compile and you still got the curly underlines, there must be some other mistake.
there must be something that you are missing there, it could be here:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;Or, you forgot to add a class named "Navigator.cs" to your project.
Also, try to read further through the book, maybe you have to add that class right after writing this code. Keep on reading, if the book tells you to compile and you still got the curly underlines, there must be some other mistake.
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics


Sign In
Create Account

Back to top









