Consulting

Results 1 to 3 of 3

Thread: BOGO

  1. #1

    BOGO

    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
    [VBA]Cells(intMyRow, intMyCol).Interior.Color = vbRed[/VBA]

    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:
    [VBA]

    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



    [/VBA]

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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...
    [vba]
    If Range("A4:C4").Value = "U" Or "D" Or "R" Or "L" Then
    [/vba]is wrong, and you also need to look at this cell by cell, something like this [vba] 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
    Next[/vba]similarly with your horrendously long line [vba]
    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[/vba]which can be written in a form like this [vba] For Each Cell In Range("B4:B100")
    If Cell > 0 And Cell < 21 Then
    validate = True
    Exit For
    End If
    Next[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    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.
    Last edited by lexluther88; 11-30-2006 at 08:12 PM.

Posting Permissions

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