944,020 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 2134
  • VB.NET RSS
Sep 21st, 2007
0

Need help getting value of text boxes into variables

Expand 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)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tamik0 is offline Offline
2 posts
since Sep 2007
Sep 22nd, 2007
0

Re: Need help getting value of text boxes into variables

I changed your code to this and added some labels to the form to display the results:

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
funrunner is offline Offline
1 posts
since Sep 2007
Sep 22nd, 2007
0

Re: Need help getting value of text boxes into variables

Being picky but you should use the following:
VB.NET Syntax (Toggle Plain Text)
  1. mlblInitialValue = Double.Parse(txtInitialValue.Text)
  2. mlblSalvageValue = Double.Parse(txtSalvageLife.Text)
  3. mlblAssetLife = Single.Parse(txtSalvageLife.Text)
or
VB.NET Syntax (Toggle Plain Text)
  1. mlblInitialValue = CDbl(txtInitialValue.Text)
  2. mlblSalvageValue = CDbl(txtSalvageLife.Text)
  3. mlblAssetLife = CSng(txtSalvageLife.Text)
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Sep 23rd, 2007
0

Re: Need help getting value of text boxes into variables

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


Click to Expand / Collapse  Quote originally posted by tamik0 ...
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)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bharatsaboo is offline Offline
7 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Find And Replace DailougBox
Next Thread in VB.NET Forum Timeline: Excel in VB





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC