Results 1 to 15 of 15

Thread: VB conversion - whats going on?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    VB conversion - whats going on?

    OK so this is really doing my head in since I am using VB to convert to C# and the variable names don't help in addition to the whole zero counts as 1 in C#

    Code:
    Public Function Parsec(stmt As Variant, delim As String, stmtinx() As Long) As Long
        Dim i As Long
        Dim j As Long
        Dim k As Long
        Dim l As Long
        Dim m As Long
        k = UBound(stmtinx) - 2
        m = Len(delim)
        Erase stmtinx
        If (m < 1) Then Exit Function
        i = 1
        For l = 1 To k
            stmtinx(l) = i
            j = InStr(i, stmt, delim)
            If (j < 1) Then Exit For
            i = j + m
        Next
        stmtinx(l + 1) = Len(stmt) + 1
        stmtinx(0) = l
        Parsec = l
          
    End Function
    how do I convert this to C#? I mean...I think I got it but the problem is, when comparing the output between the C'# and VB, it always is out by 1 number (C# is 1 number ahead)
    whether or not this is correct when it comes to C# land - im not sure. I think it is.

    here is the data I use to put through the function:

    stmt = " | |08/16/2012 21:46:01|0799555065|*205505555555558|001029604658953|038800C8080801140010296046589533106507995550650 2C050000|310650799555065|08/08/2012 08:01:20||||xxx||||||||||||||||||||||||||||||||||||||||||||||"

    delim = "|"
    stmtinx is an array length of 96 in VB:

    Dim stmtinx(96) as long
    I hope someone can help me my brain is...frazzled

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: VB conversion - whats going on?

    I'm not even sure I can tell what it does.... it looks like it's looking for the delimiters... but it's not extracting the data... is it simply storing the position of each delimiter? Well that can't be right... the calculation of i doesn't look right.... perhaps rather than converting that code (which is VB6 anyways, and should be upgraded to VB.NET before converting to C#) ... you can explain what it's supposed to do... there maybe a more efficient way of going about it... right now, it looks a little jacked.... like I said, that calculation of i looks wonky.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: VB conversion - whats going on?

    yeh but it works. what is it doing? No idea. I can't wait to find out what it does but just have to DO IT you know?

    it works and has done for years..... literally. better way of doing it? Sure. but not enough time to test the new method either, so since this works - just "port it over"

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: VB conversion - whats going on?

    VB's string handling methods are 1-based, while other languages are 0-based.
    Try the following:
    Code:
    public long Parsec(string stmt, string delim, long[] stmtinx)
    {
    	long i = 0;
    	long j = 0;
    	long k = 0;
    	long l = 0;
    	long m = 0;
    	k = stmtinx.GetUpperBound(0) - 2;
    	m = delim.Length;
    	stmtinx = null;
    	if (m < 1)
    	{
    		return 0;
    	}
    	i = 1;
    	for (l = 1; l <= k; l++)
    	{
    		stmtinx[l] = i;
    		j = stmt.IndexOf(delim, i - 1) + 1;
    		if (j < 1)
    		{
    			break;
    		}
    		i = j + m;
    	}
    	stmtinx[l + 1] = stmt.Length + 1;
    	stmtinx[0] = l;
    	return l;
    }
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB conversion - whats going on?

    Quote Originally Posted by David Anton View Post
    VB's string handling methods are 1-based, while other languages are 0-based.
    vb.net's arrays are zero based. vb6 had optional lowerbounds

  6. #6
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: VB conversion - whats going on?

    Right - I was referring to the legacy string methods, such as "InStr", which is in the posted code.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB conversion - whats going on?

    Quote Originally Posted by Techno View Post
    MVP 2007-2010 any chance of a regain?
    not a hope in hell

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: VB conversion - whats going on?

    thanks. almost there. I had to new up the array buffer when you assigned it to null instead.

    we have 1 extra element in there.... (the last one probably)

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: VB conversion - whats going on?

    Quote Originally Posted by .paul. View Post
    not a hope in hell
    yeh I know.... but hey I work alot and too much for my brain to keep things in as im getting older. LOL

    but my day will come again. you just wait

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB conversion - whats going on?

    all those long variables... i,j,k,l,m... should be integers?

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB conversion - whats going on?

    Quote Originally Posted by Techno View Post
    yeh I know.... but hey I work alot and too much for my brain to keep things in as im getting older. LOL

    but my day will come again. you just wait
    ok. i've set my timer... i'm watching you

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB conversion - whats going on?

    Quote Originally Posted by Techno View Post
    yeh I know.... but hey I work alot and too much for my brain to keep things in as im getting older. LOL

    but my day will come again. you just wait
    ok. i've set my timer... i'm watching you

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: VB conversion - whats going on?

    p.s. i didn't post twice for emphasis

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: VB conversion - whats going on?

    ok so trying to get my brain to almost work. Regardless - the contents of the array must be the same in both VB and C# and using the same "input" data. yes... thats right.

    so thanks to david, almost there. But there appears to be 1 extra element in the array

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: VB conversion - whats going on?

    any luck at all?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width