不计算或显示MessageBox(Not Calculating or Showing MessageBox)
我有一个我在VB工作的任务。 我附上了以下作业:
(我会附上图片,但我不能,因为我是新用户)
作业问题
( http://i.imgur.com/LPZre2F.jpg )
我已经编写了所有代码但由于某种原因我无法获得计算按钮来计算任何东西。 当NameTextBox或PieceTextBox中没有输入时,我是否可以在“计算”按钮中显示消息框。
有人能发现一些我错过的东西,为什么这可能不起作用?
Public Class Form1 'Declare Variables Dim Pieces As Integer Dim AmtEar As Decimal Dim NoPieces As Decimal = 0 Dim totPay As Decimal = 0 Dim avgPay As Decimal = 0.0 'Declare Confirm Message Variable Dim confirmOpt As DialogResult Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Try 'Declare constant rates paid out Const priceRate1 As Decimal = 0.5 Const priceRate2 As Decimal = 0.55 Const priceRate3 As Decimal = 0.6 Const priceRate4 As Decimal = 0.65 'Check the blank fields (name and number of pieces) If NameTextBox.Text = "" Then MessageBox.Show("Please Enter Name:") Else If PieceTextBox.Text = "" Then MessageBox.Show("Please Enter Number of Pieces Produced") Else 'Count number of pieces NoPieces += 1 'Read number of pieces Pieces = Integer.Parse(PieceTextBox.Text) 'Use select case for given constraints 'calculate earned amount for each Select Case Pieces Case 1 To 199 AmtEar = priceRate1 * Pieces totPay += AmtEar Case 200 To 399 AmtEar = priceRate2 * Pieces totPay += AmtEar Case 400 To 599 AmtEar = priceRate3 * Pieces totPay += AmtEar Case Is >= 600 AmtEar = priceRate4 * Pieces totPay += AmtEar Case Else MessageBox.Show("Number of Pieces Produced Must Be Numeric") End Select 'Display amount earned AmtTextBox.Text = AmtEar.ToString("C") End If End If 'Exception for wrong input Catch ex As FormatException MessageBox.Show("Enter Valid Data", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try End Sub Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryButton.Click 'calculates summary total If (NoPieces >= 1) Then 'calculate and update total pieces, total pay and average pay avgPay = totPay / NoPieces TotalProducedTextBox.Text = NoPieces.ToString() TotlPayTextBox.Text = NoPieces.ToString("C") AveragePayTextBox.Text = avgPay.ToString("C") Else 'Otherwise display message MessageBox.Show("Enter at Least One Employee Data", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click 'Clear name and number of pieces NameTextBox.Clear() PieceTextBox.Clear() AmtTextBox.Clear() End Sub Private Sub ClearAllButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearAllButton.Click 'If no data is available If NoPieces = 0 Then MessageBox.Show("No Data Available To Delete") Else 'Confirm option message confirmOpt = MessageBox.Show("Are You Sure You Want To Delete Summary", "Confirm", MessageBoxButtons.YesNo) 'Check if yes then clear all inputs and totals If confirmOpt = DialogResult.Yes Then avgPay = 0 totPay = 0 NoPieces = 0 NameTextBox.Clear() PieceTextBox.Clear() AmtTextBox.Clear() TotalProducedTextBox.Clear() TotlPayTextBox.Clear() AveragePayTextBox.Clear() End If End If End Sub End Class
I have an assignment I have been working on in VB. I have attached the assignment below:
(I would've attached the image but I cannot because I am a new user)
Assignment Question
(http://i.imgur.com/LPZre2F.jpg)
I have written all of the code but for some reason I cannot get the calculate button to calculate anything. Nor, can I get the messagebox to show in the Calculate button when there is no input in the NameTextBox or the PieceTextBox.
Can someone spot something that I am missing on why this may not be working?
Public Class Form1 'Declare Variables Dim Pieces As Integer Dim AmtEar As Decimal Dim NoPieces As Decimal = 0 Dim totPay As Decimal = 0 Dim avgPay As Decimal = 0.0 'Declare Confirm Message Variable Dim confirmOpt As DialogResult Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Try 'Declare constant rates paid out Const priceRate1 As Decimal = 0.5 Const priceRate2 As Decimal = 0.55 Const priceRate3 As Decimal = 0.6 Const priceRate4 As Decimal = 0.65 'Check the blank fields (name and number of pieces) If NameTextBox.Text = "" Then MessageBox.Show("Please Enter Name:") Else If PieceTextBox.Text = "" Then MessageBox.Show("Please Enter Number of Pieces Produced") Else 'Count number of pieces NoPieces += 1 'Read number of pieces Pieces = Integer.Parse(PieceTextBox.Text) 'Use select case for given constraints 'calculate earned amount for each Select Case Pieces Case 1 To 199 AmtEar = priceRate1 * Pieces totPay += AmtEar Case 200 To 399 AmtEar = priceRate2 * Pieces totPay += AmtEar Case 400 To 599 AmtEar = priceRate3 * Pieces totPay += AmtEar Case Is >= 600 AmtEar = priceRate4 * Pieces totPay += AmtEar Case Else MessageBox.Show("Number of Pieces Produced Must Be Numeric") End Select 'Display amount earned AmtTextBox.Text = AmtEar.ToString("C") End If End If 'Exception for wrong input Catch ex As FormatException MessageBox.Show("Enter Valid Data", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try End Sub Private Sub SummaryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryButton.Click 'calculates summary total If (NoPieces >= 1) Then 'calculate and update total pieces, total pay and average pay avgPay = totPay / NoPieces TotalProducedTextBox.Text = NoPieces.ToString() TotlPayTextBox.Text = NoPieces.ToString("C") AveragePayTextBox.Text = avgPay.ToString("C") Else 'Otherwise display message MessageBox.Show("Enter at Least One Employee Data", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click 'Clear name and number of pieces NameTextBox.Clear() PieceTextBox.Clear() AmtTextBox.Clear() End Sub Private Sub ClearAllButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearAllButton.Click 'If no data is available If NoPieces = 0 Then MessageBox.Show("No Data Available To Delete") Else 'Confirm option message confirmOpt = MessageBox.Show("Are You Sure You Want To Delete Summary", "Confirm", MessageBoxButtons.YesNo) 'Check if yes then clear all inputs and totals If confirmOpt = DialogResult.Yes Then avgPay = 0 totPay = 0 NoPieces = 0 NameTextBox.Clear() PieceTextBox.Clear() AmtTextBox.Clear() TotalProducedTextBox.Clear() TotlPayTextBox.Clear() AveragePayTextBox.Clear() End If End If End Sub End Class
原文:https://stackoverflow.com/questions/22748283
最满意答案
尝试使用2列的行,并将文本和图片放在单独的列中,如下所示:
<div class="row"> <div class="col-sm-12 col-xs-12 col-md-4"> <h2><span style="font-family: 'Open Sans'; font-size: 200px">01</span> Wikipedia Viewer </h2> </div> <div class="col-sm-12 col-xs-12 col-md-8"> <img class="img-responsive" src="images/ipad.png"> </div> </div>
您可以在以下链接中找到演示代码: https : //jsfiddle.net/Djav/m93p7ove/1/
Try a row with 2 columns and put text and picures in seperate columns like this:
<div class="row"> <div class="col-sm-12 col-xs-12 col-md-4"> <h2><span style="font-family: 'Open Sans'; font-size: 200px">01</span> Wikipedia Viewer </h2> </div> <div class="col-sm-12 col-xs-12 col-md-8"> <img class="img-responsive" src="images/ipad.png"> </div> </div>
You can find a demo code in the below link: https://jsfiddle.net/Djav/m93p7ove/1/
相关问答
更多-
这是你在追求什么? 我将标题改为h3 (标题)标签,因为它比使用div更具语义选择性。 现场演示#1 现场演示#2 (顶部有标题,不确定是否需要) HTML:很容易使用float:left并且不打破红色边框div的高度。 您只需将display:table-cell添加到.app_top块。 这是解决方案: .app_top { display: table-cell; } .app_top img { float: left; } 查看工作示例。 这是代码 。 It is easy to use float: left and NOT break the height of red border div. You only have to a ...
使文本浮动:左侧和图片浮动:右侧以及移动友好(Make text float: left and picture float:right along with being mobile friendly)[2023-01-22]
尝试使用2列的行,并将文本和图片放在单独的列中,如下所示:01 Wikipedia Viewer
浮动左侧间距(Float Left Spacing)[2022-04-28]
好的,既然你已经熟悉了clearfix概念,那你就错了。 以这种方式更改代码,在.clearfix包含float ed元素: