473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#->VB Snippet Translation Help Needed

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
2 1178
Phil,
\" (single quote) is in VBNet "" (double quote)

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

I hope this helps,

Cor
Nov 21 '05 #2
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: ByteSize | last post by:
Dear All, Please, this is not meant to be offensive - but it is a challenge !!! I have posted on over a dozen so called 'vb.net' expert / blog sites - in the vain hope of finding a complete,...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
11
by: alcastle | last post by:
I'm new to C. I have a snippet of code that works, but it's a little off in the output. I'm hoping someone can spot my error(s). I'm reading input from a serial device, and I need to print Hex,...
25
by: Sharrukin Amiri | last post by:
Hello, I am using VB 6.0 for many years. Everytime I needed to build software applications, I just opened VB 6.0 and started coding. I am now looking VB.NET Express Edition and I find I can no...
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
14
by: John Smith | last post by:
Can someone convert from C# into VB this line for me: if (c is System.Web.UI.HtmlControls.HtmlForm)
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: Nolanclark | last post by:
Hi there. I've read a previous thread regarding the Old VB 6 checkbox array and how it's not really needed any more. That's fine, but I'm not really sure how to implement the checkbox control array...
4
by: EricW | last post by:
Hi, I found the following code in a FAQ about the datagridview. But I am having a hard time translating it to VB, so I would like to ask via here for someone more experienced to translate this...
1
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm getting a little confused here. I have a C# class that I'm trying to translate to VB. The C# class is essentially: public static class Class1 { ..... some private static variables and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.