Jump to content
DDTRON

Média de uma coluna de um  ListView

Recommended Posts

DDTRON

Srs ,

Alguém poderia me ajudar a resolver esse probleminha :

Preciso tirar a média da ultima coluna :

 ListView1.ListItems.Item(1).ListSubItems.Add.Text = TextGrafico.Text

 

Agradeço desde já

Edited by DDTRON

Share this post


Link to post
Share on other sites
miglaranjeira

De acordo com o teu post, penso que será na coluna 1

    Dim media As Double
        Dim contador As Integer
        contador = 0
        media = 0
        For Each item1 As ListViewItem In ListView1.Items
            contador = contador + 1
            media = media + CDbl(item1.SubItems(1).Text)
        Next

        media = media / contador


        MsgBox(media)

 

Share this post


Link to post
Share on other sites
miglaranjeira

Boa tarde

Se já tens definido anteriormente item1, renomeia para

 Dim media As Double
        Dim contador As Integer
        contador = 0
        media = 0
        For Each item_media As ListViewItem In ListView1.Items
            contador = contador + 1
            media = media + CDbl(item_media.SubItems(1).Text)
        Next

        media = media / contador


        MsgBox(media)

 

Share this post


Link to post
Share on other sites
DDTRON

Olá miglaranjeira ,

 

Muito obrigado pela dica ... veja como ficou  :

'Calculando média da coluna
'***********************************************************************************************
'***********************************************************************************************
For i = 1 To FrmDesvio.ListView1.ListItems.Count
valor = valor + CDbl(FrmDesvio.ListView1.ListItems(i).ListSubItems(1))
Next i
TextMedia.Text = (Round(valor / FrmDesvio.ListView1.ListItems.Count, 4))
'***********************************************************************************************
 

Edited by DDTRON

Share this post


Link to post
Share on other sites
DDTRON
1 minuto atrás, DDTRON disse:

Olá miglaranjeira ,

 

Muito obrigado pela dica ... veja como ficou  :

'Calculando média da coluna
'***********************************************************************************************
'***********************************************************************************************
For i = 1 To FrmDesvio.ListView1.ListItems.Count
valor = valor + CDbl(FrmDesvio.ListView1.ListItems(i).ListSubItems(1))
Next i
TextMedia.Text = (Round(valor / FrmDesvio.ListView1.ListItems.Count, 4))
'***********************************************************************************************
 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.