zoukankan      html  css  js  c++  java
  • vb中字母排列组合输出函数

    Option Explicit
    
    Private Sub Command1_Click()
        Dim Num, I, J, Temp, Len1 As Long
        Dim FileNO As Long
        Dim Count As Long
        Dim str, strTemp, strArr() As String, Arr() As String
        '********************************************************************
        str = InputBox("请输入字符串,数字或者字母组成:", "提示")
        
        If str = "" Then Exit Sub
        
        '===by gary20130208
        'Len1 = Len(str): ReDim strArr(Len1)
        strArr() = Split(str, " ")
        Len1 = UBound(strArr) + 1
        
    '    For I = 1 To Len1
    '        strArr(I - 1) = Mid(str, I, 1)
    '    Next
        '===
        
        '********************************************************************
        Count = 1
        For I = 2 To Len1
            Count = Count * I
        Next
        ReDim Arr(Count)
        '*********************************************************************
        Randomize
        For I = 0 To Count - 1
            '******************************************
    Lab2:   strTemp = ""
            Num = 0
            Do While Num < Len1
    Lab1:       Temp = Int(Rnd * Len1)
                If InStr(strTemp, CStr(Temp)) Then GoTo Lab1
                strTemp = strTemp & Temp
                Num = Num + 1
            Loop
            '******************************************
            For J = 0 To UBound(Arr)
                If Arr(J) = strTemp Then GoTo Lab2
            Next
            Arr(I) = strTemp
        Next
        '**********************************************************************
        FileNO = FreeFile
        Open "e:\字符组合.txt" For Output As #FileNO
        '**************************
        For I = 0 To Count - 1
            strTemp = ""
            For J = 1 To Len1
                strTemp = strTemp & strArr(CLng(Mid(Arr(I), J, 1))) & ","
            Next
            Print #FileNO, Left(strTemp, Len(strTemp) - 1)
        Next
        '**************************
        Close #FileNO
    End Sub

    这是网上找到的一段代码(vb 6.0版本),原来是算单个字符有多少种组合。我在这基础上做了下修改。

    比如:A B C D E ,这样就总共有120种组合字符,然后输出到文本文件。

  • 相关阅读:
    核心思想:台积电目前的硬体核心技术/制造人力估计不到1,000人
    忽然懂了:云就是互联网
    Qt https 用户认证authenticationRequired()
    TDD和BDD
    MEF实现设计上的“松耦合”
    跨域调用webapi
    复杂度
    react
    Angularjs里面跨作用域
    Spring.NET程序
  • 原文地址:https://www.cnblogs.com/garyxiao/p/2909280.html
Copyright © 2011-2022 走看看