Results 1 to 9 of 9

Thread: how to 10 per line this code help newbie in vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    9

    how to 10 per line this code help newbie in vb.net

    help how to 10 per line this Name:  Screenshot (76).jpg
Views: 429
Size:  21.3 KBName:  Screenshot (74).jpg
Views: 479
Size:  25.3 KB
    pls help masters

  2. #2
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: how to 10 per line this code help newbie in vb.net

    Hi, but I'm not sure what you are actually looking for. I'm not sure what 10 per line means.

    Also, don't forget you can copy and paste code and use the [ code ] [ / code ] tags (no spaces).

    Assuming you want more than one number to appear on each line, it can be done this way, using a counter which counts how many numbers are being printed on the current line.

    vb Code:
    1. Dim NumbersOnLine As Integer = 0 ' Counts how many numbers there are on the current line.
    2. Dim Max As Integer = 10 ' How many numbers will be on one line.
    3.  
    4. For counter As Integer = 0 To 200
    5.     If counter Mod 5 = 0 OrElse counter Mod 6 = 0 Then
    6.         NumbersOnLine += 1
    7.         Console.Write(counter)
    8.         If NumbersOnLine < Max Then ' Continues the line.
    9.             Console.Write(", ")
    10.         Else
    11.             Console.WriteLine() ' Starts a new line if the numbers on that line has reached the max.
    12.             NumbersOnLine = 0
    13.         End If
    14.     End If
    15. Next
    16.  
    17. Console.ReadLine()

    There are obviously plenty of ways to accomplish this, this is just one way I chose.

    Good luck!
    ~Nic

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    9

    Re: how to 10 per line this code help newbie in vb.net

    Quote Originally Posted by NinjaNic View Post
    Hi, but I'm not sure what you are actually looking for. I'm not sure what 10 per line means.

    Also, don't forget you can copy and paste code and use the [ code ] [ / code ] tags (no spaces).

    Assuming you want more than one number to appear on each line, it can be done this way, using a counter which counts how many numbers are being printed on the current line.

    vb Code:
    1. Dim NumbersOnLine As Integer = 0 ' Counts how many numbers there are on the current line.
    2. Dim Max As Integer = 10 ' How many numbers will be on one line.
    3.  
    4. For counter As Integer = 0 To 200
    5.     If counter Mod 5 = 0 OrElse counter Mod 6 = 0 Then
    6.         NumbersOnLine += 1
    7.         Console.Write(counter)
    8.         If NumbersOnLine < Max Then ' Continues the line.
    9.             Console.Write(", ")
    10.         Else
    11.             Console.WriteLine() ' Starts a new line if the numbers on that line has reached the max.
    12.             NumbersOnLine = 0
    13.         End If
    14.     End If
    15. Next
    16.  
    17. Console.ReadLine()

    There are obviously plenty of ways to accomplish this, this is just one way I chose.

    Good luck!
    ~Nic
    Thank a lot master it works someday I will be easy for this thank man

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    9

    Re: how to 10 per line this code help newbie in vb.net

    [QUOTE=NinjaNic;5142741]Hi, but I'm not sure what you are actually looking for. I'm not sure what 10 per line means.

    Also, don't forget you can copy and paste code and use the [ code ] [ / code ] tags (no spaces).

    Assuming you want more than one number to appear on each line, it can be done this way, using a counter which counts how many numbers are being printed on the current line.

    vb Code:
    1. Dim NumbersOnLine As Integer = 0 ' Counts how many numbers there are on the current line.
    2. Dim Max As Integer = 10 ' How many numbers will be on one line.
    3.  
    4. For counter As Integer = 0 To 200
    5.     If counter Mod 5 = 0 OrElse counter Mod 6 = 0 Then
    6.         NumbersOnLine += 1
    7.         Console.Write(counter)
    8.         If NumbersOnLine < Max Then ' Continues the line.
    9.             Console.Write(", ")
    10.         Else
    11.             Console.WriteLine() ' Starts a new line if the numbers on that line has reached the max.
    12.             NumbersOnLine = 0
    13.         End If
    14.     End If
    15. Next
    16.  
    17. Console.ReadLine()

    There are obviously plenty of ways to accomplish this, this is just one way I chose.

    Good luck!
    ~Nic
    Attached Images Attached Images  
    Last edited by TABILIN; Feb 23rd, 2017 at 10:54 PM.

  5. #5
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: how to 10 per line this code help newbie in vb.net

    Well, I don't think I should do the code for you.
    But I have an idea of how you should approach this.

    Create an array of [1, 2, 3, 4, 5, 6] and print it out.
    Use a for loop 6 times, decrementing each number by 1.
    If the number is 0, do not decrement it.
    When printing out, if the number is zero, print a space.

    Good luck! If you have some code written down, I would be more than happy to help critique it.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    9

    Re: how to 10 per line this code help newbie in vb.net

    Thank I got the algorithm

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2017
    Posts
    9

    Re: how to 10 per line this code help newbie in vb.net

    Quote Originally Posted by NinjaNic View Post
    Well, I don't think I should do the code for you.
    But I have an idea of how you should approach this.

    Create an array of [1, 2, 3, 4, 5, 6] and print it out.
    Use a for loop 6 times, decrementing each number by 1.
    If the number is 0, do not decrement it.
    When printing out, if the number is zero, print a space.

    Good luck! If you have some code written down, I would be more than happy to help critique it.
    ey bro what the problem of this when I run this code
    Sub Main()
    Dim i, j As Integer
    For i = 1 To 6
    For j = 1 To i
    Console.Write(j & " ")
    Next
    Console.WriteLine()
    Next
    Console.ReadKey()
    End Sub


    1
    12
    123
    1234
    12345
    123456

    instead of this: pls help me bro I want to pass this day
    123456
    12345
    1234
    123
    12
    1
    help me bro I wanto sumbit this casestudy huhu!

  8. #8
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: how to 10 per line this code help newbie in vb.net

    In your code you are still incrementing the loop counter from 1 to 6, you need to decrement it from 6 to 1 as NinjaNic suggested.

  9. #9
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: how to 10 per line this code help newbie in vb.net

    Quote Originally Posted by PlausiblyDamp View Post
    In your code you are still incrementing the loop counter from 1 to 6, you need to decrement it from 6 to 1 as NinjaNic suggested.
    Yeah, exactly. Your output is backwards because of this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width