不改變結果,我有以下代碼:功能基於參數
Imports System.Web.Security
Public Class Form1
Dim symbols As Integer = 0
Private Sub cbSymbols_CheckedChanged(sender As Object, e As EventArgs) Handles cbSymbols.CheckedChanged
If cbSymbols.CheckState = 1 Then
symbols = 1
ElseIf cbSymbols.CheckState = 0 Then
symbols = 0
End If
End Sub
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
Dim password As String = Membership.GeneratePassword(ComboBox1.SelectedIndex + 6, symbols)
Label1.Text = password
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Font = New Font("Arial", 14)
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
End Sub
End Class
然而,不管我的複選框(cbSymbols)被選中,我的密碼有1個符號,同時選中,和2個符號取消選中。任何人都可以幫助我診斷這個問題和/或改善我的代碼嗎?謝謝。
有ypou設置斷點INT'btn_Generate_Click',看是否symbols'的'值是否正確? – Koen
[根據MSDN](http://msdn.microsoft.com/zh-cn/library/system.web.security.membership.generatepassword.aspx)第二個參數僅指定*最少*符號數。你是否期望它強加一個*最大值*而不是? –
@RogerRowland的確我是,任何想法如何做到這一點? – SCGB