Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Code Explenation & A Little Help (http://www.programmingforums.org/showthread.php?t=14479)

johann vanoustren Nov 16th, 2007 7:08 PM

Code Explenation & A Little Help
 
So in our class now, we will be making a screen saver.

I wasn't there Monday - Friday and Tuesday needed to finish a project from those few days so I wasn't totally able to pay 100% attention.

I'm just wondering if someone can read the code I have now (he posted it, just without explanations though) and help me out by telling me what each line is doing?

:

Option Explicit

Private Sub cmdRun_Click()

Dim sngChange As Single
Dim sngX As Single
Dim sngY As Single
Dim intCount As Integer
Dim sngN As Single

sngChange = 0

Do
    intCount = intCount + 1
    sngChange = sngChange + 1000
    For sngX = sngChange To Me.Width - sngChange
        sngN = sngN + ((Me.Height - 2 * sngChange - 380) / (Me.Width - 2 * sngChange))
        PSet (sngX, sngChange), vbRed
        PSet (sngX, Fix(sngN) + sngChange), vbBlue
    Next sngX
    sngN = 0
    For sngY = sngChange To Me.Height - sngChange - 380
        PSet (Me.Width - sngChange, sngY), vbRed
    Next sngY
    Line (sngChange, sngChange)-(Me.Width - sngChange, Me.Height - sngChange - 380), vbBlue
    For sngX = Me.Width - sngChange To sngChange Step -1
        PSet (sngX, Me.Height - sngChange - 380), vbRed
    Next sngX
    For sngY = Me.Height - sngChange - 380 To sngChange Step -1
        PSet (sngChange, sngY), vbRed
    Next sngY
Loop Until intCount = 5
End Sub

Private Sub Form_Load()

Me.WindowState = 2

End Sub


What I'm really having more of a problem with is the For To Step, like the "For sngY = Me.Height - sngChange - 380 To sngChange Step -1".

The end result when Run is pressed looks like this:
http://img108.imageshack.us/img108/4223/37116248tp8.jpg

And finally, we need to make a code to have a line bounce off the screen and change colors. I have it doing that, know how to do the colors (Have the "PSet (sngX, sngY) , sngColors" and sngColors = White under each If Then statement), but I don't know what the last like needs to be to get it to stop after so long or at a certain point.

Here is what I have so far though:

:

Option Explicit

Private Sub cmdBounce_Click()

Dim sngX As Single
Dim sngY As Single
Dim intChangeX As Integer
Dim intChangeY As Integer

intChangeX = 1
intChangeY = 1

Do
    sngX = sngX + intChangeX
    sngY = sngY + intChangeY
    PSet (sngX, sngY), vbBlue
    'Line(sngX,sngY)-(10000,8000), 12000000,Bf
    If sngY >= Me.Height - 380 Then
        intChangeY = -1
    End If
    If sngX >= Me.Width - 380 Then
        intChangeX = -1
    End If
    If sngY <= 0 Then
        intChangeY = 1
    End If
    If sngX <= 0 Then
        intChangeX = 1
    End If
Loop Until sngX > Me.Width

End Sub


I tend to stay away from one-on-one after class because last time I tried that I was more confused after it was done.

DaWei Nov 16th, 2007 8:21 PM

Re: Code Explenation & A Little Help
 
The for statement has two or three elements (yours has two). The first element defines a beginning value. The second defines an ending value. The loop will be executed for the number of times it takes to move from the first value through the second value, incrementing by one (or until an explicit exit is commanded).

I say "incrementing by one" because that is the default increment. If there is a third element present, it will define the increment ("step", as it's called).

You seem to have missed more than a few days, or were otherwise occupied picking your nose when the basics were taught. That's lamentable, I suppose. You might find someone willing to explain each and every line of the code to you, but don't hold your breath.

Just sayin'.


All times are GMT -5. The time now is 3:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC