在VB中怎样将A—Z转换成0-26?

来源:百度知道 编辑:UC知道 时间:2024/06/12 17:53:06
在VB中怎样将A—Z转换成0-26?代码怎么写?

num=asc("A")-96

就可以了,但是只能转换大写字母,大小写字母通用的:
str="a"
num=asc(ucase(str))-96

楼上的那么麻烦干嘛。
dim R as string,i as integer
R="F"'这里是你要转换的字母
select case R
case "A" to "Z"
i=asc(R)-ASC("A")
case "a" to "z"
i=asc(R)-ASC("a")
end select
print i
多简单!

Option Explicit

Private Sub Command1_Click()
Print Asc(InputBox("请输入大写字符")) - 65
End Sub

或者:

Option Explicit

Private Sub Command1_Click()
Dim i As Integer
For i = 0 To 25
Print Chr(i + 65) & "--------" & i '英文字符好像A-Z 是26个
Next
End Sub

看看哪个是你要的

'函数
Function GetNumber(Zfc As String) As String
Dim i As Integer, S As String
S = UCase(Zfc)
If S >= "A" And S <= "Z" Then
GetNumber = Asc(S) - 65
E