Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 109083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:00:49+00:00 2026-05-11T02:00:49+00:00

HI, I am trying to convert the following vba code to c# and i

  • 0

HI,

I am trying to convert the following vba code to c# and i am facing some errors.Hope someone can help me

vba code

    Open 'C:\testfile.txt' For Input As #1         varii = ''         Do While Not EOF(1)         Line Input #1, strField         varii = varii & ',' & strField         Loop         Close #1         astrFields = Split(varii, ',')      For intIx = 1 To UBound(astrFields)     counter = 0     i = i + 1      Dim cn As New ADODB.Connection, cn2 As New ADODB.Connection     Dim rs As ADODB.Recordset     Dim connString As String     Dim SelectFieldName     Set cn = CurrentProject.Connection     SelectFieldName = astrFields(intIx)     Set rs = cn.OpenSchema(adSchemaColumns, _     Array(Empty, Empty, Empty, SelectFieldName))          If Left(rs!Table_Name, 4) <> 'MSys' And Left(rs!Table_Name, 4) <> 'Abfr     ' Then  strSql = 'SELECT t.[' & astrFields(intIx) & '], t.fall from [' & rs!Tab     le_Name & '] t Inner Join 01UMWELT on t.fall = [01UMWELT].fall '             End If     Set rs3 = CurrentDb.OpenRecordset(strSql)     Do While Not rs3.EOF     With rs3     feedbackmsg = 'Processing ' & rs!Table_Name & ' Record no : '     & .Fields(1)     SysCmd acSysCmdSetStatus, feedbackmsg     varii = Nz(.Fields(astrFields(intIx)), 'NullValue')     If varii = 'NullValue' Then     Call .Edit     .Fields(astrFields(intIx)) = 888     Call .Update 

THis is the c# code so far i have coded

FileInfo theSourceFile = new FileInfo('C:\\csharp\\testfile.txt');             StreamReader reader = theSourceFile.OpenText();             varii = '';              do             {                 text = reader.ReadLine();                 varii = varii + ',' + reader.ReadLine();                 //Console.WriteLine(text);               } while (text != null);                string[] split = varii.Split(new Char[] {' '});              foreach (string s in split)             {                  if (s.Trim() != '')                     Console.WriteLine(s);             }                       int temp = split.GetUpperBound(1);                     for (intix = 1; intix <= temp; intix++)                     {                         counter = 0;                          i++;                         ADODB.Connection cn = new ADODB.Connection();                         ADODB.Connection cn2 = new ADODB.Connection();                         ADODB.Recordset rs;                         object selectfieldname;                          //ConnectionClass conDatabase = new ADODB.Connection();                          cn.ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;' +                                               'Data Source='C:\\csharp\\accident_database.mdb';';                          rs = cn.OpenSchema(ADODB.SchemaEnum.adSchemaTables, Missing.Value, Missing.Value);                           if (Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'MSys' && +                             Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'Abfr')                         {                             strsql = 'SELECT t.[' + split(intix) + '],t.fall from [' + rs.Fields('Table_Name').Value + ']' +                                     't Inner join 01umwelt on t.fall = [01umwelt].fall';                          }                         rs3 = CurrentDB.OpenRecordset(strsql);                          while (!rs3.EOF)                         {                              feedbackmsg = 'Processing' + rs.Fields('Table_Name').Value + 'Record no:' + rs3.Fields(1).Value;                             SysCmd acSysCmdSetStatus, feecbackmsg;                             varii = Nz(rs3.Fields(astrfields(intix)).Value, 'NullValue');                              if (varii == 'NullValue')                             {                                 rs3.Edit();                                 rs3.Fields[astrfields(intix)].Value = 888;                                 rs3.Update(); 

I am recieving errors in the if statement

if (Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'MSys' && +             Microsoft.Vbe.Left(rs.Fields('Table_Name').Value, 4) != 'Abfr') 

here Vbe.left is not getting accepted

and secondly in the sql statement following this i get an error split is an variablebut used like method.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:00:49+00:00Added an answer on May 11, 2026 at 2:00 am

    In converting bear in mind that VBA uses the same operator () for indexes and method calls, whereas C# uses [] for indexes and () for calls to methods.

    split(intix) 

    should be

    split[intix] 

    Try

    rs.Fields('Table_Name').Value.ToString().Substring(0,4), but check the length first.   ie  rs.Fields('Table_Name').Value.ToString().Length >= 4 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert the following python code to a PHP code. Can
Trying to convert the following but am having difficulty. Can anyone see where I'm
I am trying to convert the following code from Trefethen's Spectral Methods in MATLAB
I'm trying to convert the following list into a select list so it can
I was just trying to convert a PPT using the following URL http://code.google.com/p/qifei/wiki/PDFConverter python
I'm trying to convert the following scriptlet code to EL. I tried the following
I am trying to convert the following code to work with jquery: var req
I'm trying to convert the following code snippet from PHP to C# or VB.NET
I am trying to convert the following code into a Ternary Operator, but it
I was trying to convert the following c# code to vb.net. I see the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.