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

  • Home
  • SEARCH
  • 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 831039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:08:27+00:00 2026-05-15T04:08:27+00:00

i have : vb code: Private Sub Calculation() Dim txt1 As Decimal txt1 =

  • 0

i have :

vb code:

    Private Sub Calculation()

     Dim txt1 As Decimal
            txt1 = (CS_Incoms_done.Text / CS_Incoms_target.Text) * 100
            CS_Incom_Result.Text = "%" + FormatNumber(txt, 2, TriState.False)

            Dim txt2 As Decimal
            txt2 = (CS_GovernmentService_done.Text / CS_GovernmentService_target.Text) * 100
            CS_GovernmentService_Result.Text = "%" + FormatNumber(txt2, 2, TriState.False)

            Dim txt3 As Decimal
            txt3 = (CS_RentBox_done.Text / CS_RentBox_target.Text) * 100
            CS_RentBox_Result.Text = "%" + FormatNumber(txt3, 2, TriState.False)

Dim txt4 As Decimal
            txt4 = (CS_ServiceAdvertising_done.Text / CS_ServiceAdvertising_target.Text) * 100
            CS_ServiceAdvertising_Result.Text = "%" + FormatNumber(txt4, 2, TriState.False)

  Dim txt5 As Decimal
            txt5 = (CS_ServiceCatogray_done.Text / CS_ServiceCatogray_target.Text) * 100
            CS_ServiceCatogray_Result.Text = "%" + FormatNumber(txt5, 2, TriState.False)
    End Sub

i just show you 5 textbox's of 100 textbox's …. and don’t want to complete all the textbox's like this … i want a simple code to do it..

… as you notice , every three textbox's are look a like on the first two parts of their id's..~

for example –> CS_ServiceCatogray _Result.Text, CS_ServiceCatogray _done.Text and CS_ServiceCatogray _target.Text…

~..and the last part is the same in all textbox’s for geving the Result ..> _Result.Text , _done.Text and _target.Text

So… i had an idea to take the id and put the Similar two parts in an array… and use For Each something like:

Dim allItems As Array
        For Each item As Control In panel4.Controls
            Select Case item.[GetType]().Name
                Case "TextBox"

                    'here just be sure that this item is not saved in the allItems array ,if it is not  do >>'
                    allItems[Last_Item_Saved_Index+1] = DirectCast(item, TextBox).ID ',  i want  to save just the two Similar parts of the textboxs ids'


'i am not sure if this completely correct, but i wanted to do something like it['
                    Dim partOFtxt As String = allItems[Last_Item_Saved_Index]

                    Dim txt As Decimal = (partOFtxt + "_done.Text") / (partOFtxt + "_target.Text")

                    (partOFtxt + "_Result.Text") = "%" + FormatNumber(txt, 2, TriState.False)  ']'
                    'end condition'

                    Exit Select
                Case Else
        Exit Select
            End Select
        Next

i hope that you get the idea..

if you have a better idea … it would be nice..

Thanks in advance..

  • 1 1 Answer
  • 1 View
  • 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-15T04:08:28+00:00Added an answer on May 15, 2026 at 4:08 am

    Here is the short and sweet code which gives the same result as given by your answer. Feel free if need clarification.

    Private Sub Calculation()
        Dim CurParent As ContainerControl = Me
        For Each item As Control In CurParent.Controls
            Dim decZeroResult As Decimal = 0
            Select Case item.GetType().Name.ToUpper
                Case "LABEL"
                    Dim ControlName As String
                    Dim ResultControl As Control = item
                    ControlName = ResultControl.Name
                    If ControlName.ToUpper.EndsWith("_RESULT") Then
                        Dim ControlPartName As String = Mid(ControlName, 1, ControlName.Length - 7)
                        Dim TargetControl As TextBox = Nothing
                        Dim DoneControl As TextBox = Nothing
                        Dim controlsFound() As Control
                        controlsFound = CurParent.Controls.Find(ControlPartName & "_Target", True)
                        If controlsFound.Length > 0 Then
                            TargetControl = controlsFound(0)
                        End If
                        controlsFound = CurParent.Controls.Find(ControlPartName & "_Done", True)
                        If controlsFound.Length > 0 Then
                            DoneControl = controlsFound(0)
                        End If
                        If TargetControl IsNot Nothing And DoneControl IsNot Nothing Then
                            If TargetControl.Text > 0 Then
                                decZeroResult = FormatNumber(((DoneControl.Text / TargetControl.Text) * 100), 1, TriState.False)
                            Else
                                decZeroResult = 0
                            End If
                            ResultControl.Text = decZeroResult & " %"
                        End If
                    End If
            End Select
    
        Next
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 465k
  • Answers 465k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To match three or more occurrences of 1, I would… May 16, 2026 at 1:26 am
  • Editorial Team
    Editorial Team added an answer solution is add an extra class dialogaddSeasons and use rules… May 16, 2026 at 1:26 am
  • Editorial Team
    Editorial Team added an answer Afaik the only way is to use @SuppressWarnings("unchecked"). At least… May 16, 2026 at 1:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.