The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
Diamond and align right using string manipulation help
Discuss Diamond and align right using string manipulation help in the Visual Basic Programming forum on Dev Shed. Diamond and align right using string manipulation help Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 15th, 2013, 08:58 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 19 m 44 sec
Reputation Power: 0
|
|
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?
|

January 15th, 2013, 12:35 PM
|
 |
Type Cast Exception
|
|
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
|
|
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
__________________
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.
|

January 15th, 2013, 03:03 PM
|
|
|
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
|

January 16th, 2013, 06:23 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 2
Time spent in forums: 19 m 44 sec
Reputation Power: 0
|
|
|
Thanks guy's for this.
I really appreciate it.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|