Results 1 to 7 of 7

Thread: Probably a Dumb Newbie Question!!

  1. #1

    Thread Starter
    Banned
    Join Date
    Mar 2000
    Posts
    7
    OK, I am just learning.

    I want to be able to print this when
    a command button is clicked:

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********

    But I have to use a ForNext Loop...
    Can someone please help me?


  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374
    Why do you need a For...Next loop? Unless you need that for
    a specific reason, try this
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
    Dim i As Single, J As Single
    
    For i = 1 To 10
        For J = 1 To i
            Text1.Text = Text1.Text & "*"
        Next
        If i <> 10 Then Text1.Text = Text1.Text & vbNewLine
    Next
    
    End Sub

  3. #3
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177

    Talking

    It's been a while since I've done this coding. This must be for school? The coding below is the ForNext loop you want, however I'm not sure if it will print the information on seperate lines. I do know you must set your textbox multiline property to true. I'm thinking this coding will work though, if not let me know, because I know I have the coding somewhere. You caught me at work without my dope books.

    Dim i as integer
    Dim Message as String

    For i = 1 to 10 step 1

    Message = Message + "*"

    Next

    Text1.text = Message

    212 will lead you to the truth

  4. #4
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217

    Talking Actually it sounds like its an assigned project(school)

    That would make the for next make sense. But I think he means to output into a picturebox control, hence:

    'start a 10 step for next loop
    For x = 1 To 10
    For y = 1 To x
    'print x number of stars, the ; makes it print on the same line
    picbox.Print "*";
    Next y
    'print a blank so that it moves to the first line
    picbox.Print ""
    Next x

    Also there are better ways to do this, but this way is low key and easy to understand
    Chris

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

  5. #5
    Addicted Member
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    177
    DrewDog has the right idea. I know I was doing it wrong. It's been a while since I've done that one. Sorry.
    212 will lead you to the truth

  6. #6

    Thread Starter
    Banned
    Join Date
    Mar 2000
    Posts
    7

    Thank you

    thanks guys! I had forgotten about printing a blank!

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    I think this is the shortest way:
    Code:
    For i = 1 to 10
        Text1.Text = Text1.Text & String(i,"*") & VbCRLF
    Next

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