www.whkt.net > vB反序代码

vB反序代码

Private Sub Command1_Click() Dim i As Integer, n As Integer Dim a() As Integer n = InputBox("请输入数的个数") ReDim a(n) For i = 1 To n a(i) = InputBox("请输入第" & i & "个数") Print a(i) Next i Sub sort(a() As Integer, n As Integer)

Private Sub Command1_Click() Label2.Caption = StrReverse(Text1.Text) End Sub

Private Sub Command1_Click()Dim str As StringDim iTextLen As IntegerDim outStr As Stringstr = Text1.TextiTextLen = Len(Text1.Text)If iTextLen < 1 Then Exit SuboutStr = ""Dim i As IntegerFor i = iTextLen To 1 Step -1outStr = outStr & Mid(str, i, 1)Next iText1.Text = outStrEnd Sub

swap这个子过程的作用是把数组a的头尾项依次对调来达到反向排序的目的的,即:a(1) a(10)a(2) a(9)a(3) a(8)a(4) a(7)a(5) a(6)以上过程完成后,数组a的顺序就被反过来了.m=b(i)b(i)=b(n-i+1)b(n-i+1)=m这三行就是完成每两个数的对调的,比如当i=1,n=10时,n-i+1 = 10-1+1 = 10所以m=b(i)=b(1)b(1)=b(n-i+1)=b(10)b(10)=m=b(1)这样b(1)和b(10)的值就对换过来了.其他亦同

如果要用函数可以直接使用StrReverse(Str) 如果要自己写代码实现,可以写成如下的语句:for i=1 to len(str) c=mid(str,i,1) str2=c+str2 '这里的+也可以换成 & next i print str2 'str2中就是str字符串的逆序

Private Function NiXuShu(ByVal l As String) As Long Dim i As Integer, j As Integer, c As Long Dim n() As Integer ReDim n(Len(l)) For i = 1 To Len(l) n(i) = Val(Mid(l, i, 1)) For j = 1 To i - 1 If n(i) c = c + 1 End If Next j Next i NiXuShu = c End Function 这个子函数就是求逆序数的,不止是三位654123的逆序数是5+4+3+0+0+0=12 望采纳..

MsgBox "反序数:" & StrReverse(InputBox("请输入一个三位数"))

ss = Chr(KeyAscii) + ss这个的意思,是把新输入的字符放在ss的前面,然后再赋值给ss,这样的话,每次新添加的字符都是放在最前面的,那它的顺序不就会反过来了吗?如果是下面这样,那就是顺序不变:ss = ss + Chr(KeyAscii)现在理解了没?

界面设计需要你自己做,代码如下:Private Sub Command1_Click()MsgBox StrReverse(Text1.Text)End SubPrivate Sub Command2_Click()Text1.Text = ""Text1.SetFocusEnd SubPrivate Sub Command3_Click()Unload MeEnd SubPrivate Sub Form_Load()Text1.Text = Int(Rnd * 900) + 100End Sub

dim b as string for i=len("ABCD") to 1 step -1 b=b+mid("ABCD",i,1) next i

友情链接:ntxp.net | zmqs.net | kcjf.net | gpfd.net | 9647.net | 网站地图

All rights reserved Powered by www.whkt.net

copyright ©right 2010-2021。
www.whkt.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com