下面這段代碼,是我用來計算每個月存500元進銀行,連續(xù)30年,最后連本帶利能有多少錢。這里面涉及復利計算。界面中右邊的文本框用來輸出每一次計算的結(jié)果。
創(chuàng)新互聯(lián)建站是網(wǎng)站建設專家,致力于互聯(lián)網(wǎng)品牌建設與網(wǎng)絡營銷,專業(yè)領域包括網(wǎng)站設計、網(wǎng)站建設、電商網(wǎng)站制作開發(fā)、重慶小程序開發(fā)、微信營銷、系統(tǒng)平臺開發(fā),與其他網(wǎng)站設計及系統(tǒng)開發(fā)公司不同,我們的整合解決方案結(jié)合了恒基網(wǎng)絡品牌建設經(jīng)驗和互聯(lián)網(wǎng)整合營銷的理念,并將策略和執(zhí)行緊密結(jié)合,且不斷評估并優(yōu)化我們的方案,為客戶提供全方位的互聯(lián)網(wǎng)品牌整合方案!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
? Dim nianxian As Integer '年限變量
? Dim dingcun As Integer '定存變量
? Dim fuli_big As Long '大復利
? Dim fuli_small As Long '小復利
? Dim i As Integer '循環(huán)變量
? Dim DATAstring As String '數(shù)據(jù)字符串
? nianxian = Val(年限_TextBox.Text)
? dingcun = Val(定存_TextBox.Text)
? DATAstring = ""
? For i = 1 To nianxian
? ? ? fuli_small = dingcun * (1 + 0.1875)
? ? ? dingcun = fuli_small
? ? ? fuli_big = fuli_big + fuli_small
? ? ? DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_big) + Chr(13) + Chr(10)
? ? ? 'DATAstring = DATAstring + "[" + Trim(Str(i)) + "]" + Str(fuli_small) + Chr(13) + Chr(10)
? Next
? 'fuli_big = fuli_small
? TextBox1.Text = DATAstring
? 結(jié)果_TextBox.Text = Str(fuli_big) + "元"
End Sub
'vb.net的串口接收數(shù)據(jù)要用到委托
Delegate Sub SetTextCallback(ByVal InputString As String) '聲明一個委派類,并聲明符合函數(shù)參數(shù)有一個,而其型態(tài)是字符串
Private Sub ShowString(ByVal comData As String)
txt_Re.Text = comData '將收到的數(shù)據(jù)入接收文字框中--- txt_Re.Text 是接收用的文本框
txt_Re.SelectionStart = txt_Re.Text.Length
txt_Re.ScrollToCaret()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived‘自動接收事件
Dim inData As String = SerialPort1.ReadExisting
Dim d As New SetTextCallback(AddressOf ShowString)
Invoke(d, inData)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '發(fā)送指令
SerialPort1.Write("123")
End Sub
j = 0
For i = 1 To 16 Step 1
If comISP.PortOpen = True Then '先關閉串口
comISP.PortOpen = False
End If
comISP.CommPort = i
On Error Resume Next '說明當一個運行時錯誤發(fā)生時,控件轉(zhuǎn)到緊接著發(fā)生錯誤的語句之后的語句,并在此繼續(xù)運行。訪問對象時要使用這種形式而不使用 On Error GoTo。
comISP.PortOpen = True
If Err.Number 8002 Then '無效的串口號。這樣可以檢測到虛擬串口,如果用Err.Number = 0的話檢測不到虛擬串口
If j = 0 Then
j = i
End If
cboPort.AddItem "COM" i '生成串口選擇列表
End If
comISP.PortOpen = False
Next i
If j = 1 Then
cboPort.Text = "COM" j '自動打開可用的最小串口號
comISP.CommPort = j
comISP.PortOpen = True
cmdOpenCom.Caption = "關閉串口"
shpCOM.FillColor = vbGreen
If Err.Number = 8005 Then '串口已打開,vbExclamation '
comISP.PortOpen = False
cboPort.Text = ""
cmdOpenCom.Caption = "打開串口"
shpCOM.FillColor = vbRed
End If
End If