-
December 28th, 2010, 07:43 AM
#1
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
-
December 28th, 2010, 11:44 AM
#2
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?
-
December 28th, 2010, 02:04 PM
#3
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.
-
December 28th, 2010, 06:00 PM
#4
Re: Need help to convert this function from VB to VB.Net
-
December 29th, 2010, 11:04 PM
#5
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.
-
January 8th, 2011, 09:57 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|