0
目的是编写一个只有VB的代码,它将检查用户ID并查看它是否处于正确的格式。第一个字母应该是大写字母,下三个字母应该是小写字母,接下来的三个字母应该是数字。无论如何,我的程序都输出“格式不正确”。即使我输入正确的格式:程序没有给出所需的解决方案
Sub Main()
Dim userID As String
Dim a, b, c, d, e, f, g As Integer
Console.WriteLine("Input User ID")
userID = Console.ReadLine
'Take Hall123 as a example of a correct format
a = Asc(Left(userID, 1))
'First capital letter
b = Asc(Mid(userID, 2, 1))
'First lower case
c = Asc(Mid(userID, 3, 1))
'Second lower case
d = Asc(Mid(userID, 4, 1))
'Third lower case
e = Asc(Mid(userID, 5, 1))
'd contains the first number
f = Asc(Mid(userID, 6, 1))
'e contains the second number
g = Asc(Mid(userID, 7, 1))
'f contains the third number
'just checking
Console.WriteLine(a)
Console.WriteLine(b)
Console.WriteLine(c)
Console.WriteLine(d)
Console.WriteLine(e)
Console.WriteLine(f)
If Len(userID) = 7 Then
If a >= 65 And a <= 90 Then
If b >= 97 And b <= 122 And c >= 97 And c <= 122 And d >= 97 And d <= 122 Then
If e <= 57 And 48 >= e And f <= 57 And 48 >= f And g <= 57 And g >= 48 Then
Console.WriteLine("Format is correct")
Else
Console.WriteLine("Format is not correct")
End If
Else
Console.WriteLine("Format is not correct")
End If
Else
Console.WriteLine("Format is not correct")
End If
Else
Console.WriteLine("Format is not correct")
End If
Console.ReadKey()
End Sub
我是否正确使用Mid函数功能?我昨天才研究过它......
您是否检查了调试窗口以验证a,b,c,d,e,f和g是他们应该是什么? – TMH8885
我对正则表达式并不擅长,但对于正则表达式来说,这似乎是一个很好的例子。你有没有使用正则表达式的原因?找到文档[here](https://msdn.microsoft.com/en-us/library/hs600312(v = vs.110).aspx) –