![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 8
Rep Power: 0
![]() |
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 SubWhat 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 SubI tend to stay away from one-on-one after class because last time I tried that I was more confused after it was done. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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'.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Viewing VB's Automated code | john Wesley | Visual Basic .NET | 3 | Jun 8th, 2006 5:37 AM |
| FTP and return code fetching | Serinth | C | 2 | May 28th, 2006 11:05 PM |
| executing code in the data segment | para | C | 1 | Jan 4th, 2006 12:52 PM |
| String to Morse Code - Copying from string to string | Xenon | C | 29 | Nov 10th, 2005 2:30 PM |
| Help with code please | LiverLad | Java | 0 | Feb 9th, 2005 10:36 AM |