Results 1 to 6 of 6
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Learning VB 6 (VB6)

    I am *trying* to teach myself VB6. The following is the code for an exercise in a VB 5 book. You *should end up with a form that has three checkboxes on the left, and three radio buttons on the right., with a text display box below. The checkboxes display Sound, Mouse, and Colors status, On or Off in the text box.

    These work as represented.

    The three radio buttons are *supposed* to displaty either "Level1" "Level2" or "Level3". The etxt only displays intermittently, and not (I don't think) where it should.

    Can anybody help me here?

    Regards,
    Chuck Billow

    With high hope for the future, no prediction is ventured.
    -- Abraham Lincoln

    *****************************

    Private Sub Check1_Click()
    End Sub
    Private Sub Check2_Click()

    End Sub
    Private Sub Check3_Click()

    End Sub
    Private Sub Option1_Click()

    End Sub
    Private Sub Option2_Click()

    End Sub
    Private Sub Option3_Click()

    End Sub
    Private Sub chkColors_Click()
    UpdateLabel
    End Sub
    Private Sub chkMouse_Click()
    UpdateLabel
    End Sub
    Private Sub chkSound_Click()
    UpdateLabel
    End Sub
    Private Sub chkLevel1_Click()
    UpdateLabel
    End Sub
    Private Sub chkLevel2_Click()
    UpdateLabel
    End Sub
    Private Sub chkLevel3_Click()
    UpdateLabel
    End Sub

    Option Explicit
    Private Sub cmdExit_Click()
    End
    End Sub
    Public Sub UpdateLabel()
    ' Declare the Variables
    Dim Info
    Dim LFCR

    LFCR = Chr(13) + Chr(10)

    ' Sound
    If chkSound.Value = 1 Then
    Info = "Sound: On"
    Else
    Info = "Sound: Off"
    End If

    ' Mouse
    If chkMouse.Value = 1 Then
    Info = Info + LFCR + "Mouse: On"
    Else
    Info = Info + LFCR + "Mouse: Off"
    End If

    ' Colors
    If chkColors.Value = 1 Then
    Info = Info + LFCR + "Colors: On"
    Else
    Info = Info + LFCR + "Colors: Off"
    End If

    ' Level 1
    If optLevel1.Value = True Then
    Info = Info + LFCR + "Level:1"
    End If

    ' Level 2
    If optLevel2.Value = True Then
    Info = Info + LFCR + "Level:2"
    End If

    ' Level 3
    If optLevel3.Value = True Then
    Info = Info + LFCR + "Level:3"
    End If

    lblChoice.Caption = Info

    End Sub

    Private Sub Form_Load()

    End Sub
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Learning VB 6 (VB6)

    There seems to be confusion about the names of the controls. You mention that the form should contain three check boxes and three option buttons, but the code mentions:

    Check1, Check2 and Check3 (check boxes?)
    Option1, Option2 and Option3 (radio buttons?)
    chkColors, chkMouse, chkSound, chkLevel1, chkLevel2 and chkLevel3 (check boxes?)
    optLevel1, optLevel2 and optLevel3 (radio buttons?)

    In particular, you have On Click procedures for controls named chkLevel1 etc., but the code calls UpdateLabel, which refers to optLevel1 etc. Make sure that the code and the control names are consistent.

  3. #3
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Learning VB 6 (VB6)

    Hans:

    The Checkboxes are (supposed) to be:
    Checkbox 1 - Sound
    Checkbox 2 - Mouse
    Checkbox 3 - Color

    Rado Buttons are:
    Option1 - Label1
    Option2 - Label2
    Option3 - Label3

    The checkboxes are seemingly supposed to all display status, with the radio button only showing the one that is selected, or "On', and is to be displayed (below?) the checkboxes.

    I guess I'll just "try again"...

    Is there anything (in syntax) that is different in VB 5 and VB 6 that could affect this?

    Regards,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Learning VB 6 (VB6)

    Chuck, it would be easier on us if you delete all the empty procedures (nothing but air between the Sub line and End Sub line).

    Info is at least two lines long, since your code inserts a CRLF pair into it. How wide and tall is your label? Wide and tall enough to display the maximum amount of text?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Learning VB 6 (VB6)

    Many Windows applications have an "Options" or "Preferences" dialog. If you look carefully at such a dialog, you will see that a group of check boxes is used for situations where the user can tick each of the check boxes independently of the others. In other words, the user can tick none, or some, or all of the check boxes. A group of radio buttons, also known as option buttons, is used to present mutually exclusive options: the user can select only one option button in the group, all others will automatically be turned off.

    Each control has a unique name; you can see that name in the Properties pane when you select the control (in design mode). So if you select one of the radio buttons on the form, you can see its name. For the code to work correctly, you must use the exact names of the controls. In the code you posted, you seem to be using both chkLevel1 and optLevel1 for the same button. One of these must be incorrect. You should check carefully, then modify your code to refer to the correct control names.

  6. #6
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Learning VB 6 (VB6)

    Jefferson/Hans:

    Youy're right... I went back and re-entered the code, and all works now... it WAS, evidently name "mishaps", as well as name matching...

    Although it may not seem so, I appreciate your attention to, and pointing me toward syntax issues...

    I see how the syntax on the various fields can affect the overall workings...

    Thanks,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •