2013-06-25 51 views
0

我有兩個文本框的Txtmark和TxtName,數據輸入然後存儲在數組20個條目後顯示列表框顯示名稱和標記我想要做id添加額外的列有獎勵在vb.net的列表框中添加一個列和獎勵方案

高分90%及以上; 區別75%高達89%; 60%高達74%;和 通50%至59%, 一切是particpation

這是我的代碼至今:

'Enter scores - press to place value into Array 
Private Sub TxtMark_Enter(ByVal sender As System.Object, _ 
     ByVal e As KeyPressEventArgs) Handles TxtMark.KeyPress 


    Dim Mark As Double 
    Dim DataString As String 

    If e.KeyChar = ControlChars.Cr Then 

     If Double.TryParse(TxtMark.Text, Mark) = False Then 
      MessageBox.Show(" You must enter a numeric value like 1 or 2") 
      TxtMark.Clear() 
      TxtMark.Focus() 
      Exit Sub 
     End If 

     If Mark < 0 Or Mark > 100 Then 
      MessageBox.Show("Valid range is between 0 and 100, 7 would work " _ 
       & Mark.ToString & " Does not") 
      TxtMark.Clear() 
      TxtMark.Focus() 
      Exit Sub 
     End If 



     If NumberOfScores < MaxEntries Then 
      ScoreArray(NumberOfScores) = Mark 

      DataString = (NumberOfScores + 1).ToString + ". " + _ 
       NameArray(NumberOfScores).PadRight(15) + _ 
    Mark.ToString.PadLeft(5) 
      ListBox1.Items.Add(DataString) 
      NumberOfScores += 1 
     End If 
     TxtMark.Clear() 
     TxtName.Clear() 
     TxtName.Focus() 
     Exit Sub 

    End If 


    If ListBox1.Items.Count >= 20 Then 
     ListBox1.Visible = True 
    Else 
     ListBox1.Visible = False 
    End If 
+0

它是一個任務:

要點擊一個按鈕,而不是加獎?請澄清你的問題! – Alaa

+0

是的,這是一個任務,我需要在列表框中添加一個額外的列,顯示「獎」,例如,如果bary得到67那麼他的獎將是一個信用,這有助於 – Binglee2323

+0

嘗試使用標點符號。這會讓你更容易理解你的問題。 – Mark

回答

0

由於列表框沒有任何的實際列,你真正的意思是添加到您的datastring這樣的信息出現欄目化

添加一個函數來標記轉換爲獎勵是這樣的:

Private Function NewAward(Mark As Double) As String 
    Select Case Mark 
     Case 90 To 100 
      Return "High Distinction" 
     Case 75 To 89 
      Return "Distinction" 
     Case 60 To 74 
      Return "Credit" 
     Case 50 To 59 
      Return "Pass" 
     Case Else 
      Return "Participation" 
    End Select 
End Function 

然後讓你的DataString這樣的:

DataString = (NumberOfScores + 1).ToString + ". " + _ 
       NameArray(NumberOfScores).PadRight(15) + _ 
    Mark.ToString.PadLeft(5) + " - " + NewAward(Mark) 

UPDATE:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 

    For I = 0 To ListBox1.Items.Count - 1 
     Dim TempString As String = ListBox1.Items(I).ToString 
     Dim Mark As Double = Double.Parse(TempString.Substring(TempString.Length - 5)) 
     TempString += " - " + NewAward(Mark) 
     ListBox1.Items.RemoveAt(I) 
     ListBox1.Items.Insert(I, TempString) 
    Next 
End Sub 
+0

謝謝你這麼多tinstaafl – Binglee2323

+0

非常歡迎 – tinstaafl

+0

你知道如何才能獲得僅在按下按鈕時添加的獎勵 – Binglee2323