PDA

View Full Version : BOGO



lexluther88
11-29-2006, 06:50 PM
I'm making this drawing program called BOGO in excel, VBA. It's for a class. I simply can't figure out how to start it. The website can be found as follows:

http://www.cs.uiuc.edu/class/fa06/cs105/
Then on the left side click on "Machine problems (Mp's)
Then click "Mp6" in the middle of the screen.

The actual given Excel file can be downloaded to see what's been given and such.
I'm stuck on the first part of the assignment, being the validate fuction.

"You should implement Validate by writing code between the Function Validate and End Function lines. The Validate function is used to check to see if the current instruction is a valid BOGO instruction. Using the function's parameter intCurRow, which holds the row of the instruction we're attempting to validate, check each of the three parts of the instruction (Direction, Distance, Color) to see that they conform to the BOGO specification described in the Introduction (Table 1). If any part of the instruction does not conform to the table, change the background color of all three cells to red and return False. Otherwise, return True.
The syntax for changing the background color of a cell to red is
Cells(intMyRow, intMyCol).Interior.Color = vbRed

If anyone could help me with the the code I'd very much appreciate it..what I'm trying now looks wrong in many ways, but it's:


Public Function validate(intCurRow As Integer) As Boolean
Dim intMyRow As Boolean
Dim intMyCol As Boolean
If Range("A4:C4").Value = "U" Or "D" Or "R" Or "L" Then
validate = True
Else
validate = False And Cells(intMyRow, intMyCol).Interior.Color = vbRed
End If

If Range("B4:B100").intCurRow.Value = "1" Or "2" Or "3" Or "4" Or "5" Or "6" Or "7" Or "9" Or "10" Or "11" Or "12" Or "13" Or "14" Or "15" Or "16" Or "17" Or "18" Or "19" Or "20" Then
validate = True
Else
validate = False And Cells(intMyRow, intMyCol).Interior.Color = vbRed
End If

If Range("C4:C100").intCurRow.Value = "Black" Or "Red" Or "Green" Or "Yellow" Or "Blue" Or "Magenta" Or "Cyan" Or "White" Then
validate = True
Else
validate = False And Cells(intMyRow, intMyCol).Interior.Color = vbRed

End If

johnske
11-29-2006, 08:15 PM
There's just so much wrong there I don't know where to start...

To get you started, you just can't use Or like that - wrong syntax, i.e...

If Range("A4:C4").Value = "U" Or "D" Or "R" Or "L" Then
is wrong, and you also need to look at this cell by cell, something like this Dim Cell As Range
For Each Cell In Range("A4:C4")
If Cell = "U" Or Cell = "D" Or Cell = "R" Or Cell = "L" Then
validate = True
Exit For
End If
Nextsimilarly with your horrendously long line
If Range("B4:B100").intCurRow.Value = "1" Or "2" Or "3" Or "4" Or "5" Or _
"6" Or "7" Or "9" Or "10" Or "11" Or "12" Or "13" Or "14" Or _
"15" Or "16" Or "17" Or "18" Or "19" Or "20" Thenwhich can be written in a form like this For Each Cell In Range("B4:B100")
If Cell > 0 And Cell < 21 Then
validate = True
Exit For
End If
Next

lexluther88
11-30-2006, 07:35 PM
Thanks! I used the code which you gave me and the test validate button turned out to be good for valid BOGO commands, but I still can't get it to detect invalid BOGO commands. I tried changing the "=" signs to "<>" signs and then setting it to Validate = false, but it just makes a runtime error.

Also, I don't know what they mean by intCurRow as the parameter. How would I implement that into the code?

This is what they gave me:

You should implement Validate by writing code between the Function Validate and End Function lines. The Validate function is used to check to see if the current instruction is a valid BOGO instruction. Using the function's parameter intCurRow, which holds the row of the instruction we're attempting to validate, check each of the three parts of the instruction (Direction, Distance, Color) to see that they conform to the BOGO specification described in the Introduction (Table 1). If any part of the instruction does not conform to the table, change the background color of all three cells to red and return False. Otherwise, return True.
The syntax for changing the background color of a cell to red is
Cells(intMyRow, intMyCol).Interior.Color = vbRed

The valid commands for BOGO are:







Direction
U = UP

D = DOWN

L = LEFT
R = RIGHT


Distance
Any integer between 1 and 20 inclusive


Color
BLACK
RED
GREEN
YELLOW
BLUE
MAGENTA
CYAN
WHITE







I know I'm asking way too much of you guys, but I simply don't know what they're asking me to do, besides write code between the given validate function, using intcurRow which is the parameter that holds the row which we choose to validate, checking to see if the commands are valid, checking each of the 3 parts..distance, color and direction.

Just a starter code for maybe distance to check if it's valid meaning between 1 and 20, using intcurRow would help..then I can just change the code to check for color and distance..

thanks again.