none
Some Title Lines are equal to zero RRS feed

  • Question

  • My program in Visual Basic 2019 Detail Line Calculations are fine for my Straight Line Depreciation using a Listbox but, no error checking this time. On the other hand, my column line results On my Depreciable cost is $0.00 that is a wrong answer the correct answer is $60,000. The Depreciation Expense result is $0.00 that is the wrong answer the correct answer is $5,000.00. The Total Years answer is 0 but, the correct answer is 12. The Total Years Purchased answer is 0 but, the correct answer is 2031. The Accumulated Depreciation Result is $0.00 but, the correct answer is $60,000.00. The Book Value result is $0.00 but, the correct answer is $5,000.00. Can someone help me with this program that is easy for me to debug. Thank You

    Sincerely Yours,

    James Delorn Howland Jr.

    [Public Class Form1
    
    
        Private Sub BtnStrLineDeprec495f_Click(sender As Object, e As EventArgs) Handles BtnStrLineDeprec495f.Click
            Dim TxtAccountNo495A As Integer = 0
            Dim MaskedSocSecNo495A As String = "000-00-0000"
            Dim TxtCustName495A As String = "   "
            Dim TxtItemNumber495A As Integer = 0
            Dim TxtColorComboBox495A As String = "  "
            Dim TxtDescriptionName495A As String = "  "
            Dim TxtOrigPrice495A As Double = 0
            Dim TxtSalvageValue495A As Double = 0
            Dim TxtYears495A As Integer = 0
            Dim TxtYearPurchased495A As Integer = 0
    
    
            Dim TxtDepreciableCost495A As Double = 0
            Dim TxtDeprecExpense495A As Double = 0
            Dim TxtTotalYears495A As Integer = 0
            Dim TxtTotalYearsPurchased495A As Integer = 0
            Dim TxtAccumDeprec495A As Double = 0
            Dim TxtBookValue495A As Double = 0
            Dim TORIG As Double = 0
            'Dim DepCost495A As Double = 0
            TxtAccountNo495A = CInt(TxtAccountNo495.Text)
            MaskedSocSecNo495A = CStr(MaskedSocSecNo495.Text)
            TxtCustName495A = CStr(TxtCustName495.Text)
            TxtItemNumber495A = CInt(TxtItemNumber495.Text)
            TxtColorComboBox495A = CStr(TxtColorComboBox495.Text)
            TxtDescriptionName495A = CStr(TxtDescriptionName495.Text)
            TxtOrigPrice495A = CDbl(TxtOrigPrice495.Text)
            TxtSalvageValue495A = CDbl(TxtSalvageValue495.Text)
            TxtYears495A = CInt(TxtYears495.Text)
            TxtYearPurchased495A = CInt(TxtYearPurchased495.Text)
            TxtTotalYearsPurchased495A = TxtYearPurchased495A
    
    
    
    
            ListOutput495.Items.Add("Account Number        " & vbTab & TxtAccountNo495A & vbNewLine)
            ListOutput495.Items.Add("Social Security Number     " & vbTab & MaskedSocSecNo495A & vbNewLine)
            ListOutput495.Items.Add("Customer Name    " & vbTab & TxtCustName495A & vbNewLine)
            ListOutput495.Items.Add("Item Number       " & vbTab & TxtItemNumber495A & vbNewLine)
            ListOutput495.Items.Add("Item Color           " & vbTab & TxtColorComboBox495A & vbNewLine)
            ListOutput495.Items.Add("Item Name         " & vbTab & TxtDescriptionName495A & vbNewLine)
            ListOutput495.Items.Add("Original Price     " & vbTab & TxtOrigPrice495A.ToString("c2") & vbNewLine)
            ListOutput495.Items.Add("Salvage Value    " & vbTab & TxtSalvageValue495A.ToString("c2") & vbNewLine)
            ListOutput495.Items.Add("Estimated Years      " & vbTab & TxtYears495A & vbNewLine)
            ListOutput495.Items.Add("Year Purchased           " & vbTab & TxtYearPurchased495A & vbNewLine)
            ListOutput495.Items.Add("Depreciable Cost       " & vbTab & TxtDepreciableCost495A.ToString("c2"))
            ListOutput495.Items.Add("Depreciation Expense        " & vbTab & TxtDeprecExpense495A.ToString("c2"))
            ListOutput495.Items.Add("Total Years        " & vbTab & TxtTotalYears495A & vbNewLine)
            ListOutput495.Items.Add("Total Years Purchased        " & vbTab & TxtTotalYearsPurchased495A & vbNewLine)
            ListOutput495.Items.Add("Accumulated Depreciation        " & vbTab & TxtAccumDeprec495A.ToString("c2") & vbNewLine)
            ListOutput495.Items.Add("Book Value           " & vbTab & TxtBookValue495A.ToString("c2") & vbNewLine)
    
    
    
    
    
            ListOutput495.Items.Add("Total      Total Years     Original     Depreciation       Accumulated       Book     " & vbNewLine)
            ListOutput495.Items.Add("Years     Purchased       Price      Expense     Depreciation     Value    " & vbNewLine)
            ListOutput495.Items.Add("      ")
            TORIG = TxtOrigPrice495A
    
    
    
    
    
    
            For yr = 1 To TxtYears495A
                TxtDepreciableCost495A = TxtOrigPrice495A - TxtSalvageValue495A
    
                TxtDeprecExpense495A = TxtDepreciableCost495A / TxtYears495A
                TxtTotalYears495A += 1
                TxtTotalYearsPurchased495A += 1
                TxtAccumDeprec495A = TxtAccumDeprec495A + (TxtDepreciableCost495A / TxtYears495A)
                TxtBookValue495A = TxtOrigPrice495A - TxtAccumDeprec495A
                TxtBookValue495A = TORIG - TxtDeprecExpense495A
                ListOutput495.Items.Add(vbTab & TxtTotalYears495A & "     " & TxtTotalYearsPurchased495A & TORIG.ToString("C2") & "         " & TxtDeprecExpense495A.ToString("C2") & "        " & TxtAccumDeprec495A.ToString("c2") & "        " & TxtBookValue495A.ToString("c2") & vbNewLine)
                TORIG = TxtBookValue495A
            Next
    
    
    
    
    
    
            TxtAccountNo495.Text = CInt(TxtAccountNo495A)
            MaskedSocSecNo495.Text = CStr(MaskedSocSecNo495A)
            TxtCustName495.Text = CStr(TxtCustName495A)
            TxtItemNumber495.Text = CInt(TxtItemNumber495A)
            TxtColorComboBox495.Text = CStr(TxtColorComboBox495A)
            TxtDescriptionName495.Text = CStr(TxtDescriptionName495A)
            TxtOrigPrice495.Text = CDbl(TxtOrigPrice495A.ToString("c2"))
            TxtSalvageValue495.Text = CDbl(TxtSalvageValue495A.ToString("c2"))
            TxtYears495.Text = CInt(TxtYears495A)
            TxtYearPurchased495.Text = CInt(TxtYearPurchased495A)
            TxtDepreciableCost495.Text = CDbl(TxtDepreciableCost495A.ToString("c2"))
            TxtDeprecExpense495.Text = CDbl(TxtDeprecExpense495A.ToString("c2"))
            TxtTotalYears495.Text = CInt(TxtTotalYears495A)
            TxtTotalYearsPurchased495.Text = CInt(TxtTotalYearsPurchased495A)
            TxtAccumDeprec495.Text = CDbl(TxtAccumDeprec495A.ToString("c2"))
            TxtBookValue495.Text = CDbl(TxtBookValue495A.ToString("c2"))
        End Sub
    
        Private Sub BtnClear495_Click(sender As Object, e As EventArgs) Handles BtnClear495.Click
            TxtAccountNo495.Text = "  "
            MaskedSocSecNo495.Text = "  "
            TxtCustName495.Text = "   "
            TxtItemNumber495.Text = "  "
            TxtColorComboBox495.Text = "  "
            TxtDescriptionName495.Text = "  "
            TxtOrigPrice495.Text = "  "
            TxtSalvageValue495.Text = "  "
            TxtYears495.Text = "  "
            TxtYearPurchased495.Text = "  "
            TxtDepreciableCost495.Text = "  "
            TxtDeprecExpense495.Text = "  "
            TxtTotalYears495.Text =  "   "
            TxtTotalYearsPurchased495.Text = "  "
            TxtAccumDeprec495.Text = "  "
            TxtBookValue495.Text = "   "
            ListOutput495.Items.Clear()
        End Sub
    
        Private Sub BtnExit495_Click(sender As Object, e As EventArgs) Handles BtnExit495.Click
            Me.Close()
        End Sub
    End Class]
    

     

    JAMES DELORN HOWLAND JR.

    Sunday, December 1, 2019 7:48 PM

