954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

string format

Option Explicit On
Option Strict On
Public Class workschedule
    Public Sub Start()
        Dim choice As Integer = -1
        While (choice <> 0)
            WriteMenuText()
            choice = Convert.ToInt32(Console.ReadLine)
            Select Case choice
                Case 0
                Case 1
                    Week()
                    Exit Select
                Case 2
                    Nights()
            End Select
        End While
    End Sub
    Public Sub WriteMenuText()

        Console.WriteLine("-------------------------------------------------------")
        Console.WriteLine("                       Work schedule ")
        Console.WriteLine("-------------------------------------------------------")
        Console.WriteLine("      Weekend to work                         :1")
        Console.WriteLine("      Nights to work                          :2")
        Console.WriteLine("      Exit                                    :0")
        Console.WriteLine("-------------------------------------------------------")
        Console.Write("Your choice ")
    End Sub
    Private Sub Week()
        Dim count As Integer = 52
        Dim p As Integer = 0
        Const cols As Integer = 6
        Dim montera As String = ""
        For i As Integer = 6 To count Step 3

            montera += [String].Format("{1,2}", i)
            p += 1
            If (p >= cols) AndAlso (p Mod cols = 0) Then
                Console.WriteLine(montera)
                montera = ""
            End If
        Next
        Console.WriteLine(montera)
        Console.WriteLine("-------------------------------------------------------")
    End Sub
    Private Sub Nights()
        Dim count As Integer = 52
        Dim p As Integer = 0
        Const cols As Integer = 6
        Dim montera As String = ""
        For i As Integer = 1 To count Step 6

            montera += [String].Format("{0,10} {1,2}", i)
            p += 1
            If (p >= cols) AndAlso (p Mod cols = 0) Then
                Console.WriteLine(montera)
                montera = ""
            End If
        Next
        Console.WriteLine(montera)
        Console.WriteLine("-------------------------------------------------------")
    End Sub

End Class


i get a error on this line montera += [String].Format("{0,10} {1,2}", i) Index (zero based) must be greater than or equal to zero and less than the size of the argument list. what do i need to change so it can work?

i want it to look like this in week
6 9 12 15 18 21
24 and so on

Kalle21
Newbie Poster
12 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Why not just use

montera += i & " "

Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

You're missing your second argument in the format statement:

String.Format("{0,10} {1,2}", i, SOMETHING_GOES_HERE)
thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: