compiler error msg..

M

maya

am following "asp.NET Unleashed", by Stephen Walther (a SAMS book..
covers .net 1.1 though..)

on one of his examples (ch 2) am getting compilation error.. code:

<script Runat="Server">
void ChangeBox1( object s, EventArgs e ) {
txtBox1 = StrReverse( txtBox1 );
CheckWin();
}
void ChangeBox3( object s, EventArgs e ) {
txtBox3 = StrReverse( txtBox3 );
CheckWin();
}
void CheckWin() {
if ( txtBox1 == "Apple" && txtBox2 == "Apple" && txtBox3 == "Apple" )
lblMessage = "You Win!";
}
public string StrReverse(string strString) {
char[] strArray = strString.ToCharArray();
Array.Reverse(strArray);
return new String(strArray);
}
</script>
<html>
<body>
<form Runat="Server">
Enter the word Apple into all three TextBoxes:<br><br>
<asp:TextBox ID="txtBox1" AutoPostBack="True"
OnTextChanged="ChangeBox3" Runat="Server"/>
<asp:TextBox ID="txtBox2" AutoPostBack="True"
OnTextChanged="ChangeBox1" Runat="Server"/>
<asp:TextBox ID="txtBox3" AutoPostBack="True"
OnTextChanged="ChangeBox3" Runat="Server"/>
<asp:Label ID="lblMessage" Runat="Server" />
</form>
</body>
</html>


error:

Compiler Error Message: CS1502: The best overloaded method match for
'ASP.Game_aspx.StrReverse(string)' has some invalid arguments

Source Error:

Line 2: <script Runat="Server">
Line 3: void ChangeBox1( object s, EventArgs e ) {
Line 4: txtBox1 = StrReverse( txtBox1 );
Line 5: CheckWin();
Line 6: }


I know StrReverse is a method that exists already in FCL
(http://msdn2.microsoft.com/en-us/library/8ycf85wx.aspx), and
"overloaded" error probably has to do with this (I renamed StrReverse
method, but got same error.. in Java you never give a method you
declare a name of a method that exists already in API..(??) )

also in StrReverse method decl. I noticed 'string' is in lower case, is
this right? in Java it would be

public string StrReverse(String strString)" (upper case 'string'..)
(did try changing it to uppercase, got same compilation error..)

would appreciate suggestions/enlightenment.. many thanks..
 
R

Roger

Hi maya,
I think your error is that you should be using
the .Text property (a String) of the TextBox
(txtBox1). And pass that to StrReverse.
Roger
 
M

maya

thank you Roger.. ok, this is what I did now:

<script Runat="Server">
void ChangeBox1( object s, EventArgs e ) {
string one = txtBox1.Text;
StrReverse( one );
CheckWin();
}
void ChangeBox3( object s, EventArgs e ) {
string three = txtBox3.Text;
StrReverse( three );
CheckWin();
}
void CheckWin() {
if ( one == "Apple" && txtBox2.Text == "Apple" && three == "Apple" )
lblMessage = "You Win!";
}
public string StrReverse(string strString) {
char[] strArray = strString.ToCharArray();
Array.Reverse(strArray);
return new String(strArray);
}

but still get error:

Compiler Error Message: CS0103: The name 'one' does not exist in the
class or namespace 'ASP.Game_aspx'

Source Error:
Line 13: void CheckWin() {
Line 14: if ( one == "Apple" && txtBox2.Text == "Apple" && three ==
"Apple" )
Line 15: lblMessage = "You Win!";

and now am getting this error:

Cannot implicitly convert type 'string' to
'System.Web.UI.WebControls.Label'

don't get this.. do you have to put word 'string' when you declare a
string or not? took out word 'string' from string declarations, and now
get this error:

The name 'one' does not exist in the class or namespace 'ASP.gameA_aspx'

thank you...
 
R

Roger

Compiler Error Message: CS0103: The name 'one' >does not exist in the

This is because it is defined as a local variable,
widen it's scope.
<script Runat="Server">
void ChangeBox1( object s, EventArgs e ) {
string one = txtBox1.Text;
StrReverse( one );
CheckWin();


if ( one == "Apple" && txtBox2.Text == "Apple" && three == "Apple" )
lblMessage = "You Win!";
}
public string StrReverse(string strString) {
char[] strArray = strString.ToCharArray();
Array.Reverse(strArray);
return new String(strArray);
}

but still get error:

class or namespace 'ASP.Game_aspx'

Source Error:
Line 13: void CheckWin() {
Line 14: if ( one == "Apple" && txtBox2.Text == "Apple" && three ==
"Apple" )
Line 15: lblMessage = "You Win!";

and now am getting this error:

Cannot implicitly convert type 'string' to
'System.Web.UI.WebControls.Label'

don't get this.. do you have to put word 'string' when you declare a
string or not? took out word 'string' from string declarations, and now
get this error:

The name 'one' does not exist in the class or namespace 'ASP.gameA_aspx'

thank you...


Hi maya,
I think your error is that you should be using
the .Text property (a String) of the TextBox
(txtBox1). And pass that to StrReverse.
Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top