5 Replies - 929 Views - Last Post: 25 April 2013 - 01:24 PM Rate Topic: -----

#1 reveal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 13

Working on school project can't seem to get it to run correctly

Posted 24 April 2013 - 03:36 PM

I have a project to do inside the book which walks you through the steps of coding it, however at the end when you test it I am not getting the results it says I should get. I am getting nothing returned for a value and everything is verbatim from the code in the book.

It has me create a class and use it instead of a structure. Here is what the class looks like

Public Class RectangularPool
    Private _decLength As Decimal
    Private _decWidth As Decimal
    Private _decDepth As Decimal

    Public Property Length As Decimal
        Get
            Return _decLength
        End Get
        Set(ByVal value As Decimal)
            If value > 0 Then
                _decLength = value
            Else
                _decLength = 0
            End If
        End Set
    End Property

    Public Property Width As Decimal
        Get
            Return _decWidth
        End Get
        Set(ByVal value As Decimal)
            If value > 0 Then
                _decWidth = value
            Else
                _decWidth = 0
            End If
        End Set
    End Property

    Public Property Depth As Decimal
        Get
            Return _decDepth
        End Get
        Set(ByVal value As Decimal)
            If value > 0 Then
                _decDepth = 0
            Else
                _decDepth = 0
            End If
        End Set
    End Property

    Public Sub New()
        ' default constructor
        _decLength = 0
        _decWidth = 0
        _decDepth = 0
    End Sub

    Public Function GetVolume() As Decimal
        Return _decLength * _decWidth * _decDepth
    End Function

    Public Function GetGallons() As Decimal
        Dim decVol As Decimal
        decVol = GetVolume()
        Return decVol * 7.48
    End Function
End Class



That is the class code, yet when I input numbers to calculate it is returning a 0 value.

I can put also the other code for the form for people to see if that helps as well.

Is This A Good Question/Topic? 0
  • +

Replies To: Working on school project can't seem to get it to run correctly

#2 reveal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 13

Re: Working on school project can't seem to get it to run correctly

Posted 24 April 2013 - 04:12 PM

Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        ' displays the number of gallons

        Dim pool As New RectangularPool
        Dim decGallons As Decimal

        Decimal.TryParse(txtLength.Text, pool.Length)
        Decimal.TryParse(txtWidth.Text, pool.Width)
        Decimal.TryParse(txtDepth.Text, pool.Depth)

        decGallons = pool.GetGallons
        lblGallons.Text = decGallons.ToString("N0")

        txtLength.Focus()
    End Sub



The program code
Was This Post Helpful? 0
  • +
  • -

#3 reveal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 13

Re: Working on school project can't seem to get it to run correctly

Posted 24 April 2013 - 04:45 PM

I'm an idiot and noticed my mistake

If value > 0 Then
38
_decDepth = 0
39
Else
40
_decDepth = 0

needed to be _decDepth = value
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: Working on school project can't seem to get it to run correctly

Posted 24 April 2013 - 05:00 PM

View Postreveal, on 24 April 2013 - 05:45 PM, said:

I'm an idiot and noticed my mistake

Not an idiot.. a minor glitch in your thinking. I was just about to answer, and refreshed the page, and there you were, all fixed up! Sometimes all it takes is to expose your code to others.
Was This Post Helpful? 1
  • +
  • -

#5 reveal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 13

Re: Working on school project can't seem to get it to run correctly

Posted 25 April 2013 - 10:28 AM

View Postlar3ry, on 24 April 2013 - 05:00 PM, said:

View Postreveal, on 24 April 2013 - 05:45 PM, said:

I'm an idiot and noticed my mistake

Not an idiot.. a minor glitch in your thinking. I was just about to answer, and refreshed the page, and there you were, all fixed up! Sometimes all it takes is to expose your code to others.


Thank you. I really do like this site for its vast features of resources and help it provides. It's good that people won't help you write your school project but guide you to getting to work correctly when you are having problems.
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Working on school project can't seem to get it to run correctly

Posted 25 April 2013 - 01:24 PM

Very often not taugh in schools is Debugging Skills.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1