vb.net串口源码 vb串口通信程序
求vb.net的源代码,最好说明其解决问题,越多越好,满意加50分。
下面这段代码,是我用来计算每个月存500元进银行,连续30年,最后连本带利能有多少钱。这里面涉及复利计算。界面中右边的文本框用来输出每一次计算的结果。
创新互联建站是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括网站设计、网站建设、电商网站制作开发、重庆小程序开发、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!
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 '循环变量
Dim DATAstring As String '数据字符串
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
结果_TextBox.Text = Str(fuli_big) + "元"
End Sub
vb.net程序如何实现向电脑的Com口发送一段字符串信息,之后再接收显示发送的字符串信息?
'vb.net的串口接收数据要用到委托
Delegate Sub SetTextCallback(ByVal InputString As String) '声明一个委派类,并声明符合函数参数有一个,而其型态是字符串
Private Sub ShowString(ByVal comData As String)
txt_Re.Text = comData '将收到的数据入接收文字框中--- 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 '发送指令
SerialPort1.Write("123")
End Sub
怎样在vb中自动检测到可用串口号的具体程序代码
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 '说明当一个运行时错误发生时,控件转到紧接着发生错误的语句之后的语句,并在此继续运行。访问对象时要使用这种形式而不使用 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
网站栏目:vb.net串口源码 vb串口通信程序
网页链接:http://scyanting.com/article/doddsdg.html