I need someone to look over this and see what I am doing wrong. I keepgetting errors on this part of the code. It says its not defined.I also think i need to take that splitter thing out. I am new to all of this and haven't a clue how to fix it. Any help to give me some insight into what I am doing wrong is appreciated.

msngInitialValue = ToSingle(txtInitialValue.Text)
msngSalvageValue = ToSingle(txtSalvageValue.Text)
mintAssetLife = ToInt32(txtAssetLife.Text)


___________________________________________________

Option Strict On
Option Explicit On 

Public Class frmmain
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
    Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
    Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmmain))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
        Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
        Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.Label1.Location = New System.Drawing.Point(80, 80)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(112, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Initial Value :"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.Label2.Location = New System.Drawing.Point(80, 112)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(112, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Asset Life :"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.Label3.Location = New System.Drawing.Point(80, 144)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(112, 16)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "Salvage Value :"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(200, 80)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(120, 20)
        Me.TextBox1.TabIndex = 3
        Me.TextBox1.Text = ""
        Me.TextBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(200, 112)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(120, 20)
        Me.TextBox2.TabIndex = 4
        Me.TextBox2.Text = ""
        Me.TextBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'TextBox3
        '
        Me.TextBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox3.Location = New System.Drawing.Point(200, 144)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(120, 20)
        Me.TextBox3.TabIndex = 5
        Me.TextBox3.Text = ""
        Me.TextBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Splitter1
        '
        Me.Splitter1.Location = New System.Drawing.Point(0, 0)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 238)
        Me.Splitter1.TabIndex = 6
        Me.Splitter1.TabStop = False
        '
        'Button1
        '
        Me.Button1.Enabled = CType(configurationAppSettings.GetValue("Button1.Enabled", GetType(System.Boolean)), Boolean)
        Me.Button1.Location = New System.Drawing.Point(408, 88)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(112, 24)
        Me.Button1.TabIndex = 7
        Me.Button1.Text = "Print Report"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(408, 144)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(112, 24)
        Me.Button2.TabIndex = 8
        Me.Button2.Text = "Exit"
        '
        'PrintDocument1
        '
        Me.PrintDocument1.DocumentName = CType(configurationAppSettings.GetValue("Button1.Enabled", GetType(System.String)), String)
        Me.PrintDocument1.OriginAtMargins = CType(configurationAppSettings.GetValue("PrintDocument1.OriginAtMargins", GetType(System.Boolean)), Boolean)
        '
        'PrintPreviewDialog1
        '
        Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
        Me.PrintPreviewDialog1.Document = Me.PrintDocument1
        Me.PrintPreviewDialog1.Enabled = True
        Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
        Me.PrintPreviewDialog1.Location = New System.Drawing.Point(23, 23)
        Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
        Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
        Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
        Me.PrintPreviewDialog1.Visible = False
        '
        'PrintDialog1
        '
        Me.PrintDialog1.AllowPrintToFile = CType(configurationAppSettings.GetValue("PrintDialog1.AllowPrintToFile", GetType(System.Boolean)), Boolean)
        Me.PrintDialog1.AllowSelection = CType(configurationAppSettings.GetValue("PrintDialog1.AllowSelection", GetType(System.Boolean)), Boolean)
        Me.PrintDialog1.AllowSomePages = CType(configurationAppSettings.GetValue("PrintDialog1.AllowSomePages", GetType(System.Boolean)), Boolean)
        Me.PrintDialog1.Document = Me.PrintDocument1
        Me.PrintDialog1.PrintToFile = CType(configurationAppSettings.GetValue("PrintDialog1.PrintToFile", GetType(System.Boolean)), Boolean)
        Me.PrintDialog1.ShowHelp = CType(configurationAppSettings.GetValue("PrintDialog1.ShowHelp", GetType(System.Boolean)), Boolean)
        '
        'frmmain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.ActiveBorder
        Me.ClientSize = New System.Drawing.Size(610, 238)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Splitter1)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "frmmain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Depreciation Schedule"
        Me.ResumeLayout(False)

    End Sub

