0
 option explicit

dim r, res, num

num= cint(inputbox("Enter the number"))

  do while(num > 0)

 r= num mod 10

 num= num\10

res= res & r

loop

msgbox res

Well this is the code, now my question is this works perfectly fine for input 1234, well if the input is 0123 it just prints 321 which is wrong.It needs to print 3210. I am unable to figure out, tried a lot but in vain, any help would be appreciated Thanks and Regards

5 Answers 5

1

You must decide whether you want to reverse strings or numbers (accidentially represented as decimals). If you want to reverse strings, you should

  1. not convert the (string) input to a number/integer
  2. use string ops: Mid() for reading, concatenation & for building

Added: In (demo/not production) code:

Option Explicit

Function rev(s)
  Dim p
  For p = Len(s) To 1 Step -1
      rev = rev & Mid(s, p, 1)
  Next
End Function

Dim s
For Each s In Array("1234", "0123")
    WScript.Echo s, rev(s)
Next

output:

1234 4321
0123 3210
Sign up to request clarification or add additional context in comments.

2 Comments

Well what if the input is taken as num= "1234"
@Ekkehard.Horner: Well appreciate your help on this, is it not possible doing this without any functions/ built in functions what so ever.
1

String reverse program without using Reverse String function & Mid function.

str=inputbox("Enter the string: ")
str1=len(str)
a=Left(str,1)
for i=1 to str1
str2=Left(str,i)
if len(str2)>1 then
   str3=Right(str2,1)&temp
   temp=str3    
end if
next
msgbox temp&a

Comments

1

Try this:

Dim   num,   rev
num   =   inputbox("Enter a number")
If   Len(num)=4 Then
rev = rev*10 + num mod 10
num = num/10
num = left(num,3)
rev = rev*10 + num mod 10
num = num/10
num = left(num,2)
rev = rev*10 + num mod 10
num = num/10
num = left(num,1)
rev = rev*10 + num mod 10
msgbox "Reverse Order of the number is "&rev 
Else
msgbox "Number, you entered is not a 4 digit number"
End If

Comments

0

str = Inputbox("Enter the number")

rev=""

Set regx = New RegExp

regx.Global = True

regx.IgnoreCase = True

regx.Pattern = ".{1}"

Set colchars= regx.Execute(str)

For i = 0 To colchars.Count-1

rev= colchars.Item(i)&rev

Next

MsgBox rev

Comments

0
Public Function mno()
a = "Ram is a good boy"
length = Len(a)
b = Right(a, 1)
For i = 1 To length Step 1
c = Left(a, length - i)
d = Right(c, 1)
b = b & d
Next
Debug.Print a
Debug.Print b
End Function

1 Comment

You should add explanation.

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.