1

I am trying to convert the c# project into vb.net project. But i am not able to convert some code in vb.net.

C# Code:

if ((a >= 33) && (a <= 48)) { word += "|"; word1 += "|"; }

Vb.net Code:

If (Char.GetNumericValue(a) >= 33) AndAlso (Char.GetNumericValue(a) <= 48) Then
    word += "|"
    word1 += "|"
End If

Here in c# the numeric value of a is directly compared with integer value. But in Vb.net i can't get the numeric value of a to compare with the ASCII value. If there is any possible to convert the c# project solution into vb.net solution? Let me know the solution. Thanks in advance.

4
  • Have you tried to use Asc(a)? Commented Apr 9, 2018 at 6:32
  • That should be Convert.ToInt32. If you read the documentation for Char.GetNumericValue it should be obvious why that is not what you want. Commented Apr 9, 2018 at 6:37
  • @SamvelPetrosov Yeah I tested using Asc(a) also. While using this Asc(a) am getting the value as same integer value for all character Commented Apr 9, 2018 at 6:56
  • @jmcilhinney Now it works by using Convert.ToInt32. Thank you. Commented Apr 9, 2018 at 7:05

2 Answers 2

1

you can convert a character value into its ASC value and then compare it with a value in vb.net find sample code as below

Dim a As Char
a = "a"
Dim i As Integer = Asc(a)
Console.Write(i.ToString())
If i < 90 Then
    'Do what you want
End If
Sign up to request clarification or add additional context in comments.

Comments

1

You should be using the VB 'AscW' function (not 'Asc'), assuming that 'a' is a char:

If (AscW(a) >= 33) AndAlso (AscW(a) <= 48) Then
    word &= "|"
    word1 &= "|"
End If

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.