Solved

Conversion question

Posted on 2011-02-28
8
382 Views
Last Modified: 2012-08-13
Hi,
I have a following cod in VB and I am trying to convert it to C#... Thanks!

  WhereClause = " where " & Strings.Mid(WhereClause, 6)

  WhereClause = " where " + WhereClause.Substring(5, WhereClause.Length);

I am getting the following error for C# part:
ArgumentOutOfRangeException was unhandled by user code
Index and length must refer to a location within the string.
Parameter name: length
0
Comment
Question by:avi7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Assisted Solution

by:sshah254
sshah254 earned 25 total points
ID: 35003874
shouldn't it be whereclause.length - 5?

Ss
0
 

Author Comment

by:avi7
ID: 35003888
I am getting this:
Error Operator '-' cannot be applied to operands of type 'string' and 'int'
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 25 total points
ID: 35003915
shouldn't you be using:

WhereClause = " where " + WhereClause.Substring(5, WhereClause.Length - 5);

AW
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 35003917
Paste your Sample code here
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35004067
You can just do:

    WhereClause = " where " & WhereClause.Substring(5)

*But this assumes that WhereClause has at least six characters in it.

To be safe:

    if (WhereClause.Length >= 6)
    {
        WhereClause = " where " & WhereClause.Substring(5)
    }
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 35004070
*I forgot the semicolons ";" on the ends of the lines though!

    if (WhereClause.Length >= 6)
    {
        WhereClause = " where " & WhereClause.Substring(5);
    }
0
 

Author Comment

by:avi7
ID: 35004082
Thanks, let me try this...
0
 

Author Closing Comment

by:avi7
ID: 35040263
Thanks! It is working :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question