Link to home
Start Free TrialLog in
Avatar of samandrew
samandrew

asked on

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
Avatar of ee_rlee
ee_rlee
Flag of Philippines image

can you explain further what you wish to accomplish? in your code, only txtMorEst is an array.
Avatar of samandrew
samandrew

ASKER

hI
I want to make txtMorActS.Text an array and execute the code as above.

Many Thanks
Andy
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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

Many Thanks

Andy