-
Spot the mistake
I getting a compilation error for the following code but i can't find any problems with it at all - maybe a new set of eyes might spot it.
Code:
<%@ Page Language="C#" %>
<%@ import Namespace="Google_Web_APIs_Demo.Google" %>
<script runat="server">
string APIKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
public void Page_Load( Object sender, EventArgs e ) {
}
private void searchButton_Click( Object sender, EventArgs e ) {
private string URL;
private int Rank;
private int indexer;
private Table resultsTable;
private TableRow resultRow;
private TableHeaderCell headerCell;
private TableCell resultCell;
Info.Text = String.Empty;
if ( keywordBox.Text != String.Empty && keywordBox.Text != "Enter keywords" && domainBox.Text != String.Empty && domainBox.Text != "Enter Domain Name" ) {
keywordBox.Visible = false;
domainBox.Visible = false;
searchButton.Visible = false;
resultsTable = new Table();
resultsTable.GridLines = GridLines.None;
resultsTable.CellSpacing = 0;
resultsTable.CellPadding = 4;
resultRow = new TableRow();
headerCell = new TableHeaderCell();
headerCell.style = "font-family: Verdana; font-size: 10px; font-weight: bold;";
headerCell.Text = "Keyword";
resultRow.Cells.Add( headerCell );
headerCell = new TableHeaderCell();
headerCell.style = "font-family: Verdana; font-size: 10px; font-weight: bold;";
headerCell.Text = "URL found";
resultRow.Cells.Add( headerCell );
headerCell = new TableHeaderCell();
headerCell.style = "font-family: Verdana; font-size: 10px; font-weight: bold;";
headerCell.Text = "Position in top 10";
resultRow.Cells.Add( headerCell );
resultsTable.Rows.Add( resultRow );
string[] keywordArray = keywordBox.Text.Split('\n');
GoogleSearchService s = new GoogleSearchService();
foreach (string keyword in keywordArray) {
Rank = 0;
URL = String.Empty;
try {
GoogleSearchResult r = s.doGoogleSearch( APIKey, keyword.Trim(), 0, 10, true, "", false, "", "", "" );
indexer = 1;
foreach (ResultElement resultRecord in r.resultElements) {
if ( resultRecord.URL.IndexOf(domainBox.Text) != -1 ) {
Rank = indexer;
URL = resultRecord.URL;
break;
}
indexer += 1;
}
if ( Rank != 0 ) {
resultRow = new TableRow();
resultCell = new TableCell();
resultCell.style = "font-family: Verdana; font-size: 10px;";
resultCell.Text = keyword;
resultRow.Cells.Add( resultCell );
resultCell = new TableCell();
resultCell.style = "font-family: Verdana; font-size: 10px;";
resultCell.Text = URL;
resultRow.Cells.Add( resultCell );
resultCell = new TableCell();
resultCell.style = "font-family: Verdana; font-size: 10px;";
resultCell.Text = Rank;
resultRow.Cells.Add( resultCell );
resultsTable.Rows.Add( resultRow );
} else {
resultRow = new TableRow();
resultCell = new TableCell();
resultCell.style = "font-family: Verdana; font-size: 10px;";
resultCell.Text = keyword;
resultRow.Cells.Add( resultCell );
resultCell = new TableCell();
resultCell.style = "font-family: Verdana; font-size: 10px;";
resultCell.Text = "URL not found";
resultRow.Cells.Add( resultCell );
resultCell = new TableCell();
resultCell.style = "font-family: Verdana; font-size: 10px;";
resultCell.Text = "Outside top 10";
resultRow.Cells.Add( resultCell );
resultsTable.Rows.Add( resultRow );
}
}
catch (System.Web.Services.Protocols.SoapException ex) {
Info.Text += "Error: " + ex.Message;
}
}
if ( keywordArray.Length > 0 ) {
Results.Controls.Add( resultsTable );
}
} else {
if ( keywordBox.Text == String.Empty || keywordBox.Text == "Enter keywords" ) {
Info.Text = "Enter some keywords";
} else {
Info.Text = "Enter a domain name";
}
}
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:TextBox Runat="Server" id="domainBox" Text="Enter Domain Name" />
<asp:Button Runat="Server" id="searchButton" onClick="searchButton_Click" Text="Search" /><br />
<asp:TextBox Runat="Server" id="keywordBox" TextMode="MultiLine" Rows="10" Text="Enter keywords" />
<br />
<asp:Label Runat="Server" id="Info" Text="" /><br />
<asp:Panel Runat="Server" id="Results" />
</form>
</body>
</html>
The error I'm getting is:
Compiler Error Message: CS1513: } expected
Source Error:
Line 9: }
Line 10:
Line 11: private void searchButton_Click( Object sender, EventArgs e ) {
Line 12: private string URL;
Line 13: private int Rank;
Any ideas?
Cheers
DJ
-
You shouldn't use access specifiers in local function definitions.
public, protected, private should only be used for declarations with class scope.
Just remove private from the searchButton_Click variable declarations:
Code:
string URL;
int Rank;
int indexer;
// ...etc...
-
Excellent thanks wey97!
DJ