编号按字母A-Z顺序递增,递增完一遍后号码自动升一位.
是否用可用数组来解决?

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
     Dim TestCode As String
     TestCode = "aa"
     MsgBox GetNextCode(TestCode)
    End SubPublic Function GetNextCode(str_Code As String) As String
       Dim str_len As Integer
       Dim tmp_len As Integer
       Dim str_chr As String
       str_len = Len(str_Code)
       If (str_len = 0) Then '如果是空 则自动为 a
            GetNextCode = "a"
            Exit Function
       End If
       tmp_len = str_len
       While (tmp_len)
           str_chr = Mid(str_Code, tmp_len, 1) '从后边取一个字符
           If str_chr < "z" Then    '判断是否小z
              str_chr = Chr(Asc(str_chr) + 1) '取下一个字符
              GetNextCode = Left(str_Code, tmp_len - 1) + str_chr + Right(str_Code, str_len - tmp_len) '组合最后结果 既替换这个值
              Exit Function
           End If
           tmp_len = tmp_len - 1
       Wend
       GetNextCode = str_Code + "a" '都是z的时候 在后边加a
    End Function
      

  2.   

    EXCEL的列符号吧
    Private Sub Command1_Click()
    Dim x()
    n = 100 '列数ReDim x(1 To n)
    For i = 1 To n
    k = Int((i - 1) / 26)
    j = i - 26 * k
    x(i) = IIf(k = 0, Chr(64 + j), Chr(64 + k) & Chr(64 + j))Print x(i), i
    If i Mod 10 = 0 Then MsgBox "": Cls
    NextEnd Sub
      

  3.   

    记得Excel只有254列,不要超过了
      

  4.   

    整数转任意进制(比如3进制、4进制都可以),可以任意序列表达的函数。Private Sub Command1_Click()
      Dim tString As String
      Dim tValue As Long
      Text1.Text = ""
      'tString = BitStringGetByValue(26, , 26)
      'Text1.Text = Fix(1)
      For tValue = 0 To 100
        tString = BitStringGetByValue(tValue, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26)
        'tString = BitStringGetByValue(tValue, , 26)
        Text1.Text = Text1.Text & tValue & "=" & tString & vbCrLf
      Next
      
    End SubPrivate Sub Form_Load()End Sub
    Function BitStringGetByValue(ByVal pValue As Long, Optional ByVal pOutTableString As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", Optional ByVal pBound As Long = 10) As String
      Dim tOutString As String
      
      Dim tBytes() As Byte
      
      tBytes() = BitBytesGetByValue(pValue, pOutTableString, pBound)
      
      tOutString = StrConv(tBytes(), vbUnicode)
      
      BitStringGetByValue = tOutString
    End FunctionFunction BitBytesGetByValue(ByVal pValue As Long, Optional ByVal pOutTableString As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", Optional ByVal pBound As Long = 10) As Byte()
      Dim tOutBytes() As Byte
      
      Dim tOutBytes_Length As Long
      Dim tBound_Log As Double
      
      If CBool(pValue) Then
          tBound_Log = Log(pValue) / Log(pBound)
          tOutBytes_Length = Fix(tBound_Log)
        Else
          tOutBytes_Length = 0
      End If
      
      ReDim tOutBytes(tOutBytes_Length)
      
      Dim tOutBytes_Index As Long
      
      Dim tOutTable() As Byte
      
      tOutTable() = StrConv(pOutTableString, vbFromUnicode)
      
      Dim tBitValue As Long
      
      For tOutBytes_Index = 0 To tOutBytes_Length
        tBitValue = (pValue \ (pBound ^ tOutBytes_Index)) Mod pBound
        tOutBytes(tOutBytes_Length - tOutBytes_Index) = tOutTable(tBitValue)
      Next
       
      BitBytesGetByValue = tOutBytes()
    End Function