Subject: Chaper 6: Try It Out question
Posted By: ericzimma Post Date: 8/30/2006 3:16:59 PM
I can't figure question 7 in the Try It Out "Creating Dynamic Buttons." The question reads: "Edit the Add Person Click event handler in the main form code to set the AddMode property to TRUE."

Any ideas?

EZ
Reply By: Steve LeMaster Reply Date: 8/30/2006 9:20:30 PM
The project in the book does not function correctly. Nor does the downloadable version from this site. You are right at the chapter where everything goes awry.

I have been going back and forth, via email, about this and so far have been unsuccessful.

Private Sub btnAddPerson_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPerson.Click
        objPersonalDetails = New PersonalDetails
        Dim objPerson As New Person("Glenda", "Brown")
        With objPerson
            .BirthDate = "1965-12-02"
            .Address = "333 Green Valley Way, Los Angeles, CA"
            .HomePhone = "(811) 8888 7777"
        End With
        objPersonalDetails.Person = objPerson
        Me.Text = "Personal Organizer - Viewing " + _
        objPersonalDetails.Person.DisplayName
        objPersonalDetails.AddMode = True

        If pnlMain.Controls.Contains(objPersonList) Then
            pnlMain.Controls.Remove(objPersonList)
            objPersonList = Nothing
        End If

        pnlMain.Controls.Add(objPersonalDetails)
        objPersonalDetails.Dock = DockStyle.Fill


Don't forget this in PersonalDetails.vb, though:

Public Class PersonalDetails
    Private mPerson As Person
    Private mAddMode As Boolean

    Public Property AddMode() As Boolean
        Get
            Return mAddMode
        End Get
        Set(ByVal value As Boolean)
            mAddMode = value
            If mAddMode = True Then
                SetUpButtons()
            Else
                RemoveButtons()
            End If
        End Set
    End Property


Reply By: ericzimma Reply Date: 8/31/2006 12:09:14 PM
Thank you very much Steve.
I guess I shouldn't bother to finish this project.

EZ
Reply By: Steve LeMaster Reply Date: 8/31/2006 12:41:56 PM
Well, I wouldn't say forget it; you may very well get it to compile correctly.

Unfortunately, I, as well as others, can't get it to compile like advertised. At the very least it may be worth trying to figure out why it doesn't work and post it here.

Reply By: krecco Reply Date: 5/14/2007 8:02:36 AM
Try cahanging position of the buttons in the PersonalDetails.vb -  Private Sub SetUpButtons() :

        With mSaveButton
            .Name = "btnSave"
            .Text = "Shrani"
            .Anchor = AnchorStyles.Bottom + AnchorStyles.Right
            .Top = Me.Height - (.Height + 30) //was +5
            .Left = Me.Width - (.Width + 100) // was +5
        End With

 mCancleButton:

            .Top = Me.Height - (.Height + 30)
            .Left = Me.Width - (.Width + 200)



Reply By: MisterH Reply Date: 3/25/2008 5:32:40 AM
One error I found was with the code below;

Private Sub btnAddPerson_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddPerson.Click
        objPersonalDetails = New PersonalDetails
        Dim objPerson As New Person("Glenda", "Brown")
        With objPerson
            .BirthDate = "1965-12-02"
            .Address = "333 Green Valley Way, Los Angeles, CA"
            .HomePhone = "(811) 8888 7777"
        End With

The error concerns assigning the birth date and the line should read;
            .BirthDate = CType("1965-12-02", Date)

Just about to tackle the AddMode section so I will see how it goes.

Reply By: MisterH Reply Date: 3/26/2008 6:37:14 AM
Had all sorts of problems getting the AddMode to work.  In the end I copied in the code from the downloads and corrected the known errors, adjusted the txtNotes height and now it all seems to work.   Haven't managed to find why my manual entry wouldn't work   ...it appeared to be the same.


Go to topic 70075

Return to index page 2
Return to index page 1