Click here to Skip to main content
15,888,521 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: I am trying to port this code from VBScript to C# Pin
oblondel7-Mar-18 3:16
oblondel7-Mar-18 3:16 
QuestionTab control event Pin
hmanhha25-Feb-18 3:07
hmanhha25-Feb-18 3:07 
AnswerRe: Tab control event Pin
phil.o25-Feb-18 3:14
professionalphil.o25-Feb-18 3:14 
AnswerRe: Tab control event Pin
Ralf Meier25-Feb-18 22:27
mveRalf Meier25-Feb-18 22:27 
QuestionGetting an "Index was outside the bounds of the array" Error Message Pin
Member 1369355623-Feb-18 12:11
Member 1369355623-Feb-18 12:11 
AnswerRe: Getting an "Index was outside the bounds of the array" Error Message Pin
Richard Deeming23-Feb-18 13:11
mveRichard Deeming23-Feb-18 13:11 
PraiseRe: Getting an "Index was outside the bounds of the array" Error Message Pin
Member 1369355623-Feb-18 14:23
Member 1369355623-Feb-18 14:23 
GeneralRe: Getting an "Index was outside the bounds of the array" Error Message Pin
Richard Deeming26-Feb-18 0:56
mveRichard Deeming26-Feb-18 0:56 
OK, it looks like you're using the "first full week" rule, with weeks starting on Sunday.
VB.NET
Private Shared Function NumberOfWeeksInYear(ByVal year As Integer) As Integer
    Dim lastDayOfYear As New Date(year, 12, 31)
    Return System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(lastDayOfYear, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Sunday)
End Function
VB.NET
Private Sub Build_FromToLists()
    Dim wkList(0 To 208) As String
    Dim year1 As Integer = Year(Now) - 2
    Dim wkIndex As Integer = 0
    Dim currFweek As Long = MID_GetCurrFiscalWeek()
    Dim currFweekIndex As Integer = 0
    
    For yr = year1 To year1 + 3
        Dim weeksInYear As Integer = NumberOfWeeksInYear(yr)
        For wk = 1 To weeksInYear
            wkList(wkIndex) = CStr(yr) & " Wk" & Format(wk, "00")
            If (yr * 100) + wk = currFweek Then currFweekIndex = wkIndex
            wkIndex += 1
        Next wk
    Next yr
    
    cboTime_From.Items.AddRange(wkList)
    cboTime_To.Items.AddRange(wkList)
    
    If currFweekIndex > 0 Then
        cboTime_From.SelectedIndex = currFweekIndex - 1
        cboTime_To.SelectedIndex = currFweekIndex
    End If
End Sub


Member 13693556 wrote:
One question, from the lines in the error message, how did you know to target the array declaration as being the source of the problem?

The error message said "Index was outside the bounds of the array". The line it was thrown from only had a single array access, to wkList. From there, it was just a case of working out the maximum value for wkIndex, and comparing it to the declared length of the array. Smile | :)



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Getting an "Index was outside the bounds of the array" Error Message Pin
Member 1369355626-Feb-18 5:53
Member 1369355626-Feb-18 5:53 
QuestionOpen a file in a process already running Pin
Member 1361289622-Feb-18 9:36
Member 1361289622-Feb-18 9:36 
AnswerRe: Open a file in a process already running Pin
Dave Kreskowiak22-Feb-18 16:31
mveDave Kreskowiak22-Feb-18 16:31 
GeneralRe: Open a file in a process already running Pin
Member 1361289622-Feb-18 22:33
Member 1361289622-Feb-18 22:33 
GeneralRe: Open a file in a process already running Pin
Dave Kreskowiak23-Feb-18 2:14
mveDave Kreskowiak23-Feb-18 2:14 
SuggestionRe: Open a file in a process already running Pin
Richard Deeming23-Feb-18 0:57
mveRichard Deeming23-Feb-18 0:57 
GeneralRe: Open a file in a process already running Pin
Dave Kreskowiak23-Feb-18 2:15
mveDave Kreskowiak23-Feb-18 2:15 
QuestionIntegrate Excel worksheet in Windows form Pin
Frankie_M22-Feb-18 2:55
Frankie_M22-Feb-18 2:55 
AnswerRe: Integrate Excel worksheet in Windows form Pin
A_Griffin22-Feb-18 3:22
A_Griffin22-Feb-18 3:22 
GeneralRe: Integrate Excel worksheet in Windows form Pin
Frankie_M22-Feb-18 3:48
Frankie_M22-Feb-18 3:48 
AnswerRe: Integrate Excel worksheet in Windows form Pin
Alan Burkhart2-Mar-18 6:39
Alan Burkhart2-Mar-18 6:39 
Questionvb.net : How to open a form full screen Pin
desanti19-Feb-18 14:29
desanti19-Feb-18 14:29 
AnswerRe: vb.net : How to open a form full screen Pin
Eddy Vluggen19-Feb-18 17:15
professionalEddy Vluggen19-Feb-18 17:15 
QuestionBackup and restore sql server databases using SMO - How to make it work for all sql server versions Pin
desanti18-Feb-18 11:04
desanti18-Feb-18 11:04 
AnswerRe: Backup and restore sql server databases using SMO - How to make it work for all sql server versions Pin
Eddy Vluggen18-Feb-18 13:41
professionalEddy Vluggen18-Feb-18 13:41 
GeneralRe: Backup and restore sql server databases using SMO - How to make it work for all sql server versions Pin
desanti18-Feb-18 17:06
desanti18-Feb-18 17:06 
GeneralRe: Backup and restore sql server databases using SMO - How to make it work for all sql server versions Pin
Eddy Vluggen19-Feb-18 1:01
professionalEddy Vluggen19-Feb-18 1:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.