Question Locked

VB 6 covert to VB NET

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello,

I have the following line of code, but am not sure how to change it so that it works in VB NET. (It doesn't like the UCase(Right(strKey, 8) section. Appreciate any help. jay

If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then

5 replies

by neil.duncan

strKey.ToUpper().Substring(strKey.Length - 8, 8)

Does that do what you need?

by giadich

the string object has some built in methods you could use for this:

.ToUpper()
.EndsWith()

and you can also combine them like so:

strKey.ToUpper.EndsWith("BLAH BLAH")

by aikimark

If StrComp(strKey,".DEFAULT",vbCompareText)=0 Or StrComp(Right(strKey, 8),"_CLASSES",vbCompareText)=0 Then

============
You might also rewrite the second comparison as
strKey Like "*_CLASSES"

============
You can rewrite the If statement as
Select Case 0
Case StrComp(strKey, ".DEFAULT", vbCompareText) , StrComp(Right(strKey, 8), "_CLASSES", vbCompareText)

'Case Else 'optional equivalent to Else clause

End Select

by ayars

I would use the following code, making use of the OrElse to minimise processing.

If strKey.ToUpper = ".DEFAULT" OrElse strKey.ToUpper.EndsWith("_CLASSES") Then

This discussion is closed to new replies.