Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
reverse syntax Posted by chuckw1 on 7 Dec 2005 at 6:54 PM
Is there a syntax that reverses things?
Example: 123 int 321
Report
Re: reverse syntax Posted by grarun on 8 Dec 2005 at 10:16 AM
: Is there a syntax that reverses things?
: Example: 123 int 321
:

<grarun>

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"


</grarun>
Report
Re: reverse syntax Posted by lionb on 8 Dec 2005 at 11:12 AM
This message was edited by lionb at 2005-12-8 13:11:31

: 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
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



Report
Re: reverse syntax Posted by Mike_AB1 on 9 Dec 2005 at 2:38 PM
: This message was edited by lionb at 2005-12-8 13:11:31

: : 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
:
: 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
: 

:
:
:

This one works much faster:
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

Mike
Report
Re: reverse syntax Posted by lionb on 12 Dec 2005 at 10:30 AM
How faster?
Report
Re: reverse syntax Posted by BitByBit_Thor on 12 Dec 2005 at 1:27 PM
: How faster?
:

Like

Dim sString As String
Dim sReverse As String

sString = "123"
sReverse = StrReverse(sString)


Much faster... Or atleast for VB6 and VB.NET

Best Regards,
Richard

Report
Re: reverse syntax Posted by lionb on 12 Dec 2005 at 1:59 PM
: : How faster?
: :
:
: Like
:
:
: Dim sString As String
: Dim sReverse As String
: 
: sString = "123"
: sReverse = StrReverse(sString)
: 

:
: 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!
Report
Re: reverse syntax Posted by chuckw1 on 13 Dec 2005 at 2:50 PM
Thanks I thought there was something like Thor wrote but I wasn't for sure.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.