[Year 12 SofDev] Van Gogo SD U3O2 solution

Mark Kelly kel at mckinnonsc.vic.edu.au
Mon May 21 19:05:45 EST 2007


Attached is one way of tackling the Van Gogo task I posted here and at 
the VITTA site.

It's in VB6, and is only one way of doing it (specifically, using a tab 
control and FlexGrid)

Cheers

MArk

-- 
Mark Kelly
Manager - Information Systems
McKinnon Secondary College
McKinnon Rd McKinnon 3204, Victoria, Australia
Direct line / Voicemail: 8520 9085
School Phone +613 8520 9000 << new number!
School Fax   +613 9578 9253
kel AT mckinnonsc.vic.edu.au

Webmaster - http://www.mckinnonsc.vic.edu.au
IT Lecture notes: http://vceit.com
Moderator: IPM Mailing List

"My mother used to say to me,
'In this world you must be O so smart or O so pleasant.'
I recommend pleasant.  You may quote me."  Harvey, 1950.
-------------- next part --------------
'global declarations

Dim Saved As Boolean

Private Sub btnEnd_Click()
If Not Saved Then
    a = MsgBox("Data has not been saved.  Save now?", vbYesNo)
    If a = vbYes Then cmdSave_Click
End If
End
End Sub

Private Sub chkStrip_Click()
RecalcCost
End Sub

Private Sub cmdAddWall_Click()

'if first row is empty, fill it in rather than adding new one

Grid.Col = 1
If Grid.Rows > 2 Or Grid.Text > "" Then
    With Grid
        .Rows = Grid.Rows + 1
        .Col = 0
        .Row = Grid.Rows - 1
        .Text = "Wall " & Grid.Rows - 1
    End With
End If

r = Grid.Rows - 1
h$ = InputBox("Enter a height for wall " & r, "Enter value")
If Val(h$) = 0 Then MsgBox "Bad height": Exit Sub
w$ = InputBox("Enter a width for wall " & r, "Enter value")
If Val(w$) = 0 Then MsgBox "Bad width": Exit Sub

Grid.Col = 1
Grid.Text = h$
Grid.Col = 2
Grid.Text = w$
area = CSng(h$) * CSng(w$)
Grid.Col = 3
Grid.Text = CStr(area)
RecalcCost
Saved = False

End Sub



Private Sub cmdDeleteWall_Click()

If Grid.Rows = 2 Then
    Grid.Row = 1
    Grid.Col = 1: Grid.Text = ""
    Grid.Col = 2: Grid.Text = ""
    Grid.Col = 3: Grid.Text = ""
Else
    If Grid.Row > 0 Then Grid.RemoveItem (Grid.Row)
End If
Saved = False


End Sub

Private Sub cmdLoad_Click()
Dim f As Integer
Dim v As Integer
CommonDialog1.ShowOpen
FileName$ = CommonDialog1.FileName
If FileName$ = "" Then Exit Sub
Dim a1, a2 As Integer
f = FreeFile

Open FileName$ For Input As f
Input #f, x$: txtSurname = x$
Input #f, x$: txtGivenName = x$
Input #f, x$: txtStreet = x$
Input #f, x$: txtSuburb = x$
Input #f, x$: txtPostcode = x$
Input #f, x$: txtPhone = x$
Input #f, x$: txtSurcharge = x$
Input #f, x$: txtNormalCost = x$
Input #f, x$: txtDeluxeExtra = x$
Input #f, v: chkStrip.Value = v
Input #f, x$
If x$ = "interior" Then OptIntExt(0) = vbTrue Else OptIntExt(1) = vbTrue
Input #f, x$
If x$ = "normal" Then optQuality(0) = vbTrue Else optQuality(1) = vbTrue

Input #f, g: MsgBox g & "rows"
Grid.Rows = g + 1

For i = 1 To Grid.Rows - 1
    Grid.Row = i
    Grid.Col = 1: Input #f, x$: Grid.Text = x$ 'height
    Grid.Col = 2: Input #f, x$: Grid.Text = x$ 'width
    Grid.Col = 3: Input #f, x$: Grid.Text = x$ 'area
Next
Close f
Saved = True


End Sub

Private Sub cmdSave_Click()
FileName$ = InputBox("Filename$")
f = FreeFile

