Visual Basic 2010 For ..To Statment

时间:2017-10-24 09:08:43

标签: visual-studio-2010

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim password As String, ch As Char
    Dim i As Integer
    Dim valid As Boolean = False
    While valid = False
        password = InputBox("Please enter  your password")
        For i = 0 To password.Length - 1
            ch = password.Chars(i)
            If Not Char.IsLetterOrDigit(ch) Then
                valid = True
                Exit For
            End If
        Next
        If valid Then
            MsgBox("Your new password will be activated immediately")
        Else
            MsgBox("your password must contain at least one special symbol")
        End If
    End While
End Sub

大家好,这个程序将检查密码中是否有符号,我的问题在于(For i = 0 To password.Length - 1)其约(-1)为什么我们写-1,我理解除了这个之外的一切-1,谢谢

1 个答案:

答案 0 :(得分:0)

对,我明白了,你是对的。因为vb从0开始计数,所以如果我写1234这意味着对于vb 12345然后我们应该将最后一位数除去-1然后我们将1234作为结果。谢谢Hans Passant