Results 1 to 8 of 8

Thread: [2005] Concatenate variable as char

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    34

    [2005] Concatenate variable as char

    For one of my programming classes, we're supposed to display an output as asterisks, with each asterisk representing the number 100. How do you set up a do while loop to convert the input number to an asterisk?

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2005] Concatenate variable as char

    I'm not sure I understand...

    Do you need to make:
    100 = ***
    58585 = *****
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Concatenate variable as char

    You will get the user's input probably from a textbox or a inputbox, which is a string, then convert it to an integer. Now divide this integer by 100 and you'll have the number of asterisks to display. Once you know how many asterisks are required, you create a string with that many asterisks and display it. There's no loop involved at all.

  4. #4

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    34

    Re: [2005] Concatenate variable as char

    Here I'll type you exactly what it says to do.

    Create an application that prompts the user to enter today's sales for five stores. The program should then display a simple bar graph comparing each store's sales. Create each bar in the bar graph by displaying a row of asterisks (*) in a list box. Each asterisk should represent $100 in sales.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    34

    Re: [2005] Concatenate variable as char

    here's what i have so far:

    Private Sub btnDisplay_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnDisplay.Click

    ' Gather sales information and display a bar chart.

    Dim intCount As Integer = 0 ' Loop counter
    Dim decSales As Decimal ' To hold sales for each store
    Dim strInput As String ' To get store information





    ' The following loop will get the sales amounts for each store.

    Do While intCount <= 4
    intCount += 1
    strInput = InputBox("Enter the sales for store # " & _
    intCount.ToString, "Sales Amount Needed")

    If strInput <> "" Then
    decSales = CDec(strInput) ' Store input in sales
    Else
    Exit Do
    End If

    strInput = "Store " & intCount & ":" & decSales.ToString()
    lstChart.Items.Add(strInput)


    Loop
    End Sub

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Concatenate variable as char

    For each of the values entered, divide the number by 100 (whole result) and create a string with that many asterisks in it. Add to listbox.

  7. #7
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: [2005] Concatenate variable as char

    Here's another hint... you can do this to make your asterisks:
    Code:
    Dim strS As String = String.Empty.PadRight(10, "*"c)
    Will produce: **********
    (10 asterisks)
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Concatenate variable as char

    Code:
            Dim testNums() As Decimal = {100.5D, 211, 312, 1000, 1510.45D}
            Dim testAster As String
            Debug.WriteLine("'Debug Output")
            For x As Integer = 0 To testNums.Length - 1
                testAster = String.Empty.PadRight(Convert.ToInt32(testNums(x) / 100), "*"c)
                'or
                'testAster = StrDup(Convert.ToInt32(testNums(x) / 100), "*"c)
                Debug.WriteLine("'" & testNums(x) & " " & testAster)
            Next
            'Debug Output
            '100.5 *
            '211 **
            '312 ***
            '1000 **********
            '1510.45 ***************
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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