4 Replies - 184 Views - Last Post: 11 December 2018 - 08:24 AM Rate Topic: -----

#1 price58   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-December 18

code drops out of sub to early

Posted 11 December 2018 - 05:33 AM

I'm not sure what is going on here, part of the way through the sub the program drops out of the sub to early with no Exit Sub. When i in my loop "For i = 0 to 32" gets to 32, line 25 my code goes no father, it just drops out of the code. Here is my code....

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        cmbYear.Text = Date.Now.Year
        cmbDept.Text = "Facility"
        Dim i As Integer
        For i = 0 To 1
            cmbYear.Items.Add(Date.Now.Year + i)
        Next

        cmbDept.Items.Add("Facility")

        dgvJan.ColumnCount = 32
        dgvJan.Rows.Add(35)
        dgvJan.CurrentCell.Selected = False
        With dgvJan
            .Columns(0).HeaderCell.Value = "Employee"
            For i = 0 To 32
                .Columns(0).Width = 200
                .Columns(i).Width = 50
                .Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns(i).HeaderCell.Style.Font = New Font("Ariel", 10, FontStyle.Bold)
                .Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns(i).DefaultCellStyle.Font = New Font("Arial", 9, FontStyle.Bold)
                If i < dJan + 1 Then .Columns(i + 1).HeaderText = "01/" & i + 1
            Next i  'Drops out here when i gets to 32

            Dim sdate As String = .Columns(1).HeaderCell.Value & "/" & cmbYear.Text
            MsgBox(sdate)

        End With

    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: code drops out of sub to early

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14691
  • View blog
  • Posts: 58,718
  • Joined: 12-June 08

Re: code drops out of sub to early

Posted 11 December 2018 - 06:23 AM

Put a try/catch in there. Most likely ab out of bounds issue.
Was This Post Helpful? 0
  • +
  • -

#3 price58   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-December 18

Re: code drops out of sub to early

Posted 11 December 2018 - 06:42 AM

Thanks, that was the problem, index out of bounds.
Was This Post Helpful? 0
  • +
  • -

#4 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 671
  • Joined: 01-October 08

Re: code drops out of sub to early

Posted 11 December 2018 - 06:43 AM

Try putting the code in the .Shown event. The .Load event likes to swallow errors.
Was This Post Helpful? 0
  • +
  • -

#5 price58   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-December 18

Re: code drops out of sub to early

Posted 11 December 2018 - 08:24 AM

I will, thanks....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1