Answers

  • Hi

    There are too many controls included for me to want to try and recreate, so all I can say is:

    Put a break point on the line   For yr = 1 To TxtYears495A and when reached, single step through and examine the different values to see if they are as expected - if not, then chase back to see why not.

    It is all well and good to have meaningful control names, but it makes it difficult for third party to recreate for testing etc.


    Regards Les, Livingston, Scotland

    Sunday, December 1, 2019 8:18 PM
  • Hi,

    Sorry, your program is easy to debug, but I have a hard time understanding what each of your controls means and what you want to do. So I can't reproduce your problem.

    Could you share us a screen shot about your current result and explain it?

    Also, I agree with Leshay's suggestion that you can add breakpoints to debug the current program.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 2, 2019 1:55 AM
    Moderator
  • Can you give me examples of good control names? Thank You.

    I am not familiar with advanced techniques. I have been away from Visual Basic for quite awhile but, I will be getting back to writing code in Visual Basic 2019. Thank You.

    Sincerely Yours,

    James Delorn Howland Jr.


    JAMES DELORN HOWLAND JR.

    Wednesday, December 4, 2019 1:30 AM
  • Hello,

    I'm afraid you misunderstood me. I didn't think that the names of your controls were bad. Instead, they made sense.

    It ’s just that there are too many controls and the relationships between the variables are not very clear to me, so it will be difficult for me to reproduce your problem and understand your ideas.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 4, 2019 1:43 AM
    Moderator