#End Region

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

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub


        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 = 170
        Private mintAssetLife As Integer
        Private msngInitialValue As Single
        Private msngSalvageValue As Single
        Private mintCurrentYear As Integer
        Private msngTotalDepreciation As Single
        Private msngAnnualDepreciation As Single
        Private msngCurrentValue As Single

        
        Private msngPage As Single

        Private msngPages As Single

    Private msngYPos As Single

        Private msngFontHeight As Single

        Private mfntPrint As Font

    Private Sub PrintPageTitles(ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
        Dim penLine As Pen = New Pen(Brushes.Black)
        Dim recCurrent As RectangleF
        Dim sfCurrent As New StringFormat
        ev.Graphics.DrawRectangle(penLine, _
                ev.PageBounds.Left + 100, _
                ev.PageBounds.Top + 100, _
                ev.PageBounds.Right - 200, _
                ev.PageBounds.Bottom - 200)
        mfntPrint = New Font("Arial", 14)
        msngYPos = ev.MarginBounds.Top + _
            (2 * mfntPrint.GetHeight(ev.Graphics))
        recCurrent = New RectangleF(ev.MarginBounds.Left, _
            ev.MarginBounds.Top, ev.MarginBounds.Right - 100, _
            msngYPos)
        sfCurrent.Alignment = StringAlignment.Center
        ev.Graphics.DrawString("Depreciation Schedule", _
            mfntPrint, Brushes.Black, recCurrent, sfCurrent)
        mfntPrint = New Font("Arial", 10)
        msngFontHeight = mfntPrint.GetHeight(ev.Graphics)
        msngYPos += msngFontHeight

    End Sub

    Private Sub DrawStringInBox(ByVal ev As System.Drawing.Printing.PrintPageEventArgs, _
            ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single, _
            ByVal s As String)
        Dim sfCurrent As New StringFormat
        Dim recCurrent As New RectangleF(x1, y1, x2, y2)
        sfCurrent.Alignment = StringAlignment.Far
        msngCurrentValue -= msngAnnualDepreciation
        ev.Graphics.DrawString(s, mfntPrint, _
            Brushes.Black, recCurrent, sfCurrent)
        mintCurrentYear += 1


        Call DrawStringInBox(ev, cintCol1Start, msngYPos, _
                          cintColWidth, msngYPos + msngFontHeight, _
                      "Year")
        Call DrawStringInBox(ev, cintCol2Start, msngYPos, _
            cintColWidth, msngYPos + msngFontHeight, "Start Value")
        Call DrawStringInBox(ev, cintCol3Start, msngYPos, _
            cintColWidth, msngYPos + msngFontHeight, "Depreciation")
        Call DrawStringInBox(ev, cintCol4Start, msngYPos, _
            cintColWidth, msngYPos + msngFontHeight, "End Value")




        msngInitialValue = ToSingle(txtInitialValue.Text)
        msngSalvageValue = ToSingle(txtSalvageValue.Text)
        mintAssetLife = ToInt32(txtAssetLife.Text)
        msngTotalDepreciation = msngInitialValue - msngSalvageValue
        msngAnnualDepreciation = msngTotalDepreciation / mintAssetLife
        msngCurrentValue = msngInitialValue
        msngPage = 1
        mintCurrentYear = 1








    End Sub
End Class

Please just copy the lines give errors not all your application!!! and provide us with exception\error raised!!

I did have what errored at the very top of my post and said it says it is not defined. Each one of the To statements is what is erroring.

msngInitialValue = ToSingle(txtInitialValue.Text)
msngSalvageValue = ToSingle(txtSalvageValue.Text)
mintAssetLife = ToInt32(txtAssetLife.Text)

I included everything to make sure something wasn't wrong somewhere else. Sorry.

you should to use convert.
repair your code with following code :

msngInitialValue = Convert.ToSingle(txtInitialValue.Text)
msngSalvageValue = Convert.ToSingle(txtSalvageValue.Text)
mintAssetLife = Convert.ToInt32(txtAssetLife.Text)

ok. hope this helps.

Thanks Jx_Man, I will try that .

It still stays that those aren't defined.

huh?? i was try and i did not get any error..
that error message "aren't defined" for the code i post? or for other code??

I did have what errored at the very top of my post and said it says it is not defined..

What is not defined: Convert.ToSingle or a variable name? I've glanced over your code, but you never declare txtInitialValue,txtSalvageValue and txtAssetLife

Please post the exact compilererror

Niek

msngInitialValue = ToSingle(txtInitialValue.Text)
msngSalvageValue = ToSingle(txtSalvageValue.Text)
mintAssetLife = ToInt32(txtAssetLife.Text).Text)

When I debug everything after the = sign is not declared.

What do I need to do to correct that?

What do I need to do to correct that?

you need to do as Jx_Man suggest , use Convert.ToSingle

I did what Jx_Man suggested and I get that same thing when I debug it that everything after the = sign of those 3 statements is not defined. I guess I need to know how to define those 3.

