need help in while wend loop help me plz

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetzhay
    New Member
    • Sep 2009
    • 5

    need help in while wend loop help me plz

    this code i will have an output of
    1
    12
    123
    1234
    12345 when pressing command 1

    Private Sub Command1_Click( )

    Label1.Caption = Clear
    sides = 5
    rows = 1
    While rows <= sides
    Column = 0
    While Column < rows
    Column = Column + 1
    Label1 = Label1 & Column & Space(1)
    Wend
    Label1 = Label1 & vbCrLf
    rows = rows + 1
    Wend

    End Sub

    Now my problem is to get the output of
    1
    21
    321
    4321
    54321
    can anyone help me do this plz

    and also this one
    using 2 labels and 1 command button
    on the first label1 when u hit command button u will have this output
    2 4 6 8 10
    then in label 2
    1 3 5 7 9
    this is the even and odd project
    need help in a code.
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    The code below is written in VBA.

    I think it does what you have described, but not using While/Wend
    Code:
    Option Explicit
    Dim sides As Integer
        
    Private Sub Command1_Click()
        Dim i As Integer
        Dim j As Integer
        
        Label1.Caption = ""
        sides = 5
        For j = 1 To sides
            For i = 1 To j
                Label1 = Label1 & i & Space(1)
            Next i
            Label1 = Label1 & vbCrLf
        Next j
    End Sub
    
    Private Sub Command2_Click()
        Dim i As Integer
        Dim j As Integer
        
        Label1.Caption = ""
        sides = 5
        For j = sides - 1 To 0 Step -1
            For i = sides - j To 1 Step -1
                Label1 = Label1 & i & Space(1)
            Next i
            Label1 = Label1 & vbCrLf
        Next j
    End Sub
    
    Private Sub Command3_Click()
        Dim i As Integer
        
        Label1.Caption = ""
        Label2.Caption = ""
        sides = 10
        For i = 1 To sides
            If i Mod 2 = 0 Then
                Label1 = Label1 & i & Space(1)
            Else
                Label2 = Label2 & i & Space(1)
            End If
        Next i
    End Sub
    HTH

    MTB
    Last edited by debasisdas; Sep 2 '09, 05:47 PM. Reason: removed unnecessary quote.

    Comment

    • sweetzhay
      New Member
      • Sep 2009
      • 5

      #3
      wow great

      u dont have any idea on how to get it using while wend?

      so what if i want to get also this output

      ''''''''''''''' 1
      ''''''''''''12
      ''''''''''123
      '''''''1234
      ''''12345

      and also this one

      ''''''''''''''' ''''1
      ''''''''''''''' ''123
      ''''''''''''''1 2345
      '''''''''''1234 567
      ''''''''1234567 89
      this one is the diamond, disregard the ''''''''''''''' ''''''''


      does using FOR is also in looping thanks alot from helping

      Comment

      • kadghar
        Recognized Expert Top Contributor
        • Apr 2007
        • 1302

        #4
        actually any FOR can be converted into a While Wend statement

        For i = 1 to 5
        .....
        next i

        is the same as
        i=1
        while i <=5
        .....
        i=i+1
        wend

        Comment

        • sweetzhay
          New Member
          • Sep 2009
          • 5

          #5
          i am just a bit confused here coz in while wend i cannot use the STEP like u use in for the step - 1 im a having a hardtime to convert it

          For j = sides - 1 To 0 Step -1

          Comment

          • MikeTheBike
            Recognized Expert Contributor
            • Jun 2007
            • 640

            #6
            Originally posted by sweetzhay
            i am just a bit confused here coz in while wend i cannot use the STEP like u use in for the step - 1 im a having a hardtime to convert it

            For j = sides - 1 To 0 Step -1
            Hi again

            The code for your origional questions using While/Wend is as follows
            Code:
            Option Explicit
            Dim sides As Integer
                
            Private Sub Command1_Click()
                Dim i As Integer
                Dim j As Integer
                
                Label1.Caption = ""
                sides = 5
                j = 1
                While j <= sides
                    i = 1
                    While i <= j
                        Label1 = Label1 & i & Space(1)
                        i = i + 1
                    Wend
                    Label1 = Label1 & vbCrLf
                    j = j + 1
                Wend
            End Sub
            
            Private Sub Command2_Click()
                Dim i As Integer
                Dim j As Integer
                
                Label1.Caption = ""
                sides = 5
                j = sides - 1
                While j >= 0
                    i = sides - j
                    While i >= 1
                        Label1 = Label1 & i & Space(1)
                        i = i - 1
                    Wend
                    Label1 = Label1 & vbCrLf
                    j = j - 1
                Wend
            End Sub
            
            Private Sub Command3_Click()
                Dim i As Integer
                
                Label1.Caption = ""
                Label2.Caption = ""
                sides = 10
                i = 1
                While i <= sides
                    If i Mod 2 = 0 Then
                        Label1 = Label1 & i & Space(1)
                    Else
                        Label2 = Label2 & i & Space(1)
                    End If
                    i = i + 1
                Wend
                
            End Sub
            With regard your other questions, well, where do the permutations end !!

            Without wishing to seem unhelpful, I think you should have enough info now to try things yourself so you can do whatever is required in future. It is the only way to learn !!


            MTB

            Comment

            Working...