making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
Go Back  Xtreme Visual Basic Talk > > > making a blank space in a character shape based on user inputs


Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2015, 03:02 PM
grimmjow40 grimmjow40 is offline
Newcomer
 
Join Date: May 2015
Posts: 1
Default making a blank space in a character shape based on user inputs


Code:
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click        
        Dim charHeight, charWidth As Integer
        Dim blankH, blankW As Integer
        Dim shapeheight, shapeWidth As Integer
        Dim row, column, blankRow As Integer
        Dim character As String

        outputTextBox.Clear()

        charHeight = Int32.Parse(heightTextBox.Text) 
        charWidth = Int32.Parse(widthTextBox.Text)  
        blankH = Int32.Parse(blankHTextBox.Text)    
        blankW = Int32.Parse(blankWTextBox.Text)    
        character = charTextBox.Text
        shapeheight = CInt((charHeight - blankH) / 2)  
        shapeWidth = CInt((charWidth - blankW) / 2)
'I can get the code to make a rectangle or square, but not a smaller rectangle or square inside of it

Code:
For row = 1 To charHeight
            For column = 1 To charWidth
                For blankRow =
                outputTextBox.AppendText(" ")
                Next blankRow
                outputTextBox.AppendText(character)
            Next column
            outputTextBox.AppendText(vbCrLf)
        Next row
# # # # # # <-- This is what I get
# # # # # #
# # # # # #
# # # # # #
# # # # # #

# # # # # #
# # _ _ # #
# # _ _ # #
# # # # # #
# # # # # # <-- This is what I want when the user enters charHeight(5), charwidth(6), blankH(2) and blankW(2).

My brain is starting to stretch and hurt which is good, but it's killing me haha
Reply With Quote
  #2  
Old 05-28-2015, 01:00 PM
passel's Avatar
passelmaking a blank space in a character shape based on user inputs passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I think rather than have the nested loops and build it a character at a time,
I would use two strings, one representing a filled row, and the other a hollowed row.
Then I would just have a single loop, and append the appropriate row type to the string.
I used a Stringbuilder, since it is made for building up strings efficiently.

<edit> note below I didn't add the charTextBox so hardcoded the character. You will want to fix that.</edit>
Code:
  Private Sub displayButton_Click(sender As System.Object, e As System.EventArgs) Handles displayButton.Click
    Dim charHeight, charWidth As Integer
    Dim blankH, blankW As Integer
    Dim shapeheight, shapeWidth As Integer
    Dim row, column, blankRow As Integer
    Dim character As String

    outputTextBox.Clear()

    charHeight = Int32.Parse(heightTextBox.Text)
    charWidth = Int32.Parse(widthTextBox.Text)
    blankH = Int32.Parse(blankHTextBox.Text)
    blankW = Int32.Parse(blankWTextBox.Text)
    character = "#" 'charTextBox.Text
    shapeheight = CInt((charHeight - blankH) / 2)
    shapeWidth = CInt((charWidth - blankW) / 2)

    Dim sb As New System.Text.StringBuilder
    Dim fillRow As String = StrDup(charWidth, CChar(character))           'create the "######" string
    Dim hollowRow As String = StrDup(shapeWidth, CChar(character)) & Space(blankW)    'start the "## " string
    hollowRow = String.Concat(hollowRow, StrDup((charWidth - hollowRow.Length), CChar(character))) 'finish the "##  ##" string

    For row = 1 To charHeight
      If row <= shapeheight Or row > shapeheight + blankH Then
        sb.AppendLine(fillRow)
      Else
        sb.AppendLine(hollowRow)
      End If
    Next
    outputTextBox.Text = sb.ToString

  End Sub
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
 
making a blank space in a character shape based on user inputs
making a blank space in a character shape based on user inputs
 
-->