Generation of Hours with a for Visual Basic .net

1

I have this code that fills me in a datagrid with the hours every 15 minutes starting from 8 a.m.

How would I do if I want to generate the same hours but one more row per hour? ahem: in this case there would be two rows with 8 a.m. and two rows with 8:15 so on.

Private Horario4(52) As String

Private Sub LlenarHoras()
    Dim minuto As Integer
    Dim Horas As String = ""
    Dim contador As Integer
    For hora As Integer = 8 To 20
        For minuto = 0 To 45 Step 15
            If hora < 10 And minuto < 10 Then
                Horas = "0" + hora.ToString() + ":" + "0" + minuto.ToString()
            Else
                If hora < 10 And minuto >= 10 Then
                    Horas = "0" + hora.ToString() + ":" + minuto.ToString()
                Else
                    If hora >= 10 And minuto < 10 Then
                        Horas = "" + hora.ToString() + ":" + "0" + minuto.ToString()
                    Else
                        If hora >= 10 And minuto >= 10 Then
                            Horas = "" + hora.ToString() + ":" + minuto.ToString()
                        End If
                    End If
                End If
            End If
            Horario4(contador) = Horas
            contador = contador + 1
        Next
    Next 
End Sub
    
asked by Jose Salazar 24.04.2018 в 23:39
source

1 answer

0
  

You must duplicate the place where you assign the value to the schedule, and add two   times in the counter

Private Horario4(104) As String

Private Sub LlenarHoras()
    Dim minuto As Integer
    Dim Horas As String = ""
    Dim contador As Integer

    For hora As Integer = 8 To 20
        For minuto = 0 To 45 Step 15
            If hora < 10 And minuto < 10 Then
                Horas = "0" + hora.ToString() + ":" + "0" + minuto.ToString()
            Else
                If hora < 10 And minuto >= 10 Then
                    Horas = "0" + hora.ToString() + ":" + minuto.ToString()
                Else
                    If hora >= 10 And minuto < 10 Then
                        Horas = "" + hora.ToString() + ":" + "0" + minuto.ToString()
                    Else
                        If hora >= 10 And minuto >= 10 Then
                            Horas = "" + hora.ToString() + ":" + minuto.ToString()
                        End If
                    End If
                End If
            End If
            Horario4(contador) = Horas
            contador = contador + 1
            Horario4(contador) = Horas   'Aquí se duplica                
            contador = contador + 1  'y sumas otro

        Next
    Next 
End Sub
    
answered by 25.04.2018 в 00:16