Is there any way to loop through class properties to fill them?

Viewed 54

So I'm writting some code which works perfectly but bothers me a lot:

For i = 3 To UBound(arr)
    If arr(i, 4) = 0 Then Exit For
    Login = arr(i, 4)
    Agentes.Logins(Login).Negocio = DatosAgente("NEGOCIO")
    Agentes.Logins(Login).Mes = DatosAgente("MES")
    Agentes.Logins(Login).Año = DatosAgente("AÑO")
    Agentes.Logins(Login).Modo = aDatosAgente("MODO")
    Agentes.Logins(Login).Coordinador = DatosAgente("COORDINADOR")
    Agentes.Logins(Login).Incorporacion = DatosAgente("FECHA INCORPORACIÓN")
    Agentes.Logins(Login).Antiguedad = DatosAgente("ANTIGÜEDAD")
    For j = 9 To UBound(arr, 2) Step 6
        Fecha = arr(1, j)
        Agentes.Logins(Login).Fechas(Fecha).VentasVerificadas = arr(i, Encabezados(Fecha & j))
        Agentes.Logins(Login).Fechas(Fecha).VentasCargadas = arr(i, Encabezados(Fecha & j + 1))
        Agentes.Logins(Login).Fechas(Fecha).Llamadas = arr(i, Encabezados(Fecha & j + 2))
        Agentes.Logins(Login).Fechas(Fecha).AHT = arr(i, Encabezados(Fecha & j + 3))
        Agentes.Logins(Login).Fechas(Fecha).TMO = arr(i, Encabezados(Fecha & j + 4))
        Agentes.Logins(Login).Fechas(Fecha).PorcentajeVerificadas = arr(i, Encabezados(Fecha & j + 5))
        Agentes.Logins(Login).Fechas(Fecha).PorcentajeCargadas = arr(i, Encabezados(Fecha & j + 6))
    Next j
Next i

As you can see, I need to manually input every single class property. I did a function for the first part, but wondered why bother if I have to write them all anyway.

Is it possible to loop through all the properties my class have and fill them so the code looks cleaner and I only need to use a couple of helper functions?

P.S: I've already asked on CodeReview and they told me to come here.

0 Answers
Related