VB Program - To Reverse the n Digit Number entered by a user
Program :
Here n= 5,this can be modified in the below code.
Sub ReverseNumber()
Dim varNum
Dim varRev
Dim varRev
varNum = InputBox("Please Enter a number")
If Len(varNum) <> 5 Then
MsgBox varNum + " is not a 5 digit number"
Else
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 4)
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 3)
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 2)
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 1)
varRev = varRev * 10 + varNum Mod 10
MsgBox "Reverse Order of the entered number is " & varRev
End If
MsgBox varNum + " is not a 5 digit number"
Else
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 4)
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 3)
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 2)
varRev = varRev * 10 + varNum Mod 10
varNum = varNum / 10
varNum = Left(varNum, 1)
varRev = varRev * 10 + varNum Mod 10
MsgBox "Reverse Order of the entered number is " & varRev
End If
End Sub
No comments:
Post a Comment