아래소스는 사용자가 주민번호를 입력할때 생일이 자동으로 입력되도록 해주라는 요구사항이였는데 아래와 같이 만들면 되겠다. 포커스를 이해하자.

Private Sub Jumin_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles mskJumin.LostFocus
    Dim strSex As String
    Dim strBirth As String

    strSex = Mid(mskJumin.CtlText, 8, 1)
    Select Case strSex
        Case "1", "3"
            cboSex.SelectedIndex = 1
        Case "2", "4"
            cboSex.SelectedIndex = 2
    End Select

    If mskJumin.CtlText <> "" Then '주민번호 자동생성
        mskBirth.CtlText = Format(Val("19" + MSVB.Left(mskJumin.CtlText, 6)), "####-##-##")
    End If
End Sub

+ Recent posts