#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Question Diamond and align right using string manipulation help


    i can make a diamond and align right pattern using this code:

    Code:
    diamond :
        a = Mid("awesome", 4, 1)
             Print Space(20); a
        a = Mid("awesome", 3, 3)
             Print Space(18); a
        a = Mid("awesome", 2, 5)
             Print Space(16); a
        a = Mid("awesome", 1, 7)
             Print Space(14); a
        a = Mid("awesome", 2, 5)
             Print Space(16); a
        a = Mid("awesome", 3, 3)
             Print Space(18); a
        a = Mid("awesome", 4, 1)
             Print Space(20); a
    
    align right :
        a = Mid("awesome", 1, 7)
            Print Space(10); a
        a = Mid("awesome", 2, 6)
            Print Space(12); a
        a = Mid("awesome", 3, 5)
            Print Space(14); a
        a = Mid("awesome", 4, 4)
            Print Space(16); a
        a = Mid("awesome", 5, 3)
            Print Space(18); a
        a = Mid("awesome", 6, 2)
            Print Space(20); a
        a = Mid("awesome", 7, 1)
            Print Space(22); a
    I want to make it in a loop, but i cant figure out how to.
    anyone have ideas?
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    I'd scrap the example code on the assignment and do it without all the unnecessary nonsense myself.

    Just make one single "awesome" string and iterate through it

    Code:
    strVar = "awesome"
    For n=1 to len(strVar)
       a = mid(strVar, n, 1)
     ' etc
    Next

    Comments on this post

    • ragefour agrees
    Last edited by medialint; January 15th, 2013 at 12:37 PM.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Code:
    Option Explicit
    Const s As String = "awesome"
    
    Private Function AlignRight(iPtr As Integer) As String
        AlignRight = Space(8 + 2 * iPtr) & Mid(s, iPtr, 8 - iPtr)
    End Function
    
    Private Function Diamond(iPtr As Integer) As String
        Diamond = Space((iPtr + 6) * 2) & Mid(s, iPtr, 9 - 2 * iPtr)
    End Function
    
    Private Sub cmdAlignR_Click()
        Dim N%
        For N% = 1 To 7
            Print AlignRight(N%)
        Next N%
    End Sub
    
    Private Sub cmdDiamond_Click()
        Dim N%
        For N% = 4 To 1 Step -1
            Print Diamond(N%)
        Next N%
        For N% = 2 To 4
            Print Diamond(N%)
        Next N%
    End Sub
    J.A. Coutts

    Comments on this post

    • ragefour agrees
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    Thanks guy's for this.
    I really appreciate it.

IMN logo majestic logo threadwatch logo seochat tools logo