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)

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

Imports System.convert

Public Class Form1
    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

    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) 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        

    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        mlblInitialValue = (txtInitialValue.Text)
        mlblSalvageValue = (txtSalvageLife.Text)
        mlblAssetLife = (txtSalvageLife.Text)

        mdblTotalDepreciation = mlblInitialValue - mlblSalvageValue
        mdblAnnualDepreciation = mdblTotalDepreciation / mlblSalvageValue

        Me.lblTotalDeprec.Text = mdblTotalDepreciation.ToString
        Me.lblAnnualDeprec.Text = mdblAnnualDepreciation.ToString

    End Sub
End Class

Being picky but you should use the following:

mlblInitialValue = Double.Parse(txtInitialValue.Text)
        mlblSalvageValue = Double.Parse(txtSalvageLife.Text)
        mlblAssetLife = Single.Parse(txtSalvageLife.Text)

or

mlblInitialValue = CDbl(txtInitialValue.Text)
        mlblSalvageValue = CDbl(txtSalvageLife.Text)
        mlblAssetLife = CSng(txtSalvageLife.Text)

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

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.