CREATE AN ARRAY FOR EXISTING CODE

hI
I have the following code and would like to use this in an array of 6 txtboxs would anyone be able to give me some example code ?


Private Sub txtMorActS_Change()

If IsNumeric(txtMorEst(0).Text) And IsNumeric(txtMorActS.Text) Then
        If CDbl(txtMorActS.Text) < 0.00001 Then
            txtPercent.Text = "0"
        Else
            txtPercent.Text = Format(Val(txtMorActS.Text) - Val(txtMorEst(0).Text) / Val(txtMorActS.Text) * 100, "#0") & "%"
        End If
    End If

txtMorMixS.Text = Format$(txtMorEst(0).Text * 16 * 6 / 1925, "#0.0")


End Sub
samandrewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ee_rleeCommented:
can you explain further what you wish to accomplish? in your code, only txtMorEst is an array.
0
samandrewAuthor Commented:
hI
I want to make txtMorActS.Text an array and execute the code as above.

Many Thanks
Andy
0
GrahamSkanRetiredCommented:
Do you mean like this?
Private Sub txtMorActS_Change(Index As Integer)
    Dim i As Integer
    For i = 0 To 5
        If IsNumeric(txtMorEst(i).Text) And IsNumeric(txtMorActS.Text) Then
            If CDbl(txtMorActS.Text) < 0.00001 Then
                txtPercent.Text = "0"
            Else
                txtPercent.Text = Format(Val(txtMorActS.Text) - Val(txtMorEst(i).Text) / Val(txtMorActS.Text) * 100, "#0") & "%"
            End If
        End If
    
        txtMorMixS.Text = Format$(txtMorEst(i).Text * 16 * 6 / 1925, "#0.0")
    Next i
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

GrahamSkanRetiredCommented:
Or like this (now that I've seen your last comment)
Private Sub txtMorActS_Change(Index As Integer)
    If IsNumeric(txtMorEst(Index).Text) And IsNumeric(txtMorActS.Text) Then
        If CDbl(txtMorActS.Text) < 0.00001 Then
            txtPercent.Text = "0"
        Else
            txtPercent.Text = Format(Val(txtMorActS.Text) - Val(txtMorEst(Index).Text) / Val(txtMorActS.Text) * 100, "#0") & "%"
        End If
    End If
 
    txtMorMixS.Text = Format$(txtMorEst(Index).Text * 16 * 6 / 1925, "#0.0")
End Sub

Open in new window

0
GrahamSkanRetiredCommented:
Oops. txtMorActS needs indexing, too
Private Sub txtMorActS_Change(Index As Integer)
    If IsNumeric(txtMorEst(Index).Text) And IsNumeric(txtMorActS.Text) Then
        If CDbl(txtMorActS(Index).Text) < 0.00001 Then
            txtPercent.Text = "0"
        Else
            txtPercent.Text = Format(Val(txtMorActS(Index).Text) - Val(txtMorEst(Index).Text) / Val(txtMorActS(Index).Text) * 100, "#0") & "%"
        End If
    End If
 
    txtMorMixS.Text = Format$(txtMorEst(Index).Text * 16 * 6 / 1925, "#0.0")
End Sub

Open in new window

0
samandrewAuthor Commented:
Many Thanks

Andy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.