Results 1 to 9 of 9
  1. #1
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Option Explicit (VB6 SP-5)

    <hr>Private Sub tmrTimer1_Timer()
    Dim R, G, B
    Dim X, Y
    Dim Counter
    'Is it OK to draw?
    If gDrawPoints = 1 Then
    'Draw 100 Points
    For Counter = 1 To 100 Step 1
    'Get a random color
    R = Rnd * 255
    G = Rnd * 255
    B = Rnd * 255
    frmPoints.PSet Step(1, 1), RGB(R, G, [img]/forums/images/smilies/cool.gif[/img]
    If CurrentX >= frmPoints.ScaleWidth Then
    CurrentX = Rnd * frmPoints.ScaleWidth
    End If
    If CurrentY >= frmPoints.ScaleHeight Then
    CurrentY = Rnd + frmPoints.ScaleHeight
    End If
    Next
    End If

    End Sub
    <hr>
    See BOLD areas!
    You declared X and Y, but are using CurrentX and CurrentY in the If block.
    Also is the * and + correct?
    Regards,
    Rudi

  2. #2
    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

    Option Explicit (VB6 SP-5)

    The folowing works fine, except that (the book) says it's supposed to draw random colors... and it don't draw nuttin...

    No errors, menu seems to work, but no dots, lines, or anything else.

    Can you see something?

    Chuck Billow
    *******
    Option Explicit

    'A flag to determine if points will be drawn
    Dim gDrawPoints

    Private Sub Form_Load()
    'Disable drawing
    gDrawPoints = 0

    End Sub

    Private Sub mnuClear_Click()
    'Disable drawing
    gDrawPoints = 0
    'Clear the form
    frmPoints.Cls
    End Sub

    Private Sub mnuDrawPoints_Click()
    'Enable drawing
    gDrawPoints = 1

    End Sub

    Private Sub mnuExit_Click()
    End
    End Sub
    Private Sub tmrTimer1_Timer()
    Dim R, G, B
    Dim X, Y
    Dim Counter
    'Is it OK to draw?
    If gDrawPoints = 1 Then
    'Draw 100 Points
    For Counter = 1 To 100 Step 1
    'Get a random color
    R = Rnd * 255
    G = Rnd * 255
    B = Rnd * 255
    frmPoints.PSet Step(1, 1), RGB(R, G, [img]/forums/images/smilies/cool.gif[/img]
    If CurrentX >= frmPoints.ScaleWidth Then
    CurrentX = Rnd * frmPoints.ScaleWidth
    End If
    If CurrentY >= frmPoints.ScaleHeight Then
    CurrentY = Rnd + frmPoints.ScaleHeight
    End If
    Next
    End If

    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"

  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: Option Explicit (VB6 SP-5)

    Rudi:

    I'm (obviously) trying to learn VBasic...

    I went back a step to the initial coding...

    I've double-checked it, I think... Although I understand what you are saying, I cannot find any errors in my inputs, so I can't find a bloody thing to correct... and yet it still all stays white, while it is supposed to generate random color dots.

    Again, no errors, but no dots either,,,

    ??

    Chuck

    Option Explicit
    'A flag to determine if points will be drawn
    Dim gDrawPoints
    Private Sub Form_Load()
    'Disable drawing
    gDrawPoints = 0
    End Sub
    Private Sub mnuClear_Click()
    'Disable drawing
    gDrawPoints = 0
    'Clear the form
    frmPoints.Cls
    End Sub
    Private Sub mnuDrawPoints_Click()
    'Enable drawing
    gDrawPoints = 1
    End Sub
    Private Sub mnuExit_Click()
    End
    End Sub
    Private Sub tmrTimer1_Timer()
    Dim R, G, B
    Dim X, Y
    Dim Counter
    'Is it OK to draw?
    If gDrawPoints = 1 Then
    'Draw 100 Points
    For Counter = 1 To 100 Step 1
    'Get a random color
    R = Rnd * 255
    G = Rnd * 255
    B = Rnd * 255
    'Get a random (X,Y) coordinate
    X = Rnd * frmPoints.ScaleWidth
    Y = Rnd * frmPoints.ScaleHeight
    'Draw a point
    frmPoints.PSet (X, Y), RGB(R, G, [img]/forums/images/smilies/cool.gif[/img]
    Next
    End If
    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"

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

    Re: Option Explicit (VB6 SP-5)

    The code refers to a Timer control tmrTimer1.
    1. Have you placed a Timer control on your form?
    2. If so, have you renamed it to tmrTimer1?
    3. And have you set its Interval property to a non-zero value?

    The code also refers to several menu items.
    4. Did you create a menu, using Tools | Menu Editor?
    5. If so, did you select the Draw Points menu item when you ran the program?

    The On Timer event of the Timer control fires every Interval milliseconds; if Interval is 0, the timer is Off. If you want to draw some points every 2 seconds, set Interval to 2000 (2 seconds = 2000 milliseconds)

  5. #5
    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: Option Explicit (VB6 SP-5)

    Hans / Rudi:

    I'm sorry....

    It was the control. It was Timer instead of Timer1...

    I'll look harder next time...

    Thanks.

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

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

  6. #6
    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: Option Explicit (VB6 SP-5)

    I don't understand why this didn't generate a compile error. Do you use Option Explicit at the top of your code modules? There is a checkbox somewhere in the options to add this automatically. In the Office VBA version of the VBE, it's Tools>Options...>(Editor tab) Require Variable Declaration. This will save a lot of grief relating to typos. Regarding form object names, it may help to use the Me reference to the form in front of your control names (that is, type Me. and choose the control name from the pop-up list). Of course, if you rename the control, you have to fix the references yourself... and the event procedure names, well... I don't think VB helps much with those.

  7. #7
    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: Option Explicit (VB6 SP-5)

    Jefferson:

    I did use Option Explicit (see code in initial entry), so I don't know what went wrong, but I'm not good enough (yet) to really be able to cut off errors at the pass...

    Geez, I'm having enough problems with just dumb mistakes...

    But I saw the setting for the Option Explicit in the Options... Thought it was a good idea, but was gonna wait and leave settings to "defaults"...

    When or why would you NOT want the declarations "enforced"?

    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"

  8. #8
    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: Option Explicit (VB6 SP-5)

    > When or why would you NOT want the declarations "enforced"?

    I can't think of any time that you would purposely choose to work with undeclared variables.

  9. #9
    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: Option Explicit (VB6 SP-5)

    Jefferson:

    Dat's what I thought... 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
  •