Need help getting value of text boxes into variables

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 2
Reputation: tamik0 is an unknown quantity at this point 
Solved Threads: 0
tamik0 tamik0 is offline Offline
Newbie Poster

Need help getting value of text boxes into variables

 
0
  #1
Sep 21st, 2007
I need help figuring out how to get the value of my text boxes into the variables I have declared (in bold) , any suggestions would be appreciated:



(/code) Option Explicit On
Option Strict On
Imports System.Convert

Public Class frmMain
Inherits System.Windows.Forms.Form


Private mlblInitialValue As Double
Private mlblSalvageValue As Double
Private mlblAssetLife As Single


Private mdblTotalDepreciation As Double
Private mdblAnnualDepreciation As Double


mlblInitialValue = (txtInitialValue.Text)
mlblSalvageLife = (txtSalvageLife.Text)
mlblAssetLife = (txtSalvageLife.Text)

mdblTotalDepreciation = mlblInitialValue - mlblSalvageLife
mdblAnnualDepreciation = mdblTotalDepreciation / mdblAssetLife

Private Const cintCol1Start As Integer = 100
Private Const cintCol2Start As Integer = 250
Private Const cintCol3Start As Integer = 400
Private Const cintCol4Start As Integer = 550
Private Const cintColWidth As Integer = 150

Private mfntPrint As Font
Private msngFontHeight As Single
Private msngYPos As Single
Private mfnrPrint As Font(/code)
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1
Reputation: funrunner is an unknown quantity at this point 
Solved Threads: 0
funrunner funrunner is offline Offline
Newbie Poster

Re: Need help getting value of text boxes into variables

 
0
  #2
Sep 22nd, 2007
I changed your code to this and added some labels to the form to display the results:

  1. Imports System.convert
  2.  
  3. Public Class Form1
  4. Inherits System.Windows.Forms.Form
  5.  
  6. Private mlblInitialValue As Double
  7. Private mlblSalvageValue As Double
  8. Private mlblAssetLife As Single
  9.  
  10. Private mdblTotalDepreciation As Double
  11. Private mdblAnnualDepreciation As Double
  12.  
  13. Private Const cintCol1Start As Integer = 100
  14. Private Const cintCol2Start As Integer = 250
  15. Private Const cintCol3Start As Integer = 400
  16. Private Const cintCol4Start As Integer = 550
  17. Private Const cintColWidth As Integer = 150
  18.  
  19. Private mfntPrint As Font
  20. Private msngFontHeight As Single
  21. Private msngYPos As Single
  22. 'Private mfnrPrint As Font(/code)
  23.  
  24. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  25.  
  26.  
  27. End Sub
  28.  
  29. Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  30. mlblInitialValue = (txtInitialValue.Text)
  31. mlblSalvageValue = (txtSalvageLife.Text)
  32. mlblAssetLife = (txtSalvageLife.Text)
  33.  
  34. mdblTotalDepreciation = mlblInitialValue - mlblSalvageValue
  35. mdblAnnualDepreciation = mdblTotalDepreciation / mlblSalvageValue
  36.  
  37. Me.lblTotalDeprec.Text = mdblTotalDepreciation.ToString
  38. Me.lblAnnualDeprec.Text = mdblAnnualDepreciation.ToString
  39.  
  40. End Sub
  41. End Class
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Need help getting value of text boxes into variables

 
0
  #3
Sep 22nd, 2007
Being picky but you should use the following:
  1. mlblInitialValue = Double.Parse(txtInitialValue.Text)
  2. mlblSalvageValue = Double.Parse(txtSalvageLife.Text)
  3. mlblAssetLife = Single.Parse(txtSalvageLife.Text)
or
  1. mlblInitialValue = CDbl(txtInitialValue.Text)
  2. mlblSalvageValue = CDbl(txtSalvageLife.Text)
  3. mlblAssetLife = CSng(txtSalvageLife.Text)
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 7
Reputation: bharatsaboo is an unknown quantity at this point 
Solved Threads: 0
bharatsaboo bharatsaboo is offline Offline
Newbie Poster

Re: Need help getting value of text boxes into variables

 
0
  #4
Sep 23rd, 2007
You should use the following functions when transferring text content to a numeric content

Val()
CDbl()
CSng()

The above will convert the text data into numeric data and then the data will transfer into the variables and then there would be no problem.

Hope the above was useful to you.

Bharat Saboo


Originally Posted by tamik0 View Post
I need help figuring out how to get the value of my text boxes into the variables I have declared (in bold) , any suggestions would be appreciated:



(/code) Option Explicit On
Option Strict On
Imports System.Convert

Public Class frmMain
Inherits System.Windows.Forms.Form


Private mlblInitialValue As Double
Private mlblSalvageValue As Double
Private mlblAssetLife As Single


Private mdblTotalDepreciation As Double
Private mdblAnnualDepreciation As Double


mlblInitialValue = (txtInitialValue.Text)
mlblSalvageLife = (txtSalvageLife.Text)
mlblAssetLife = (txtSalvageLife.Text)

mdblTotalDepreciation = mlblInitialValue - mlblSalvageLife
mdblAnnualDepreciation = mdblTotalDepreciation / mdblAssetLife

Private Const cintCol1Start As Integer = 100
Private Const cintCol2Start As Integer = 250
Private Const cintCol3Start As Integer = 400
Private Const cintCol4Start As Integer = 550
Private Const cintColWidth As Integer = 150

Private mfntPrint As Font
Private msngFontHeight As Single
Private msngYPos As Single
Private mfnrPrint As Font(/code)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC