Results 1 to 7 of 7

Thread: Really easy question, but very frustrating. Newbie alert

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Really easy question, but very frustrating. Newbie alert

    Hello people, first time poster.

    I have been fooling with vb for a couple of weeks now and have a question.
    I need help coding, and i know its probably right in front of me. If i were to design a program that would let me enter the size of a diamond and then drawn a diamond of that size using only odd numbers
    like the diamond size is 9 and the drawing would look like

    *
    * * *
    * * * * *
    * * * * * * *
    * * * * * * * * * - this is where the 9 input would go
    * * * * * * *
    * * * * *
    * * *
    *
    this is just a little fun project on the side, but i wanted to see if i could do it
    the output can be in console, message box, or list box

    I know how do declare variables and to check for valid entries

    in advance thanks for you help.

    Simon

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Really easy question, but very frustrating. Newbie alert

    This is how I would do it:

    VB Code:
    1. Public Shared Function CreateTextDiamond(ByVal MaximumValue As Integer) As String
    2.         Dim Diamond As String
    3.  
    4.         'Build Increasing Half
    5.         For I As Integer = 1 To MaximumValue Step 2
    6.             'Append(add) a string made of '*' I long and add a new line to Diamond
    7.             Diamond &= New String("*"c, I) & ControlChars.CrLf
    8.         Next
    9.         'Build Decreasing Half
    10.         'We Need to subtract 2 from MaxiumValue otherwise there wil be two lines MaximumValue Long
    11.         For D As Integer = (MaximumValue - 2) To 1 Step -2
    12.             'Append(add) a string made of '*' I long and add a new line (Crlf)
    13.             Diamond &= New String("*"c, D) & ControlChars.CrLf
    14.         Next
    15.         'Done return the generated Diamond
    16.         Return Diamond
    17.     End Function

    Usage:

    VB Code:
    1. Msgbox (CreateTextDiamond(9))
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Re: Really easy question, but very frustrating. Newbie alert

    Thanks for your help, but i think thats is a more complicated than i was thinking. On my design i have a textbox for input, a calculate button so when you press it then i either need a message box or a list box shows that shows the diamond. I was reading in abook about loops, can this be done using loops starting with the "Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click" code


    Thanks again for your help
    sorry if this is lame

  4. #4
    Hyperactive Member gjon's Avatar
    Join Date
    Nov 2004
    Location
    Inescapable Void
    Posts
    442

    Re: Really easy question, but very frustrating. Newbie alert

    Quote Originally Posted by rasdak24
    Thanks for your help, but i think thats is a more complicated than i was thinking. On my design i have a textbox for input, a calculate button so when you press it then i either need a message box or a list box shows that shows the diamond. I was reading in abook about loops, can this be done using loops starting with the "Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click" code


    Thanks again for your help
    sorry if this is lame
    He is using a loop. 2 of them. They are For Next loops that are counting by twos.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Re: Really easy question, but very frustrating. Newbie alert

    thanks for all your help people, I am still not getting what i am looking for, but i do thank you for your help. can this be put into a do while loop using a button click thanks

  6. #6
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Really easy question, but very frustrating. Newbie alert

    Here is a complete copy-and-paste sample

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.     End Sub
    4.  
    5.     Public Shared Function CreateTextDiamond(ByVal MaximumValue As Integer) As String
    6.         Dim Diamond As String
    7.  
    8.         'Build Increasing Half
    9.         For I As Integer = 1 To MaximumValue Step 2
    10.             'Append(add) a string made of '*' I long and add a new line to Diamond
    11.             Diamond &= New String("*"c, I) & ControlChars.CrLf
    12.         Next
    13.         'Build Decreasing Half
    14.         'We Need to subtract 2 from MaxiumValue otherwise there wil be two lines MaximumValue Long
    15.         For D As Integer = (MaximumValue - 2) To 1 Step -2
    16.             'Append(add) a string made of '*' I long and add a new line
    17.             Diamond &= New String("*"c, D) & ControlChars.CrLf 'Diamond
    18.         Next
    19.         'Done return the generated Diamond
    20.         Return Diamond
    21.     End Function
    22.  
    23.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    24.         Dim sValue As String = InputBox("What Number?")
    25.  
    26.         If IsNumeric(sValue) Then
    27.             Dim iValue As Integer = Integer.Parse(sValue)
    28.             MsgBox(CreateTextDiamond(iValue))
    29.         Else
    30.             MsgBox("you did not enter a valued numeric expression!")
    31.         End If
    32.     End Sub
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    4

    Talking Re: Really easy question, but very frustrating. Newbie alert

    Thanks thats exactly what i needed.

    Thank you very much

    simon

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