By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,217 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

C#->VB Snippet Translation Help Needed

P: n/a
Hi.
I'm having trouble translating a routine to alter validation at the client
and the server.

A portion of the C# code is:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> namespace Test.WebControls
{

public class WebPage : System.Web.UI.Page
{
public WebPage()
{
validatorAssignments = new NameValueCollection();
}

private void Page_Load( object sender, System.EventArgs e )
{
if( this.validatorAssignments != null &&
this.validatorAssignments.HasKeys() )
{
StringBuilder sb = new StringBuilder();
sb.Append("<script>");
sb.Append(Environment.NewLine);
sb.Append("Page_ValidatorAssignments = true;");
sb.Append(Environment.NewLine);
for( int i = 0; i < this.validatorAssignments.Count; i++ )
{
if( this.validatorAssignments.Keys[i].ToString() != string.Empty &&
this.validatorAssignments[i].ToString() != string.Empty )
{
sb.AppendFormat(" var {0}Validators = new Array(",
this.validatorAssignments.Keys[i].ToString());
string[] keys = this.validatorAssignments[i].Split(",".ToCharArray());
for( int k = 0; k < keys.Length; k++ )
{
sb.AppendFormat("'document.all[\"{0}\"]'", keys[k].Trim()); ///This
Line has Problems

if( k != keys.Length - 1 )
sb.Append(",");
}
sb.Append(");");
sb.Append(Environment.NewLine);

}
}
sb.Append(Environment.NewLine);
sb.Append("</script>");
Page.RegisterClientScriptBlock("ValidatorAssignmen ts", sb.ToString());
}
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

The problem is with the line:
sb.AppendFormat("'document.all[\"{0}\"]'", keys[k].Trim());

The error reads "Overload resolution failed because no accessible
AppendFormat can be called with these arguments....."

Any help would be appreciated

My VB translation up to that line reads:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


If (Me.validatorAssignments Is Nothing) AndAlso
(Me.validatorAssignments.HasKeys() = True) Then

Dim sB As New StringBuilder

sB.Append("<script>")

sB.Append(Environment.NewLine)

sB.Append("Page_ValidatorAssignments = true;")

sB.Append(Environment.NewLine)

Dim i, j As Integer

For i = 0 To Me.validatorAssignments.Count - 1

If Me.validatorAssignments.Keys(i).ToString <> "" AndAlso
Me.validatorAssignments(i).ToString <> "" Then

sB.AppendFormat(" var {0}Validators = new Array(",
Me.validatorAssignments.Keys(i).ToString())

Dim keys As String() = Me.validatorAssignments(i).Split(",".ToCharArray() )

For j = 0 To keys.Length - 1

sb.AppendFormat("'document.all[\"{0}\"]'", keys(j).Trim())

Next

End If

Next

End If

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Phil,
\" (single quote) is in VBNet "" (double quote)

Therefore
"""This""" is "This"

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Thanks for saving my skin Cor,
I should remember that backslash escapes are strictly C language type
constructs.
I learned C from K&R and used it more in the past than VB,
so when I translate C# to VB I frequently think things look ok. I
remember now constructing sql queries in regular asp vbscript
and having to concatenate strings and escape the single quotes too.

I learned .Net in VB, so I started this project with it.
In the future I'm going to do everything in C# so I don't
get a headache ;-)

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.