帮朋友写的vb.net代码

http://edison.mohawkcollege.ca/access/course/co314/Labs/Lab5/Lab5.html
Public Class Form1
    
' Declare the arrays that will be used in the program

    
Dim strParams(2As String
    
Dim strParamN(9As String ' Actually 10 values 0 to 9
    Dim dblParamV(9As Double ' Actually 10 values 0 to 9

    
' Declare constants to be used for data validation 

    
Const dblMinpH As Double = 2
    
Const dblMaxpH As Double = 12
    
Const dblMinFlow As Double = 0
    
Const dblMaxFlow As Double = 2000
    
Const dblMinTSS As Double = 0
    
Const dblMaxTSS As Double = 100

    
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
Dim I As Short
        strParams(
0= "FLOW"
        strParams(
1= "PH"
        strParams(
2= "TSS"

        
' Add Array elements to the combo box

        
For I = 0 To 2
            cboID.Items.Add(strParams(I))
        
Next

        cboID.Text 
= strParams(0)

        
' Create the two data arrays with 10 values

        strParamN(
0= "TSS"
        dblParamV(
0= 11
        strParamN(
1= "FLOW"
        dblParamV(
1= 200
        strParamN(
2= "TSS"
        dblParamV(
2= 9.0
        strParamN(
3= "PH"
        dblParamV(
3= 8.1
        strParamN(
4= "PH"
        dblParamV(
4= 6.9
        strParamN(
5= "PH"
        dblParamV(
5= 7.5
        strParamN(
6= "FLOW"
        dblParamV(
6= 500
        strParamN(
7= "TSS"
        dblParamV(
7= 20.2
        strParamN(
8= "TSS"
        dblParamV(
8= 15.0
        strParamN(
9= "TSS"
        dblParamV(
9= 19.8
        
' NEED TO ADD CODE here at STEP 3
        For I = 0 To 9
            lstParam.Items.Add(strParamN(I))
        
Next
        
For I = 0 To 9
            lstValue.Items.Add(dblParamV(I))
        
Next
    
End Sub


    
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        
If IsNumeric(txtNum.Text) Then
            
' Data is numeric it can be converted to a number

            
' Add your code here for data validation 
            Dim number As Double = Val(txtNum.Text) 'Val()是vb内置的类型转换函数,能将字符串类型转换为双字节型
            If cboID.SelectedIndex = 0 Then 'Flow
                If number < dblMinFlow Then 'less than min
                    MessageBox.Show("Less than min"' MessageBox.Show()为vb内置的弹出提示框函数,能弹出指定内容以供用户查看
                ElseIf number > dblMaxFlow Then
                    MessageBox.Show(
"More then max")
                
Else
                    lstParam.Items.Add(
"FLOW")
                    lstValue.Items.Add(number)
                
End If
            
ElseIf cboID.SelectedIndex = 1 Then 'PH
                If number < dblMinpH Then 'less than min
                    MessageBox.Show("Less than min")
                
ElseIf number > dblMaxpH Then
                    MessageBox.Show(
"More then max")
                
Else
                    lstParam.Items.Add(
"PH")
                    lstValue.Items.Add(number)
                
End If
            
Else 'TSS
                If number < dblMinTSS Then 'less than min
                    MessageBox.Show("Less than min")
                
ElseIf number > dblMaxTSS Then
                    MessageBox.Show(
"More then max")
                
Else
                    lstParam.Items.Add(
"TSS")
                    lstValue.Items.Add(number)
                
End If
            
End If
        
Else
            
' Data is not numeric - Display an error message  
            MessageBox.Show("Must input a numeric value")
        
End If
    
End Sub


    
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        
Dim I As Integer
        
Dim flowCount As Integer = 0
        
Dim phCount As Integer = 0
        
Dim tssCount As Integer = 0
        
Dim flowSum As Double = 0
        
Dim phSum As Double = 0
        
Dim tssSum As Double = 0
        
For I = 0 To lstParam.Items.Count - 1 '循环读取所有listbox里的数据,然后根据类型添加到各自的总量和计数变量中
            If lstParam.Items.Item(I) = "FLOW" Then
                flowSum 
= flowSum + Val(lstValue.Items.Item(I))
                flowCount 
= flowCount + 1
            
ElseIf lstParam.Items.Item(I) = "PH" Then
                phSum 
= phSum + Val(lstValue.Items.Item(I))
                phCount 
= phCount + 1
            
Else
                tssSum 
= tssSum + Val(lstValue.Items.Item(I))
                tssCount 
= tssCount + 1
            
End If
        
Next
        txtFlowNum.Text 
= flowSum
        txtFlowAvg.Text 
= flowSum / flowCount
        txtpHNum.Text 
= phSum
        txtpHAvg.Text 
= phSum / phCount
        txtTSSNum.Text 
= tssSum
        txtTSSAvg.Text 
= tssSum / tssCount
    
End Sub


    
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        
Me.Close()
    
End Sub

End Class


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial 
Class Form1
    
Inherits System.Windows.Forms.Form

    
'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        
Try
            
If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            
End If
        
Finally
            
MyBase.Dispose(disposing)
        
End Try
    
End Sub


    
'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    
'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    
Private Sub InitializeComponent()
        
Me.gbDataEntry = New System.Windows.Forms.GroupBox
        
Me.cboID = New System.Windows.Forms.ComboBox
        
Me.lblNumber = New System.Windows.Forms.Label
        
Me.txtNum = New System.Windows.Forms.TextBox
        
Me.btnAdd = New System.Windows.Forms.Button
        
Me.lblParam = New System.Windows.Forms.Label
        
Me.lblValue = New System.Windows.Forms.Label
        
Me.lstParam = New System.Windows.Forms.ListBox
        
Me.lstValue = New System.Windows.Forms.ListBox
        
Me.gbCaculations = New System.Windows.Forms.GroupBox
        
Me.lblFlow = New System.Windows.Forms.Label
        
Me.lblpH = New System.Windows.Forms.Label
        
Me.lblTSS = New System.Windows.Forms.Label
        
Me.lblNum = New System.Windows.Forms.Label
        
Me.lblAverage = New System.Windows.Forms.Label
        
Me.txtFlowNum = New System.Windows.Forms.TextBox
        
Me.txtpHNum = New System.Windows.Forms.TextBox
        
Me.txtTSSNum = New System.Windows.Forms.TextBox
        
Me.txtFlowAvg = New System.Windows.Forms.TextBox
        
Me.txtpHAvg = New System.Windows.Forms.TextBox
        
Me.txtTSSAvg = New System.Windows.Forms.TextBox
        
Me.btnUpdate = New System.Windows.Forms.Button
        
Me.btnExit = New System.Windows.Forms.Button
        
Me.gbDataEntry.SuspendLayout()
        
Me.gbCaculations.SuspendLayout()
        
Me.SuspendLayout()
        
'
        'gbDataEntry
        '
        Me.gbDataEntry.Controls.Add(Me.btnAdd)
        
Me.gbDataEntry.Controls.Add(Me.txtNum)
        
Me.gbDataEntry.Controls.Add(Me.lblNumber)
        
Me.gbDataEntry.Controls.Add(Me.cboID)
        
Me.gbDataEntry.ForeColor = System.Drawing.SystemColors.HotTrack
        
Me.gbDataEntry.Location = New System.Drawing.Point(6763)
        
Me.gbDataEntry.Name = "gbDataEntry"
        
Me.gbDataEntry.Size = New System.Drawing.Size(263220)
        
Me.gbDataEntry.TabIndex = 0
        
Me.gbDataEntry.TabStop = False
        
Me.gbDataEntry.Text = "DataEntry"
        
'
        'cboID
        '
        Me.cboID.FormattingEnabled = True
        
Me.cboID.Location = New System.Drawing.Point(630)
        
Me.cboID.Name = "cboID"
        
Me.cboID.Size = New System.Drawing.Size(25121)
        
Me.cboID.TabIndex = 0
        
'
        'lblNumber
        '
        Me.lblNumber.AutoSize = True
        
Me.lblNumber.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.lblNumber.Location = New System.Drawing.Point(668)
        
Me.lblNumber.Name = "lblNumber"
        
Me.lblNumber.Size = New System.Drawing.Size(4413)
        
Me.lblNumber.TabIndex = 1
        
Me.lblNumber.Text = "Number"
        
'
        'txtNum
        '
        Me.txtNum.Location = New System.Drawing.Point(10665)
        
Me.txtNum.Name = "txtNum"
        
Me.txtNum.Size = New System.Drawing.Size(15120)
        
Me.txtNum.TabIndex = 2
        
'
        'btnAdd
        '
        Me.btnAdd.Location = New System.Drawing.Point(182121)
        
Me.btnAdd.Name = "btnAdd"
        
Me.btnAdd.Size = New System.Drawing.Size(7523)
        
Me.btnAdd.TabIndex = 3
        
Me.btnAdd.Text = "Add"
        
Me.btnAdd.UseVisualStyleBackColor = True
        
'
        'lblParam
        '
        Me.lblParam.AutoSize = True
        
Me.lblParam.Location = New System.Drawing.Point(43963)
        
Me.lblParam.Name = "lblParam"
        
Me.lblParam.Size = New System.Drawing.Size(5513)
        
Me.lblParam.TabIndex = 1
        
Me.lblParam.Text = "Parameter"
        
'
        'lblValue
        '
        Me.lblValue.AutoSize = True
        
Me.lblValue.Location = New System.Drawing.Point(62063)
        
Me.lblValue.Name = "lblValue"
        
Me.lblValue.Size = New System.Drawing.Size(3413)
        
Me.lblValue.TabIndex = 2
        
Me.lblValue.Text = "Value"
        
'
        'lstParam
        '
        Me.lstParam.FormattingEnabled = True
        
Me.lstParam.Location = New System.Drawing.Point(44293)
        
Me.lstParam.Name = "lstParam"
        
Me.lstParam.Size = New System.Drawing.Size(172186)
        
Me.lstParam.TabIndex = 3
        
'
        'lstValue
        '
        Me.lstValue.FormattingEnabled = True
        
Me.lstValue.Location = New System.Drawing.Point(61393)
        
Me.lstValue.Name = "lstValue"
        
Me.lstValue.Size = New System.Drawing.Size(160186)
        
Me.lstValue.TabIndex = 4
        
'
        'gbCaculations
        '
        Me.gbCaculations.Controls.Add(Me.btnExit)
        
Me.gbCaculations.Controls.Add(Me.btnUpdate)
        
Me.gbCaculations.Controls.Add(Me.txtTSSAvg)
        
Me.gbCaculations.Controls.Add(Me.txtpHAvg)
        
Me.gbCaculations.Controls.Add(Me.txtFlowAvg)
        
Me.gbCaculations.Controls.Add(Me.txtTSSNum)
        
Me.gbCaculations.Controls.Add(Me.txtpHNum)
        
Me.gbCaculations.Controls.Add(Me.txtFlowNum)
        
Me.gbCaculations.Controls.Add(Me.lblAverage)
        
Me.gbCaculations.Controls.Add(Me.lblNum)
        
Me.gbCaculations.Controls.Add(Me.lblTSS)
        
Me.gbCaculations.Controls.Add(Me.lblpH)
        
Me.gbCaculations.Controls.Add(Me.lblFlow)
        
Me.gbCaculations.ForeColor = System.Drawing.SystemColors.HotTrack
        
Me.gbCaculations.Location = New System.Drawing.Point(67306)
        
Me.gbCaculations.Name = "gbCaculations"
        
Me.gbCaculations.Size = New System.Drawing.Size(706100)
        
Me.gbCaculations.TabIndex = 5
        
Me.gbCaculations.TabStop = False
        
Me.gbCaculations.Text = "Caculations"
        
'
        'lblFlow
        '
        Me.lblFlow.AutoSize = True
        
Me.lblFlow.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.lblFlow.Location = New System.Drawing.Point(1125)
        
Me.lblFlow.Name = "lblFlow"
        
Me.lblFlow.Size = New System.Drawing.Size(2913)
        
Me.lblFlow.TabIndex = 0
        
Me.lblFlow.Text = "Flow"
        
'
        'lblpH
        '
        Me.lblpH.AutoSize = True
        
Me.lblpH.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.lblpH.Location = New System.Drawing.Point(1150)
        
Me.lblpH.Name = "lblpH"
        
Me.lblpH.Size = New System.Drawing.Size(2213)
        
Me.lblpH.TabIndex = 1
        
Me.lblpH.Text = "PH"
        
'
        'lblTSS
        '
        Me.lblTSS.AutoSize = True
        
Me.lblTSS.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.lblTSS.Location = New System.Drawing.Point(1172)
        
Me.lblTSS.Name = "lblTSS"
        
Me.lblTSS.Size = New System.Drawing.Size(2813)
        
Me.lblTSS.TabIndex = 2
        
Me.lblTSS.Text = "TSS"
        
'
        'lblNum
        '
        Me.lblNum.AutoSize = True
        
Me.lblNum.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.lblNum.Location = New System.Drawing.Point(12412)
        
Me.lblNum.Name = "lblNum"
        
Me.lblNum.Size = New System.Drawing.Size(6113)
        
Me.lblNum.TabIndex = 3
        
Me.lblNum.Text = "# of Values"
        
'
        'lblAverage
        '
        Me.lblAverage.AutoSize = True
        
Me.lblAverage.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.lblAverage.Location = New System.Drawing.Point(37212)
        
Me.lblAverage.Name = "lblAverage"
        
Me.lblAverage.Size = New System.Drawing.Size(4713)
        
Me.lblAverage.TabIndex = 4
        
Me.lblAverage.Text = "Average"
        
'
        'txtFlowNum
        '
        Me.txtFlowNum.Location = New System.Drawing.Point(10625)
        
Me.txtFlowNum.Name = "txtFlowNum"
        
Me.txtFlowNum.Size = New System.Drawing.Size(15120)
        
Me.txtFlowNum.TabIndex = 5
        
'
        'txtpHNum
        '
        Me.txtpHNum.Location = New System.Drawing.Point(10647)
        
Me.txtpHNum.Name = "txtpHNum"
        
Me.txtpHNum.Size = New System.Drawing.Size(15120)
        
Me.txtpHNum.TabIndex = 6
        
'
        'txtTSSNum
        '
        Me.txtTSSNum.Location = New System.Drawing.Point(10669)
        
Me.txtTSSNum.Name = "txtTSSNum"
        
Me.txtTSSNum.Size = New System.Drawing.Size(15120)
        
Me.txtTSSNum.TabIndex = 7
        
'
        'txtFlowAvg
        '
        Me.txtFlowAvg.Location = New System.Drawing.Point(32325)
        
Me.txtFlowAvg.Name = "txtFlowAvg"
        
Me.txtFlowAvg.Size = New System.Drawing.Size(15120)
        
Me.txtFlowAvg.TabIndex = 8
        
'
        'txtpHAvg
        '
        Me.txtpHAvg.Location = New System.Drawing.Point(32347)
        
Me.txtpHAvg.Name = "txtpHAvg"
        
Me.txtpHAvg.Size = New System.Drawing.Size(15120)
        
Me.txtpHAvg.TabIndex = 9
        
'
        'txtTSSAvg
        '
        Me.txtTSSAvg.Location = New System.Drawing.Point(32370)
        
Me.txtTSSAvg.Name = "txtTSSAvg"
        
Me.txtTSSAvg.Size = New System.Drawing.Size(15120)
        
Me.txtTSSAvg.TabIndex = 10
        
'
        'btnUpdate
        '
        Me.btnUpdate.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.btnUpdate.Location = New System.Drawing.Point(54625)
        
Me.btnUpdate.Name = "btnUpdate"
        
Me.btnUpdate.Size = New System.Drawing.Size(7523)
        
Me.btnUpdate.TabIndex = 11
        
Me.btnUpdate.Text = "Update"
        
Me.btnUpdate.UseVisualStyleBackColor = True
        
'
        'btnExit
        '
        Me.btnExit.ForeColor = System.Drawing.SystemColors.InfoText
        
Me.btnExit.Location = New System.Drawing.Point(54662)
        
Me.btnExit.Name = "btnExit"
        
Me.btnExit.Size = New System.Drawing.Size(7523)
        
Me.btnExit.TabIndex = 12
        
Me.btnExit.Text = "Exit"
        
Me.btnExit.UseVisualStyleBackColor = True
        
'
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        
Me.ClientSize = New System.Drawing.Size(809455)
        
Me.Controls.Add(Me.gbCaculations)
        
Me.Controls.Add(Me.lstValue)
        
Me.Controls.Add(Me.lstParam)
        
Me.Controls.Add(Me.lblValue)
        
Me.Controls.Add(Me.lblParam)
        
Me.Controls.Add(Me.gbDataEntry)
        
Me.ForeColor = System.Drawing.SystemColors.Highlight
        
Me.Name = "Form1"
        
Me.Text = "Form1"
        
Me.gbDataEntry.ResumeLayout(False)
        
Me.gbDataEntry.PerformLayout()
        
Me.gbCaculations.ResumeLayout(False)
        
Me.gbCaculations.PerformLayout()
        
Me.ResumeLayout(False)
        
Me.PerformLayout()

    
End Sub

    
Friend WithEvents gbDataEntry As System.Windows.Forms.GroupBox
    
Friend WithEvents cboID As System.Windows.Forms.ComboBox
    
Friend WithEvents lblNumber As System.Windows.Forms.Label
    
Friend WithEvents txtNum As System.Windows.Forms.TextBox
    
Friend WithEvents btnAdd As System.Windows.Forms.Button
    
Friend WithEvents lblParam As System.Windows.Forms.Label
    
Friend WithEvents lblValue As System.Windows.Forms.Label
    
Friend WithEvents lstParam As System.Windows.Forms.ListBox
    
Friend WithEvents lstValue As System.Windows.Forms.ListBox
    
Friend WithEvents gbCaculations As System.Windows.Forms.GroupBox
    
Friend WithEvents lblFlow As System.Windows.Forms.Label
    
Friend WithEvents lblpH As System.Windows.Forms.Label
    
Friend WithEvents lblTSS As System.Windows.Forms.Label
    
Friend WithEvents lblNum As System.Windows.Forms.Label
    
Friend WithEvents lblAverage As System.Windows.Forms.Label
    
Friend WithEvents txtFlowNum As System.Windows.Forms.TextBox
    
Friend WithEvents txtpHNum As System.Windows.Forms.TextBox
    
Friend WithEvents txtTSSNum As System.Windows.Forms.TextBox
    
Friend WithEvents txtpHAvg As System.Windows.Forms.TextBox
    
Friend WithEvents txtFlowAvg As System.Windows.Forms.TextBox
    
Friend WithEvents txtTSSAvg As System.Windows.Forms.TextBox
    
Friend WithEvents btnUpdate As System.Windows.Forms.Button
    
Friend WithEvents btnExit As System.Windows.Forms.Button

End Class

posted @ 2007-10-19 15:23  N/A2011  阅读(443)  评论(0编辑  收藏  举报