All replies

  • Hi

    There are too many controls included for me to want to try and recreate, so all I can say is:

    Put a break point on the line   For yr = 1 To TxtYears495A and when reached, single step through and examine the different values to see if they are as expected - if not, then chase back to see why not.

    It is all well and good to have meaningful control names, but it makes it difficult for third party to recreate for testing etc.


    Regards Les, Livingston, Scotland

    Sunday, December 1, 2019 8:18 PM
  • Hi,

    Sorry, your program is easy to debug, but I have a hard time understanding what each of your controls means and what you want to do. So I can't reproduce your problem.

    Could you share us a screen shot about your current result and explain it?

    Also, I agree with Leshay's suggestion that you can add breakpoints to debug the current program.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 2, 2019 1:55 AM
    Moderator
  • Yes I would like that very much. Thank You.

    Sincerely Yours,

    James Delorn Howland Jr


    JAMES DELORN HOWLAND JR.

    Wednesday, December 4, 2019 1:24 AM
  • Can you give me examples of good control names? Thank You.

    I am not familiar with advanced techniques. I have been away from Visual Basic for quite awhile but, I will be getting back to writing code in Visual Basic 2019. Thank You.

    Sincerely Yours,

    James Delorn Howland Jr.


    JAMES DELORN HOWLAND JR.

    Wednesday, December 4, 2019 1:30 AM
  • Hello,

    I'm afraid you misunderstood me. I didn't think that the names of your controls were bad. Instead, they made sense.

    It ’s just that there are too many controls and the relationships between the variables are not very clear to me, so it will be difficult for me to reproduce your problem and understand your ideas.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 4, 2019 1:43 AM
    Moderator
  • Can you give me examples of good control names? Thank You.

    I am not familiar with advanced techniques. I have been away from Visual Basic for quite awhile but, I will be getting back to writing code in Visual Basic 2019. Thank You.

    Sincerely Yours,

    James Delorn Howland Jr.


    JAMES DELORN HOWLAND JR.

    Hi

    There are good reasons to have variable names that mean something to the programmer. The difficulties lie entirely with the reader who is not familiar with your particular naming convention, and, specifically when wanting to copy/paste the posted code to enable editing

    Depending on circumstances, it is better to use default control names. Like you, when I started I did use meaningful names, but as time passed, I found I could just as easily keep track of what each one was by using thr Designer view, and, it was much more straightforward too.


    Regards Les, Livingston, Scotland

    Wednesday, December 4, 2019 12:56 PM
  • How can I reduce my controls? I am sorry I am had tried to use the breakpoint constantly but, I had no success. Can you give some examples about controls? I learn better visually. When someone tells me to do something verbally it can very confusing to me. I can write the code again with meaningful variables. I will add comments next time. Thank You.

    Sincerely Yours,

    James Delorn Howland Jr.


    JAMES DELORN HOWLAND JR.

    Thursday, December 5, 2019 2:55 AM
  • How can I reduce my controls? I am sorry I am had tried to use the breakpoint constantly but, I had no success. Can you give some examples about controls? I learn better visually. When someone tells me to do something verbally it can very confusing to me. I can write the code again with meaningful variables. I will add comments next time. Thank You.

    Sincerely Yours,

    James Delorn Howland Jr.


    JAMES DELORN HOWLAND JR.

    Hi

    My suggestions regarding Controls, specifically for posting here, is to accept the default names as they are added in the Designer, That way, in the code, all references are easily seen - such as ListBox3.Items.Add( ....., TextBox7.Text=.......  etc., and so any reader can easily see what is needed in the Designer.

    It might be an idea to show the actual calculations required, and, although daunting if you haven't used them before, using Classes could simplify your task.

    *

    As for Debugging. You really really need to get to grips with the features available, maybe start HERE.

    As a simple example,

    Option Strict On
    Option Explicit On
    Public Class Form1
    	' store all books in a collection
    	Dim Books As New List(Of Book)
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
    		' add one Book
    		Dim MyBook As New Book With {.ID = "ABC123", .Title = "GoodFellas", .Description = "Good read, all about gabgsters in early America", .Cost = 19.5D, .Location = "Third Shelf, BookCase 12", .Purchased = Now}
    		Books.Add(MyBook)
    
    		' add another Book
    		Books.Add(New Book With {.ID = "HWQ786", .Title = "BadFellas", .Description = "Poor read, all about failed gabgsters in early America", .Cost = 9.5D, .Location = "First Shelf, BookCase 212", .Purchased = Now.AddDays(-111)})
    
    		' add some new Books with defaults
    		For i As Integer = 1 To 9
    			Books.Add(New Book)
    		Next
    
    		RichTextBox1.AppendText(Books(1).ToString)
    
    		RichTextBox1.AppendText(Books(7).ToString)
    
    	End Sub
    	Class Book
    		Property ID As String
    		Property Title As String
    		Property Description As String
    		Property Cost As Decimal
    		Property Location As String
    		Property Purchased As DateTime
    		Sub New()
    			' set defaults
    			ID = "Not Set"
    			Title = "UnKnown"
    			Description = "Waiting on Description"
    			Cost = 0.0D
    			Location = "New Books - first shelf, Bookcase 1"
    			Purchased = Now
    		End Sub
    
    		Public Overrides Function ToString() As String
    			' what to use for '.ToString'
    			Return "ID: " & ID & "  Title: " & Title & ",  " & Cost.ToString("[$0.00],") & vbCrLf & Description & "," & vbCrLf & "Location: " & Location & vbCrLf & "Purchased: " & Purchased.ToString("ddd, dd MMM yyyy") & vbCrLf & StrDup(20, "="c) & vbCrLf
    		End Function
    	End Class
    End Class


    Regards Les, Livingston, Scotland



    • Edited by leshay Thursday, December 5, 2019 2:48 PM Added code block
    Thursday, December 5, 2019 1:40 PM