Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:12:52+00:00 2026-05-17T16:12:52+00:00

VB beginner here. My For… Next Loop will not work and I cannot for

  • 0

VB beginner here. My For… Next Loop will not work and I cannot for the life of me figure out why. I have tried to display the results in a label and a text box with multiline enabled. Doesn’t seem to matter. It’s probably something obvious I have been overlooking for 2 hours. Thanks in advance for any help.

Option Explicit On
Option Strict On
Option Infer Off

Public Class Form1

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub displayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles displayButton.Click

        Dim monthly As Double
        Dim results As Double
        Dim interest As Double

        ''#clear textbox results
        displayLabel.Text = String.Empty
        monthlyTextBox.Text = String.Empty

        ''#calculate the monthly payment due

        monthly = -Financial.Pmt(0.06 / 12, 12, 5000)
        monthlyTextBox.Text = monthly.ToString("C2")

        ''#calculate the amounts applied to principal and interest
        For per As Integer = 12 To 1 Step -1
            results = -Financial.PPmt(0.06 / 12, per, 12, 5000)
            interest = monthly - results
            displayLabel.Text = results.ToString("C2") & "   " & interest.ToString("C2") & ControlChars.NewLine
        Next per

        displayLabel.Focus()
    End Sub

End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:12:53+00:00Added an answer on May 17, 2026 at 4:12 pm

    The problem is in two parts:

    1. Your code is running in the GUI thread – that is, the thread that your textbox or label control uses to repaint itself to the screen. This means the control can’t redraw itself to show updated results until your entire method has finished.
    2. You write over the entire contents of the .Text property rather than append to it on each loop iteration.

    Taken together, what you see when your code runs is the result of 12 iterations. It just happens to look very much like running one iteration.

    In this case, I’m not sure problem 1 is a big deal. This is a quick enough operation and it looks like seeing all the results at once might be what you intend. Just be aware of the issue for the future. For item #2, I’d write the loop like this:

    ''#calculate the amounts applied to principal and interest
    Dim resultText As New Text.StringBuilder()
    For per As Integer = 12 To 1 Step -1
        results = -Financial.PPmt(0.06 / 12, per, 12, 5000)
        interest = monthly - results
        resultText.AppendFormat("{0:C2}  {1:C2}{2}", results, interest, Environment.NewLine)
    Next per
    displayLabel.Text = resultText.ToString()
    

    We can improve upon this further by taking advantage of the format string to control spacing and make everything line up nice, rather than just inserting a couple spaces between terms. Try plugging this string into your .AppendFormat() call:

    {0,12:C2}{1:C2}{2}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner here. Why is this an endless loop ? for (p = 0; p
Beginner here, I have a simple question. In Android what would be the best
(R beginner here...) I have a dataset like: > head(q) Date Time System User
Haskell beginner here. I want to pass a type parameter with JSON, and have
jQuery beginner here. Here is what I'm working on. I have an area map
Django advanced beginner here. I'm banging my head against the wall trying to figure
SQL beginner here. I have a query which takes around 10 seconds to run,
Complete prolog beginner here. Let's say I have a prolog knowledge base which contains
iOS beginner here. I have the following code: [facebook authorize:nil delegate:self]; NSString *string1=[facebook accessToken];
Beginner programmer here. So bear with me. I have a simple python program. print

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.