Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 06-15-08   #1 (permalink)
New to Overclock.net
 
Vagrant Storm's Avatar
 
intel nvidia

Join Date: Nov 2005
Location: Rochester, MN
Posts: 1,886

Rep: 86 Vagrant Storm is acknowledged by some
Unique Rep: 0
Folding Team Rank: 459
Trader Rating: 2
Default Can I get a little VB help?

Screwing arround here and I am at a loss why no matter what is entered in the text box it will end up being zero. In the default constructor I can set the "_side" variable to some thing other than zero and that value will be calculated and displayed just fine (_side = 5 will display 25 in the label)

This should be so simple...I don't understand


Code:
Option Explicit On
Option Strict On

Public Class MainForm

    Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
        Me.Close()
    End Sub

    Private Sub xSideTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xSideTextBox.Enter
        Me.xSideTextBox.SelectAll()
    End Sub

    Private Sub xSideTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles xSideTextBox.KeyPress
        ' accept only numbers, the period, and the Backspace

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
            AndAlso e.KeyChar <> "." _
            AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub xSideTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xSideTextBox.TextChanged
        Me.xAreaLabel.Text = String.Empty
    End Sub

    Private Sub xCalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
        Dim mySquare As New Square
        Dim area As New Square


        Integer.TryParse(Me.xSideTextBox.Text, mySquare.Side)
        Call area.CalculateArea()
        Me.xAreaLabel.Text = Convert.ToString(area.Area)

        Me.xSideTextBox.Focus()
    End Sub
End Class
and here is the class

Code:
Option Explicit On
Option Strict On

Public Class Square
    Private _area As Integer
    Private _side As Integer
    Public Property Side() As Integer
        Get
            Return _side
        End Get
        Set(ByVal value As Integer)
            If value > 0 Then
                _side = value
            Else
                _side = 0
            End If
        End Set
    End Property
    Public ReadOnly Property Area() As Integer
        Get
            Return _area
        End Get

    End Property
    Public Sub New()
        _side = 0
        _area = 0
    End Sub
   
    Public Sub CalculateArea()
        _area = _side * _side

    End Sub
End Class
Even if I completely delete any thing that defaults the _side variable to zero it will still come up as zero.

Any one have any ideas?

(Oh yeah this is suppose to take a value for the side of square and find the area of it...but that part works...it is just the user input that is being a pain...which should be the easy part)
__________________
If it ain't broke...MAKE IT GO FASTER!!!

System: My System
CPU
E8500 @ 4GHz
Motherboard
DFI X48 T2RS
Memory
4 Gigs Gskill DDR2 800
Graphics Card
8800GTS 320MB
Hard Drive
3x250GB WD in RAID 5
Sound Card
Xtreme Gamer
Power Supply
750 watt Silverstone
Case
Gigabyte Aurora
CPU cooling
Appogee
GPU cooling
Stock
OS
Vista 64 Ultimate
Monitor
19" Hans G wide screen
Vagrant Storm is offline I fold for Overclock.net   Reply With Quote
Old 06-16-08   #2 (permalink)
Intel Overclocker
 
Ledward's Avatar
 
intel nvidia

Join Date: Oct 2006
Posts: 19

Rep: 2 Ledward Unknown
Unique Rep: 0
Trader Rating: 0
Default

I'm not a vb.net person but it doesn't look like you ever set _side in your square object, you seem to just call CalculateArea() which takes _side (which is equal to 0) and calculates _area (which of course will then be equal to 0)

Edit:
Try changing Public Sub CalculateArea() to:

Public Sub CalculateArea(ByVal side as Integer)
_area = side * side
End Sub


and then when you call CalculateArea just pass the contents of the textbox like this
Call area.CalculateArea(xSideTextBox.Text)

Edit2: I noticed also that you have two square objects, mySquare and area. I'm not familiar with the vb.net API, what does Integer.TryParse do? I'm guessing TryParse takes (source,target) parameters... if that is the case then you need to do TryParse(xSideTextBox.Text, area.Side) instead.
__________________
System: My System
CPU
C2Q Q6600 @ 3200MHz
Motherboard
Gigabyte GA-965P-S3
Memory
4GB OCZ Platinum PC2-8500
Graphics Card
Gigabyte 8800GT Turboforce
Hard Drive
WD Caviar 320GB x2
Sound Card
Creative SB X-Fi Premium
Power Supply
Coolermaster eXtreme 430W
Case
TT Soprano
CPU cooling
TT Blue Orb II
OS
Windows Vista
Monitor
Samsung 245B

Last edited by Ledward : 06-16-08 at 04:10 AM.
Ledward is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 08:00 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.12298 seconds with 9 queries