?
Solved

CREATE AN ARRAY FOR EXISTING CODE

Posted on 2008-02-12
6
Medium Priority
?
155 Views
Last Modified: 2010-04-30
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
Comment
Question by:samandrew
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

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

Author Comment

by:samandrew
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

by:
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

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 77

Expert Comment

by:GrahamSkan
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

Open in new window

0
 
LVL 77

Expert Comment

by:GrahamSkan
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

Open in new window

0
 

Author Closing Comment

by:samandrew
ID: 31430125
Many Thanks

Andy
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question