【发布时间】:2014-10-08 21:00:04
【问题描述】:
我是 vb 的初学者,我要为每 100 个商店销售额显示一个 *;但是,在循环中是重印之前输入的值。谢谢你的帮助。
我想添加如下列表:
- 商店 1:**
- 商店 2 *****
每个 * = 100
Public Class Exercise6
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const intNumberOfDays As Integer = 5 'days
Dim intSales As Decimal = 0 'to hold daily sales
Dim strUserInput As String 'to hold user input
Dim strAsterisks As String = "" 'Asterisks
Const intAsterisk As Integer = 100
Dim intAsteriskTotal As Integer
Dim strDataOut As String = String.Empty 'holds the list output
Dim intCounter As Integer = 1
'gets sales for 5 stores
Do While intCounter <= intNumberOfDays
strUserInput = InputBox("Enter the sales for store" &
intCounter.ToString(), "Store Sales is Needed")
If strUserInput <> String.Empty And IsNumeric(strUserInput) Then
intSales = CInt(strUserInput)
'calculate the number of asterisk that must be display
intAsteriskTotal = CInt(intSales / intAsterisk)
strAsterisks = New String(CChar("*"), intAsteriskTotal)
'add the store to the output string
strDataOut &= "Store " & intCounter.ToString() & ": " & strAsterisks
'add the output to the list box
lstChart.Items.Add(strDataOut)
intCounter += 1
Else
MessageBox.Show("Please enter a proper value for store sales.")
End If
Loop
End Sub
End Class
【问题讨论】:
标签: vb.net