3

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.

Damian
  • 5,152
  • 1
  • 10
  • 21
  • 1
    Yes, it is possible to [loop through all the properties](https://stackoverflow.com/q/19783180/11683). It will probably not help you though. There is nothing wrong with setting properties individually, especially to different values. – GSerg Oct 10 '19 at 09:36
  • Thank you @GSerg for the info, but yeah... This won't help me since I need to assign them. Shame that this can't be done :( – Damian Oct 10 '19 at 09:47
  • It can be done, with [`CallByName`](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/callbyname-function), using the fetched property names. It's just that it will hardly make your code better. – GSerg Oct 10 '19 at 09:50

0 Answers0