5 Replies - 183 Views - Last Post: 07 February 2012 - 01:28 PM Rate Topic: -----

Topic Sponsor:

#1 Kalle114  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 12

string format

Posted 07 February 2012 - 12:43 PM

    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


i get a erro 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?

Is This A Good Question/Topic? 0
  • +

Replies To: string format

#2 modi123_1  Icon User is offline

  • Suiter #2
  • member icon


Reputation: 3561
  • View blog
  • Posts: 14,989
  • Joined: 12-June 08

Re: string format

Posted 07 February 2012 - 12:54 PM

What do you believe you are trying to accomplish with this line?

[String].Format("{0,10} {1,2}", i)

Was This Post Helpful? 0
  • +
  • -

#3 Kalle114  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 12

Re: string format

Posted 07 February 2012 - 01:10 PM

im going to get that it looks like this

6 9 12 15 18 21
24 and so on
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suiter #2
  • member icon


Reputation: 3561
  • View blog
  • Posts: 14,989
  • Joined: 12-June 08

Re: string format

Posted 07 February 2012 - 01:18 PM

Okay.. so what do you believe "{0,10}" does? (with respects to string.format?)
Was This Post Helpful? 0
  • +
  • -

#5 Kalle114  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 01-February 12

Re: string format

Posted 07 February 2012 - 01:22 PM

in vb i really dont know i have converted it from my c# so thats way i need help to make it the way i wanted it to be
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suiter #2
  • member icon


Reputation: 3561
  • View blog
  • Posts: 14,989
  • Joined: 12-June 08

Re: string format

Posted 07 February 2012 - 01:28 PM

Have your fingers do some walk'n then! Head over and read up on what string.format does!

http://msdn.microsof...ing.format.aspx


string.format returns a string, right? It also allows you to setup placeholders in one string and fill them at run time!

Example:

string.format("hugs are for {0}", "thugs")


{0} is the place holder here.. and says the first of the items after the comma is to be filled in there.

You can do something like
string.format("hugs are for {0} but {1} have great hats!", "thugs", "cats")


See how the second element, "cats", would fill in to place holder {1}.

No go nuts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1