Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303

    [VB.NET]Calcolo dei giorni tra mese corrente e successivo

    ho un problema nel codice seguente, praticamente se eseguo il seguente codice all' interno del mese questo esegue la sua funzione correttamente, ma logicamente se eseguo un' operazione a cavallo tra la fine e l'inizio del mese successivo questo vā in errore in quanto Date.DaysInMonth si trova al di fuori dei suoi giorni come posso gestire l' aggiunta di Date.DaysInMonth del mese successivo?

    txtnumero.Text č un numero di giorni

    codice:
                 ListBox6.Items.Clear()
                 For i As Integer = Mid(txtData.Text, 1, 2) To Date.DaysInMonth(Mid(Date.Today.Year, 3, 2), Date.Today.Month)
                    Dim d = i.ToString("00") & "/" & Date.Today.Month.ToString("00") & "/" & Mid(Date.Today.Year, 3, 2)
                    If Convert.ToDateTime(d).DayOfWeek <> DayOfWeek.Sunday Then
                        Application.DoEvents()
                        ListBox6.Items.Add(d)
                    End If
                Next
                For n As Integer = ListBox6.Items.IndexOf(ListBox6.Items(0)) To txtnumero.Text - 1
                    Application.DoEvents()
                    ExecSql("INSERT INTO ore VALUES ('" & ListBox6.Items.Item(n) & "','" & Me.CboAltro.Text & "','" & "**.**" & "','" & "**.**" & "','" & "06:00" & "')")
                Next

  2. #2
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    non sō se questo metodo sia corretto, ma comunque funziona:
    codice:
      ListBox1.Items.Clear()
            ListBox2.Items.Clear()
            Label1.Text = ""
    
            For i As Integer = Mid(TextBox1.Text, 1, 2) To Date.DaysInMonth(Mid(Date.Today.Year, 3, 2), Date.Today.Month)
                Dim d = i.ToString("00") & "/" & Date.Today.Month.ToString("00") & "/" & Mid(Date.Today.Year, 3, 2)
                If Convert.ToDateTime(d).DayOfWeek <> DayOfWeek.Sunday Then
                    Application.DoEvents()
                    ListBox1.Items.Add(d)
                End If
            Next
    
            For m As Integer = 1 To Date.DaysInMonth(Mid(Date.Today.Year, 3, 2), Date.Today.Month + 1)
                Dim s = m.ToString("00") & "/" & (Date.Today.Month + 1).ToString("00") & "/" & Mid(Date.Today.Year, 3, 2)
                If Convert.ToDateTime(s).DayOfWeek <> DayOfWeek.Sunday Then
                    Application.DoEvents()
                    ListBox1.Items.Add(s)
                End If
            Next
    
            For j As Integer = 1 To Date.DaysInMonth(Mid(Date.Today.Year, 3, 2), Date.Today.Month + 2)
                Dim k = j.ToString("00") & "/" & (Date.Today.Month + 2).ToString("00") & "/" & Mid(Date.Today.Year, 3, 2)
                If Convert.ToDateTime(k).DayOfWeek <> DayOfWeek.Sunday Then
                    Application.DoEvents()
                    ListBox1.Items.Add(k)
                End If
            Next
    
            For n As Integer = ListBox1.Items.IndexOf(ListBox1.Items(0)) To ComboBox1.Text - 1
                Application.DoEvents()
                Label1.Text = ListBox2.Items.Count + 1
                ListBox2.Items.Add(ListBox1.Items(n))
            Next
    Adesso perō mi si presenta il problema dell' anno nel senso che se sono tra la fine e l' inizio dell' anno il programma mi vā chiaramente in errore.
    Qualche suggerimento

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.