Hello, I know that I asked it already but I saw an article which answered my problem. I have only one problem left.
When a the KEYWORD is ended up by Z it always replace by this }
The CSharp code is doing Fine
But the problem arise when I'm using VB Code
Here is the code
CS
public string NxtKeyCode(string KeyCode)
{
byte[] ASCIIValues = ASCIIEncoding.ASCII.GetBytes(KeyCode) ;
int StringLength = ASCIIValues.Length ;
bool isAllZed = true;
bool isAllNine = true;
//Check if all has ZZZ.... then do nothing just return empty string.
for(int i =0; i < StringLength-1; i++)
{
if(ASCIIValues[i] != 90)
{
isAllZed = false;
break;
}
}
if(isAllZed && ASCIIValues[StringLength-1] == 57)
{
ASCIIValues[StringLength-1] = 64;
}
// Check if all has 999... then make it A0
for(int i =0; i < StringLength; i++)
{
if(ASCIIValues[i] != 57)
{
isAllNine = false;
break;
}
}
if(isAllNine)
{
ASCIIValues[StringLength-1] = 47;
ASCIIValues[0] = 65;
for(int i =1; i < StringLength-1; i++)
{
ASCIIValues[i] = 48;
}
}
for(int i = StringLength; i>0; i--)
{
if(i-StringLength == 0)
{
ASCIIValues[i-1] +=1;
}
if(ASCIIValues[i-1] == 58)
{
ASCIIValues[i-1] = 48;
if(i-2 ==-1)
{
break;
}
ASCIIValues[i-2] += 1;
}
else if(ASCIIValues[i-1] == 91)
{
ASCIIValues[i-1] = 65;
if(i-2 ==-1)
{
break;
}
ASCIIValues[i-2] += 1;
}
else
{
break;
}
}
KeyCode = ASCIIEncoding.ASCII.GetString(ASCIIValues);
return KeyCode;
}
VB.Net
Public Shared Function NxtKeyCode(KeyCode As String) As String
Dim ASCIIValues As Byte() = ASCIIEncoding.ASCII.GetBytes(KeyCode)
Dim StringLength As Integer = ASCIIValues.Length
Dim isAllZed As Boolean = True
Dim isAllNine As Boolean = True
'Check if all has ZZZ.... then do nothing just return empty string.
For i As Integer = 0 To StringLength - 2
If ASCIIValues(i) <> 90 Then
isAllZed = False
Exit For
End If
Next
If isAllZed AndAlso ASCIIValues(StringLength - 1) = 57 Then
ASCIIValues(StringLength - 1) = 64
End If
' Check if all has 999... then make it A0
For i As Integer = 0 To StringLength - 1
If ASCIIValues(i) <> 57 Then
isAllNine = False
Exit For
End If
Next
If isAllNine Then
ASCIIValues(StringLength - 1) = 47
ASCIIValues(0) = 65
For i As Integer = 1 To StringLength - 2
ASCIIValues(i) = 48
Next
End If
For i As Integer = StringLength To 1 Step -1
If i - StringLength = 0 Then
ASCIIValues(i - 1) += 1
End If
If ASCIIValues(i - 1) = 58 Then
ASCIIValues(i - 1) = 48
If i - 2 = -1 Then
Exit For
End If
ASCIIValues(i - 2) += 1
ElseIf ASCIIValues(i - 1) = 91 Then
ASCIIValues(i - 1) = 65
If i - 2 = -1 Then
Exit For
End If
ASCIIValues(i - 2) += 1
Else
Exit For
End If
Next
KeyCode = ASCIIEncoding.ASCII.GetString(ASCIIValues)
Return KeyCode
End Function
I only need the VB.Net Code. I hope you will help me thanks