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 8258173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:26:57+00:00 2026-06-08T02:26:57+00:00

Have started a paper on C++ and have, what most experienced C++ programmers would

  • 0

Have started a paper on C++ and have, what most experienced C++ programmers would call, a small problem…

I am using Visual Studio 2008 and coding in Visual C++ with .NET. I am trying to code the tiniest of applications that will add a new line into a textbox everytime a button is clicked. Adding new lines is simple enough, but I am wanting to add an incrementing integer with each line, e.g if I click on a button the first time, “This is line 1” gets added into the textbox, and on second click “This is line 2” gets added into the textbox. I am a little rusty on my programming and can’t think of a looping structure that will enable this.

Here is the code (with some pseudocode) for the button’s handler below:

private: System::Void addLine_Click(System::Object^  sender, System::EventArgs^  e) {

    int i = 0;
    if(button is clicked){
      listBox->Items->Add("This is line " + i);
      i++;
    }

}

Should output something like: 

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
             .
             .
             .
This is line i

The name of my button is “addLine” and the name of the list box I want these lines to appear in is called “listBox”.

Thanks in advance for helping this C++ noob :).

  • 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-06-08T02:26:58+00:00Added an answer on June 8, 2026 at 2:26 am

    i is a local variable so it will loose its scope whenever the function exits. Either you need to declare i as static or make it as a class variable.

    private: System::Void addLine_Click(System::Object^  sender, System::EventArgs^  e) {
    
        static int i = 0;
        if(button is clicked){
          listBox->Items->Add("This is line " + i);
          i++;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using WSO2 Stratos live and started using WSO2 data services server.
I have started using SqLite recently, so I am relatively new to it. I
I have started using https://github.com/omab/django-social-auth and been successfully able to login via twitter, google
I have started developing a new Rails app on my server using RVM, Rails
I have started learning GWT and I would like to know if it is
I have started experimenting with codeigniter and pdfs. I'm using the latest version of
I have started developing a full-web application by using the ASP .NET MVC 3
I have started a jetty server in my remote server. But I got problem
I have started some code, and I would like to be able to enter
I currently work in a small business (15-20 employees, 5 programmers) where most projects

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.