Open FileName$ For Output As f
Print #f, txtSurname
Print #f, txtGivenName
Print #f, txtStreet
Print #f, txtSuburb
Print #f, txtPostcode
Print #f, txtPhone
Print #f, txtSurcharge
Print #f, txtNormalCost
Print #f, txtDeluxeExtra
Print #f, chkStrip.Value
If OptIntExt(0) = vbTrue Then x$ = "interior" Else x$ = "exterior"
Print #f, x$
If optQuality(0) = vbTrue Then x$ = "normal" Else x$ = "deluxe"
Print #f, x$
Print #f, Grid.Rows - 1

For i = 1 To Grid.Rows - 1
    Grid.Row = i
    Grid.Col = 1: Print #f, Grid.Text   'height
    Grid.Col = 2: Print #f, Grid.Text   'width
    Grid.Col = 3: Print #f, Grid.Text   'area
Next
Close f
MsgBox "Data saved to " & FileName$
Saved = True


End Sub


Private Sub Form_Load()

    With Grid
        .Row = 0
        .Col = 1
        .Text = "Height (m)"
        .Col = 2
        .Text = "Width (m)"
        .Col = 3
        .Text = "Area (sq.m)"
    End With
    Saved = True
    
End Sub



Private Sub Grid_Click()   'clicked in grid, to edit cell
    Dim area, totalarea As Single
    
    Grid.Row = Grid.MouseRow
    Grid.Col = Grid.MouseCol
    If r < 1 Or c < 1 Or c > 2 Then Exit Sub
        
    If c = 1 Then   'height
        h$ = InputBox("Enter a height for wall " & r, "Enter value")
    ElseIf c = 2 Then  'width
        h$ = InputBox("Enter a width for wall " & r, "Enter value")
    End If
    If h$ = "" Then Exit Sub
    Grid.Text = h$
    
    Grid.Col = 1: h$ = Grid.Text
    Grid.Col = 2: w$ = Grid.Text
    If h$ > "" And w$ > "" Then
        area = CSng(h$) * CSng(w$)
        Grid.Col = 3
        Grid.Text = CStr(area)
        RecalcCost
    End If
    Saved = False
    
End Sub
Private Sub RecalcCost()
    'calculate total area of all walls
    Grid.Col = 3  'where the wall totalareas live
    
    For r = 1 To Grid.Rows - 1
        Grid.Row = r
        If Grid.Text > "" Then  'area exists
            totalarea = totalarea + CSng(Grid.Text)
        End If
    Next
    
    txtTotalArea = CStr(totalarea)
    
    ' work out cost, step by step to keep it simple
    'first - validate setup data
    
    If txtNormalCost = "" Then
        MsgBox "Error - Setup > Normal Paint cost is empty!"
        bad = True
    End If
    
    If txtSurcharge = "" Then
        MsgBox "Error - Setup > Exterior surcharge is empty!"
        bad = True
    End If
    
    If txtDeluxeExtra = "" Then
        MsgBox "Error - Setup > Normal Paint cost is empty!"
        bad = True
    End If
    
    If bad Then Exit Sub
    
    cost = totalarea * CSng(txtNormalCost)  'basic cost
    
    If optQuality(1) = True Then    'is LongLife paint
    'remember value is e.g. 15 not .15 so need to /100
        cost = cost + (cost * CSng(txtDeluxeExtra / 100))
    End If
    
    If OptIntExt(1) = True Then 'is exterior
        'again, surcharge is like 15 not .15
        cost = cost + (cost * CSng(txtSurcharge / 100))
    Else ' is interior - check if wallpaper has to be stripped
        If chkStrip Then   'non-zero = true
            cost = cost + (totalarea * CSng(txtStripCost))
        End If
    End If
    
    txtTotalCost = Format$(CStr(cost), "$#,#####.00")
   

End Sub

Private Sub SetGrid(r, c, v)
With Grid
    .Row = CInt(r)
    .Col = CInt(c)
    .Text = v
End With
End Sub


Private Sub OptIntExt_Click(Index As Integer)
chkStrip.Enabled = OptIntExt(0) = True
RecalcCost
End Sub

Private Sub optQuality_Click(Index As Integer)
RecalcCost

End Sub

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gogo1.jpg
Type: image/jpeg
Size: 28796 bytes
Desc: not available
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20070521/45e46922/gogo1-0001.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gogo2.jpg
Type: image/jpeg
Size: 25633 bytes
Desc: not available
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20070521/45e46922/gogo2-0001.jpg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gogo3.jpg
Type: image/jpeg
Size: 22695 bytes
Desc: not available
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20070521/45e46922/gogo3-0001.jpg


More information about the sofdev mailing list