Question:

How to add values in visual basic 2005 and 2008 ver only?

by  |  earlier

0 LIKES UnLike

hi, im a VB 2005 noob.

need help addign values in a label. the values are in a loop of 1 to 6 and i need help to show them added up in another label

 Tags:

   Report

2 ANSWERS


  1. you have to parse each label values to int or decimal...

    heres a sample:

    suppose you have 6 labels namely(label1, lable2, label3, etc),

    a labelSum as you result.

    int sum = 0;

    sum = sum + int.Parse(label1.Text);

    sum = sum + int.Parse(label2.Text;

    sum = sum + int.Parse(label3.Text;

    sum = sum + int.Parse(label4.Text;

    sum = sum + int.Parse(label5.Text;

    sum = sum + int.Parse(label6.Text;

    labelSum.Text = sum.toString();

    hope this helps.


  2. Dim Sum as Integer = 0

    For I as Integer = 1 to 6

       If Me.Controls(0).GetType.ToString = "System.Windows.Forms.Button" then

       sum += CType(Me.Control("Button" & I).Text, Integer)

       End If

    Next

    Print Sum

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.