自动递增字母 [英] Auto Incrementing letters

查看:98
本文介绍了自动递增字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正忙于一个程序,在其中添加记录时,我需要在文本框中增加一个字母.请有人帮我增加字母,以前从未做过吗?

感谢

I am currently busy on a program in which when a record is added i need to increment a letter in a text box. Please could someone help me with incrementing letters , have never done it before?

thanks

推荐答案

尝试此代码
(为简单起见,假定输入字符串为大写)
Try this code
(for sake of simplicity it assumes the input string being uppercase)
Public Function Increment(ByVal s As String) As String
    Dim index As Integer = s.Length - 1
    Dim n As Integer
    While index > 0 And s.Chars(index) = "Z"
        index = index - 1
    End While

    Increment = ""
    For n = 0 To index - 1
        Increment = Increment + s.Chars(n)
    Next

    If index > 0 Then
        Increment = Increment + Microsoft.VisualBasic.ChrW(Microsoft.VisualBasic.AscW(s.Chars(index)) + 1)


        For n = index + 1 To s.Length - 1
            Increment = Increment + "A"
        Next
    Else
        Increment = "A" + s
    End If

End Function


Sub Main()
    Dim nxt As String
    nxt = Increment("ZZABZZ")
End Sub


感谢所有帮助
我找到了一个更简单的解决方案


昏暗的字母作为字符串="A"
字母= Chr(Asc(字母)+ 1)
Me.letter.Text =字母
Thanks for all the help
i have found an easier solution


Dim letter As String = "A"
letter = Chr(Asc(letter) + 1)
Me.letter.Text = letter



您需要将字母加载到数组中
Hi
You will need to load the the alphabet in an array
Dim letters(25) As String

letters(0) = "A"
letters(1) = "B"
letters(2) = "C"
letters(3) = "D"
letters(4) = "E"
etc.


然后,您将需要获取文本"框的内容.


Then You will need to grab the Text box''s contents.

Dim letterGrab As String

letterGrab = tbLetter.Text


现在获取字母索引
找到


Now get the letter''s index

Dim found As Boolean = False
Dim FoundIndex As Integer = 0
For i As Integer = 0 To 25

    If letters(i) = letterGrab Then
        found = True
        FoundIndex = i
        Exit For
    End If
Next


最终得到新的Letter并将其放在文本框中


Finally get the new Letter and put it in the text box

If found = True Then
    FoundIndex = FoundIndex + 1
    tbLetter.Text = letters(FoundIndex)
        
Else
'What to do if end of array reached
End If



如果需要不区分大小写的比较,请将代码块3更改为此:

找到



If you need case insensitive comparison, change code block 3 to this:

Dim found As Boolean = False
Dim FoundIndex As Integer = 0
For i As Integer = 0 To 25
Dim CaseDiff As Integer  = String.Compare(letters(i), letterGrab, True)

    If CaseDiff = 0 Then
        found = True
        FoundIndex = i
        Exit For
    End If
Next



希望对您有帮助
雅克



Hope This Helps
Jacques


这篇关于自动递增字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