CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2002
    Location
    Israel
    Posts
    396

    Need help to convert this function from VB to VB.Net

    Hi
    I have this function that i need your help to convert it to work on VB.Net 2008 code:
    Code:
    Function BdikatTakinutMisparZeut(ByVal IDNumber As Object) As Integer        
            Dim SumAll As Byte, SumTemp As Byte, index As Byte
            Select Case True
                Case IsNothing(IDNumber) : BdikatTakinutMisparZeut = 1
                Case IDNumber = "" : BdikatTakinutMisparZeut = 2
                Case Not IsNumeric(IDNumber) : BdikatTakinutMisparZeut = 3
                Case Len(IDNumber) > 9 : BdikatTakinutMisparZeut = 4
                Case Else
                    IDNumber = String$(9 - Len(IDNumber), "0") & IDNumber
                    For index = 1 To 8
                        SumTemp = Mid(IDNumber, index, 1) * Mid("12121212", index, 1)
                        SumAll = SumAll + IIf(SumTemp < 10, SumTemp, 1 + Right(SumTemp, 1))
                    Next index
                    BdikatTakinutMisparZeut = Right(100 - SumAll, 1) = Right(IDNumber, 1)
            End Select   
        End Function
    Basically i need the help with this code String$ and Right
    Many thanks
    Last edited by leeshadmi; December 28th, 2010 at 07:44 AM. Reason: forgot something

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Need help to convert this function from VB to VB.Net

    There is a String property that includes .Index()

    What is the 12121212 in there for?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2002
    Location
    Israel
    Posts
    396

    Re: Need help to convert this function from VB to VB.Net

    Thanks but its not helping i need some one to translate the lines that contain String$ and the line that contain Right words since i just do not understnd it thats why i cant do it my self.

    Basically this function is for ID number validation.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Need help to convert this function from VB to VB.Net

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help to convert this function from VB to VB.Net

    This line

    Code:
    IDNumber = String$(9 - Len(IDNumber), "0") & IDNumber
    Could be written something like
    Code:
    IDNumber=Mid("000000000",1,9-Len(IDNumber)) & IDNumber
    You can also use mid() to replace the uses of right()
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Need help to convert this function from VB to VB.Net

    on the fly (you could find you have to fix something inside...)
    Code:
     Function BdikatTakinutMisparZeut(ByVal IDNumber As Object) As Integer
            Dim SumAll As Byte, SumTemp As Byte, index As Byte
    
            Select Case True
                Case IDNumber Is Nothing
                    BdikatTakinutMisparZeut = 1
                Case String.IsNullOrEmpty(IDNumber)
                    BdikatTakinutMisparZeut = 2
                Case Not IsNumeric(IDNumber)
                    BdikatTakinutMisparZeut = 3
                Case Len(IDNumber.ToString) > 9
                    BdikatTakinutMisparZeut = 4
                Case Else
                    IDNumber = New String("0"c, 9 - Len(IDNumber.ToString)) & IDNumber
                    For index = 1 To 8
                        SumTemp = Mid(IDNumber, index, 1) * Mid("12121212", index, 1)
                        SumAll = SumAll + IIf(SumTemp < 10, SumTemp, 1 + Integer.Parse(SumTemp.ToString.Substring(SumTemp.ToString.Length - 1, 1)))
                    Next index
                    Dim rsumAll As Integer = 100 - SumAll
    
                    BdikatTakinutMisparZeut = rsumAll.ToString.Substring(Len(rsumAll.ToString)-1,1)  = (IDNumber.ToString.Substring(Len(IDNumber.ToString)-1   , 1)
            End Select
        End Function
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured