Solved

# CREATE AN ARRAY FOR EXISTING CODE

Posted on 2008-02-12
Medium Priority
155 Views
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
0
Question by:samandrew
• 3
• 2

LVL 26

Expert Comment

ID: 20874175
can you explain further what you wish to accomplish? in your code, only txtMorEst is an array.
0

Author Comment

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

Many Thanks
Andy
0

LVL 77

Accepted Solution

GrahamSkan earned 2000 total points
ID: 20874205
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
``````
0

LVL 77

Expert Comment

ID: 20874212
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
``````
0

LVL 77

Expert Comment

ID: 20874224
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
``````
0

Author Closing Comment

ID: 31430125
Many Thanks

Andy
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
###### Suggested Courses
Course of the Month5 days, 1 hour left to enroll