Sunday, July 17, 2011

Reverse Function

    Some of the functions in the VB 6 (Visual Basic 6.0) are obsolete and do not exist in the VB.Net. So in this kind of situation, we are the one who must create a code to to perform the task of the certain function that are obsolete. That is why the VB.Net offers a feature in which we can create our own function. Below, we can is code to perform the reverse function:




---------------------------------------------------------------------------------------------------------------------------
Function reverse(Byval toreverse as String) as String
    Dim x as Integer
    If Len(toreverse) >0 then
    For x = 1 to Len(toreverse)
         reverse = Mid(toreverse,x,1) & reverse
    Next x
    End if
End Function
---------------------------------------------------------------------------------------------------------------------------
    This code shows how to reverse a string. Since we have to import a value to be reverse, we will put up a parameter. I declare "x" as Integer because i will use it as a counter for the loop. Then, we have first check if the value that is passed to the function is null so that we can determine if it still necessary to perform the function. Next, we need to use the loop so that we can manipulate every letter of a word to be reversed. I put the "reverse" after the "&" because it will get the first character of the word then it must be put to last so that it can be reversed.

No comments:

Post a Comment