Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 15th, 2013, 08:58 AM
ragefour ragefour is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 ragefour User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 44 sec
Reputation 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?

Reply With Quote
  #2  
Old January 15th, 2013, 12:35 PM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
Posts: 14,938 medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)  Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Months 2 Weeks 2 Days 13 m 33 sec
Reputation Power: 8490
Facebook
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!
__________________
medialint.com

“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

Last edited by medialint : January 15th, 2013 at 12:37 PM.

Reply With Quote
  #3  
Old January 15th, 2013, 03:03 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 165 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 16 h 28 m 34 sec
Reputation Power: 43
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!

Reply With Quote
  #4  
Old January 16th, 2013, 06:23 AM
ragefour ragefour is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 ragefour User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 44 sec
Reputation Power: 0
Thanks guy's for this.
I really appreciate it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Diamond and align right using string manipulation help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap