[b][red]This message was edited by lionb at 2005-12-8 13:11:31[/red][/b][hr] : Is there a syntax that reverses things? : Example: 123 int 321 : There is always some syntax around ... if you willing to think a little bit ;-) [code] Private Sub Command1_Click() Dim i As Integer Dim sOld As String, sReverse As String
sOld = "123"
For i = Len(sOld) To 0 Step -1 If i > 0 Then sReverse = sReverse & Mid(sOld, i, 1) End If Next Text1 = sReverse End Sub [/code]
: [b][red]This message was edited by lionb at 2005-12-8 13:11:31[/red][/b][hr] : : Is there a syntax that reverses things? : : Example: 123 int 321 : : : There is always some syntax around ... if you willing to think a little bit ;-) : [code] : Private Sub Command1_Click() : Dim i As Integer : Dim sOld As String, sReverse As String : : sOld = "123" : : For i = Len(sOld) To 0 Step -1 : If i > 0 Then : sReverse = sReverse & Mid(sOld, i, 1) : End If : Next : Text1 = sReverse : End Sub : [/code] : : :
This one works much faster: [Code] Private Function Mod_sReverse(ByRef sOriginal As String) As String
Dim lIndex As Long Dim lLen As Long Dim sReverse As String
lLen = Len(sOriginal) '''Preallocate string sReverse = sOriginal For lIndex = 1 To lLen '''move each character Mid$(sReverse, (lLen - lIndex + 1), 1) = Mid(sOriginal, lIndex, 1) Next lIndex Mod_sReverse = sReverse End Function [/Code] Mike
: : How faster? : : : : Like : : [code] : Dim sString As String : Dim sReverse As String : : sString = "123" : sReverse = StrReverse(sString) : [/code] : : Much faster... Or atleast for VB6 and VB.NET : : Best Regards, : Richard : Thanks! I did know that StrReverse() was existed in vb6. Learn every day!
Comments
: Example: 123 int 321
:
Hi!
I'll give u the C code. U change it to VB.
void main()
{
int n = 12345,rev = 0,num = 0;
while(n>0)
{
num = n % 10;
rev = rev*10 + num;
n = n/10;
}
printf("%d",rev);
}
U can pass any value instead of "n"
: Is there a syntax that reverses things?
: Example: 123 int 321
:
There is always some syntax around ... if you willing to think a little bit ;-)
[code]
Private Sub Command1_Click()
Dim i As Integer
Dim sOld As String, sReverse As String
sOld = "123"
For i = Len(sOld) To 0 Step -1
If i > 0 Then
sReverse = sReverse & Mid(sOld, i, 1)
End If
Next
Text1 = sReverse
End Sub
[/code]
: : Is there a syntax that reverses things?
: : Example: 123 int 321
: :
: There is always some syntax around ... if you willing to think a little bit ;-)
: [code]
: Private Sub Command1_Click()
: Dim i As Integer
: Dim sOld As String, sReverse As String
:
: sOld = "123"
:
: For i = Len(sOld) To 0 Step -1
: If i > 0 Then
: sReverse = sReverse & Mid(sOld, i, 1)
: End If
: Next
: Text1 = sReverse
: End Sub
: [/code]
:
:
:
This one works much faster:
[Code]
Private Function Mod_sReverse(ByRef sOriginal As String) As String
Dim lIndex As Long
Dim lLen As Long
Dim sReverse As String
lLen = Len(sOriginal)
'''Preallocate string
sReverse = sOriginal
For lIndex = 1 To lLen
'''move each character
Mid$(sReverse, (lLen - lIndex + 1), 1) = Mid(sOriginal, lIndex, 1)
Next lIndex
Mod_sReverse = sReverse
End Function
[/Code]
Mike
:
Like
[code]
Dim sString As String
Dim sReverse As String
sString = "123"
sReverse = StrReverse(sString)
[/code]
Much faster... Or atleast for VB6 and VB.NET
Best Regards,
Richard
: :
:
: Like
:
: [code]
: Dim sString As String
: Dim sReverse As String
:
: sString = "123"
: sReverse = StrReverse(sString)
: [/code]
:
: Much faster... Or atleast for VB6 and VB.NET
:
: Best Regards,
: Richard
:
Thanks! I did know that StrReverse() was existed in vb6. Learn every day!