I tried again what Jx_Man suggested and I know get this when I debug. Could it be how I declared the following:
(txtInitialValue.Text)
(txtSalvageValue.Text)
txtAssetLife.Text

Here is the error if you could explain what I am doing wrong.

An unhandled exception of type 'System.NullReferenceException' occurred in Startup06.exe

Additional information: Object reference not set to an instance of an object.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim txtInitialValue As TextBox
        Dim txtSalvageValue As TextBox
        Dim txtAssetLife As TextBox
        Dim ppdDepreciation As PrintDialog
        msngInitialValue = Convert.ToSingle(txtInitialValue.Text)
        msngSalvageValue = Convert.ToSingle(txtSalvageValue.Text)
        mintAssetLife = Convert.ToInt32(txtAssetLife.Text)

        msngTotalDepreciation = msngInitialValue - msngSalvageValue
        msngAnnualDepreciation = msngTotalDepreciation / mintAssetLife
        msngCurrentValue = msngInitialValue
        msngPage = 1
        mintCurrentYear = 1
        ppdDepreciation.ShowDialog()
    End Sub

You have some very basic problems here, some having to do with you not understanding defining an object and creating an instance of an object.

You also have some serious logic issues.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       '
       '    Without the "New" below you were simply defining objects. EMPTY objects!
       '    Adding "New" created Instances of the textboxes you defined
       '
        Dim txtInitialValue As [B]New [/B]TextBox
        Dim txtSalvageValue As [B]New [/B]TextBox
        Dim txtAssetLife As [B]New [/B]TextBox
        Dim ppdDepreciation As PrintDialog
       '
       '    The syntax below is correct, but the logic is flawed and will generate an 
       '    error. You can't convert the value of a control to anything if it is 
       '    nothing. This logic needs to be separated from the creation logic and 
       '    placed under another button on in some other tyoe of event.
       '
        msngInitialValue = [B]ctype(txtInitialValue.Text,single)[/B]        
        msngSalvageValue = [B]ctype(txtSalvageValue.Text,single)[/B]
        mintAssetLife = [B]ctype(txtAssetLife.Text,integer)[/B]

        msngTotalDepreciation = msngInitialValue - msngSalvageValue
        msngAnnualDepreciation = msngTotalDepreciation / mintAssetLife
        msngCurrentValue = msngInitialValue
        msngPage = 1
        mintCurrentYear = 1
        ppdDepreciation.ShowDialog()
    End Sub

I also did not go back and look at the rest of your code, so I'm not sure at all what you are attempting to do here, but you can't just create textboxes and not do some formatting and placement and expect to get anything useful (labels might be helpful as well!)

Also, if you are going to create textboxes on the fly, define the boxes in the scope of the class and only create the instances in the button_click routine.

If you don't mind me asking what does that ctype stand for. I am new to all of this and don't understand this print thing at all.

I am trying to get this to print a report when the user clicks the print report button. It should contain the Initial value, Salvage Value and Asset Life . I just want to understand what I am doing. I just started using VB.net so I am not too savvy on alot of things. Before I used that code somebody else suggested I was getting that the txt statements weren't defined.

I also did not go back and look at the rest of your code, so I'm not sure at all what you are attempting to do here, but you can't just create textboxes and not do some formatting and placement and expect to get anything useful (labels might be helpful as well!)

Also, if you are going to create textboxes on the fly, define the boxes in the scope of the class and only create the instances in the button_click routine.

CType(expression, typename)

Converts the expression to the specified type (highlight any command and hit F1 to get the help for it).

OK, if you want to open a new form to enter in print values, then build another form and show it, but don't try creating textboxes on the fly, particularly if you are going to try and pull values from them when they have nothing in them (the problem I mentioned with the code I gave you is that after we create the textboxes, you attempt to pull data out of them and convert it to a single. At that time the data is "", and empty string and cannot be converted to a number of any kind).

It wasn't that the txt controls were not defined, they were not instanciated. To get anywhere in .NET you have to understand the difference. Your code:

Dim txtInitialValue As TextBox

does not create an instance of a textbox. It basically says, "Hey, at some point in the future I might create a textbox using this name." It does not create a textbox.

Dim txtInitialValue As New TextBox

says create me a new textbox and call it this. "New" is the object constructor, it creates the instances of an object.

Ok, so how do I go back and fix this to make it print? I've tried several different things to define those but keep getting errors that it can't be single or double. Stuff like that.

I have the text boxes created by using the designer mode . Like I said I am new to this and don't quite understand it all.

Thanks for your great definition of that stuff though it made a bit more sense.

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.