帮看一下VB的代码

y的值一直在变化,y的值怎么来的,最好能详细介绍一下。PrivateSubaa(ByValn!,jc!)DimiAsIntegerjc=1Fori=1Tonjc=jc*i... y的值一直在变化,y的值怎么来的,最好能详细介绍一下。
Private Sub aa(ByVal n!, jc!)
Dim i As Integer
jc = 1
For i = 1 To n
jc = jc * i
Next i
End Sub

Private Sub Form_Click()
Dim sum!, x%, y!
sum = 0
For x = 1 To 9 Step 2
Call aa(x, y)
sum = sum + y
Next x
Print sum
End Sub
展开
 我来答
素净又虔诚丶松柏s
推荐于2016-11-30 · 超过62用户采纳过TA的回答
知道答主
回答量:170
采纳率:0%
帮助的人:65.6万
展开全部
“'”后面的是注释
你不给控件或VB工程,俺们怎读啊?

Dim DataR As String 'DataR为接收到的数据
Dim DataS As String 'DataS为要发送的数据
Dim NumS As Integer 'NumS为发送的字节数
Dim NumR As Integer 'NumR为接收的字节数
Dim TempData As String
Dim TempStr As String
Dim SignStr As String
Dim bWaitCommand As Boolean
Dim SignLength, StartIndex, EndIndex, Length As Long
Private Sub CmdEnd_Click()
End
End Sub
'cmd获取终端参数
Private Sub cmdGetInfo_Click()
'DataS = "show" & vbCr
'Call Send
'此处需等待一段时间
Timer2.Interval = 10
Timer2.Enabled = True
bWaitCommand = True
'
''加载信息
'
'TempData = txtR.Text
'If Len(TempData) = 0 Then
'MsgBox "没有从终端获取到任何数据,请检查连接"
'Exit Sub
'End If
'
'SignStr = "PPP Dialnumber:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“移动服务商号码”的终端参数"
'Else
'txtDialnumber.Text = TempStr
'End If
'
'SignStr = "PPP Username:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“PPP用户名”的终端参数"
'Else
'txtUsername.Text = TempStr
'End If
'
'SignStr = "PPP Password:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“PPP密码”的终端参数"
'Else
'txtPassword.Text = TempStr
'End If
'
'SignStr = "PPP Timeout:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“超时”的终端参数"
'Else
'txtTimeOut.Text = TempStr
'End If
'
'SignStr = "PPP Retry Time:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“重拨次数”的终端参数"
'Else
'txtReDail.Text = TempStr
'End If
'
'SignStr = "APN:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“APN接入点名称”的终端参数"
'Else
'txtAPN.Text = TempStr
'End If
'
'SignStr = "user id:"
'Call Temp
'If StartIndex = SignLength Then
' MsgBox "没有找到“终端ID号码”的终端参数"
'Else
'txtUserID.Text = TempStr
'End If
'
End Sub
Private Sub CmdGo_Click()
PicShow.Visible = False
End Sub
Private Sub cmdResetCom_Click()
cmdResetCom.Enabled = False
DataS = "set sys default" & vbCr
Call Send
cmdResetCom.Enabled = True
End Sub
'cmd更新终端参数
Private Sub cmdWriteCom_Click()

TempData = txtR.Text '由于在获取参数过程中TempData的字符串不断减少,再此让TempData重新等于txtR.Text
SignStr = "PPP Dialnumber:"
Call Temp
If txtDialnumber.Text <> TempStr Then
DataS = "set ppp dialnumber " & Trim(txtDialnumber.Text) & vbCr
Call Send
End If
' username
SignStr = "PPP Username:"
Call Temp
If txtUsername.Text <> TempStr Then
DataS = "set ppp username " & Trim(txtUsername.Text) & vbCr
Call Send
End If
' password
SignStr = "PPP Password:"
Call Temp
If txtPassword.Text <> TempStr Then
DataS = "set ppp password " & Trim(txtPassword.Text) & vbCr
Call Send
End If
SignStr = "PPP Timeout:"
Call Temp
If txtTimeOut.Text <> TempStr Then
DataS = "set ppp timeout " & Trim(txtTimeOut.Text) & vbCr
Call Send
End If
SignStr = "PPP Retry Time:"
Call Temp
If txtReDail.Text <> TempStr Then
DataS = "set ppp retry time " & Trim(txtReDail.Text) & vbCr
Call Send
End If
SignStr = "APN:"
Call Temp
If txtAPN.Text <> TempStr Then
DataS = "set apn " & Trim(txtAPN.Text) & vbCr
Call Send
End If
SignStr = "user id:"
Call Temp
If txtUserID.Text <> TempStr Then
DataS = "set ppp user id " & Trim(txtUserID.Text) & vbCr
Call Send
End If
End Sub
Private Sub Form_Load()
PicShow.Move 0, 0, Me.Width, Me.Height
CmdGo.Move (PicShow.Width - CmdGo.Width) / 2 - 1000, (PicShow.Height - CmdGo.Height) / 2
CmdEnd.Move CmdGo.Left + 2000, CmdGo.Top
'================================
'PC串口初始化
'串口
Combo1.AddItem "COM1"
Combo1.AddItem "COM2"
Combo1.AddItem "COM3"
Combo1.AddItem "COM4"

'串口速率
Combo2.AddItem "1200"
Combo2.AddItem "2400"
Combo2.AddItem "4800"
Combo2.AddItem "9600"
Combo2.AddItem "19200"
Combo2.AddItem "38400"
Combo2.AddItem "57600"
Combo2.AddItem "115200"

'数据位
Combo3.AddItem "5"
Combo3.AddItem "6"
Combo3.AddItem "7"
Combo3.AddItem "8"

'停止位
Combo4.AddItem "1"
Combo4.AddItem "1.5"
Combo4.AddItem "2"

'校验位
Combo5.AddItem "无"
Combo5.AddItem "奇校验"
Combo5.AddItem "偶校验"
Combo5.AddItem "标记"
Combo5.AddItem "空格"
'================================
'使一些按钮无效

cmdDataS.Enabled = False
cmdCloseCOM.Enabled = False

DataR = ""
'================================

End Sub
'cmd打开串口
Private Sub cmdOpenCOM_Click()

On Error GoTo DoErr1
'使相应按钮可用
cmdGetInfo.Enabled = True
cmdWriteCom.Enabled = True
cmdResetCom.Enabled = True
cmdDataS.Enabled = True
cmdCloseCOM.Enabled = True
cmdOpenCOM.Enabled = False
'设定串口
Dim s As String
s = Combo1.Text
Select Case s
Case "COM1"
MSComm1.CommPort = 1
Case "COM2"
MSComm1.CommPort = 2
Case "COM3"
MSComm1.CommPort = 3
Case "COM4"
MSComm1.CommPort = 4
End Select
'===================================
'设定串口参数
MSComm1.Settings = Combo2.Text & "," & "n," & Combo3.Text & "," & Combo4.Text '波特率,无校验,数据位,停止位
MsgBox "选择的端口号为 " & CStr(MSComm1.CommPort) & vbCr & "设定的参数为 " & MSComm1.Settings
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True '打开串口

MSComm1.OutBufferCount = 0 '清空发送缓冲区
MSComm1.InBufferCount = 0 '清空接收缓冲区
If Check1.Value = 0 Then
MSComm1.InputMode = comInputModeText
Else
MSComm1.InputMode = comInputModeBinary
End If
''发送字符数据时注意必须用回车符(vbcr)结束
'MSComm1.Output = "This is a qood book ! " & vbCr
'
''泼打电话号码或发送AT命令
'MSComm1.Output = "ATDT 05778191898 , & vbCr"
Timer1.Enabled = True
'If Timer1.Enabled Then
' cmdOpenCOM.Caption = "关闭串口"
'Else
'
' cmdOpenCOM.Caption = "打开串口"
'End If
DoErr1:
If Err.Number = 8002 Then
MsgBox Err.Description, vbOKOnly, "错误"
cmdOpenCOM.Enabled = True
cmdCloseCOM.Enabled = False
cmdDataS.Enabled = False
ElseIf Err.Description <> "" Then
MsgBox Err.Description
End If
End Sub
'cmd关闭串口
Private Sub cmdCloseCOM_Click()
MSComm1.PortOpen = False
Timer1.Enabled = False
cmdOpenCOM.Enabled = True
cmdCloseCOM.Enabled = False
cmdDataS.Enabled = False
End Sub
Private Sub cmdDataS_Click()
DataS = Trim(txtS.Text) & vbCr '将要发送的文本框内的空格去除,并且赋给DataS
Call Send
txtS.Text = ""
End Sub
Private Sub cmdClsR_Click()
txtR.Text = ""
End Sub
Private Sub cmdClsS_Click()
txtDisplay.Text = ""
End Sub
Private Sub cmdQuit_Click()
End
'q = MsgBox("确实要退出程序?", vbYesNo)
'If q = 1 Then
'Unload Me
'End If
End Sub
Private Sub cmdResetS_Click()
NumS = 0
txtNumS.Text = NumS
End Sub
Private Sub cmdResetR_Click()
txtNumR.Text = "0"
End Sub

Private Sub txtComPortNum_Change()
txtSeverPortNum.Text = txtComPortNum.Text
End Sub

'每50毫秒接收一次数据
Private Sub Timer1_Timer()
DataR = Me.MSComm1.Input
txtR.Text = txtR.Text & DataR '& Chr(10)& Chr(13)
NumR = NumR + Len(DataR)
txtNumR.Text = NumR
DataR = ""

End Sub
Private Sub Timer2_Timer()
If bWaitCommand = True Then
DataS = "show" & vbCr
Call Send
Timer2.Interval = 3000
bWaitCommand = False
Exit Sub
Else
'加载信息

TempData = txtR.Text
If Len(TempData) = 0 Then
MsgBox "没有从终端获取到任何数据,请检查连接"
Exit Sub
End If

SignStr = "PPP Dialnumber:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“移动服务商号码”的终端参数"
Else
txtDialnumber.Text = TempStr
End If

SignStr = "PPP Username:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“PPP用户名”的终端参数"
Else
txtUsername.Text = TempStr
End If

SignStr = "PPP Password:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“PPP密码”的终端参数"
Else
txtPassword.Text = TempStr
End If

SignStr = "PPP Timeout:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“超时”的终端参数"
Else
txtTimeOut.Text = TempStr
End If

SignStr = "PPP Retry Time:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“重拨次数”的终端参数"
Else
txtReDail.Text = TempStr
End If

SignStr = "APN:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“APN接入点名称”的终端参数"
Else
txtAPN.Text = TempStr
End If

SignStr = "user id:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“终端ID号码”的终端参数"
Else
txtUserID.Text = TempStr
End If

SignStr = "TCP Remote IP:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“TCP服务器IP/域名”的终端参数"
Else
txtTcpIP = TempStr
End If

SignStr = "TCP Remote Port:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“TCP端口”的终端参数"
Else
txtTcpPort = TempStr
End If

SignStr = "TCP Data Mode:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“数据传输模式”的终端参数"
Else
Combo6.Text = TempStr
End If

SignStr = "FTP Server IP:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“FTP服务器IP/域名”的终端参数"
Else
txtFtpIP = TempStr
End If

SignStr = "FTP Server Port:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“FTP端口”的终端参数"
Else
txtFtpPort = TempStr
End If

SignStr = "FTP Server Username:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“FTP用户名”的终端参数"
Else
txtFtpUsername = TempStr
End If

SignStr = "FTP Server Password:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“FTP密码”的终端参数"
Else
txtFtpPassword = TempStr
End If

SignStr = "FTP Server Directory:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“服务器文件路径”的终端参数"
Else
txtFtpDir = TempStr
End If

SignStr = "Upload Buffer Size:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“上传文件大小”的终端参数"
Else
txtUpSize = TempStr
End If

SignStr = "SYS Mode:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“上线方式”的终端参数"
Else
If TempStr = "auto" Then Option1.Value = True
If TempStr = "manual" Then Option2.Value = True
End If

SignStr = "SYS Baudrate:"
Call Temp
If StartIndex = SignLength Then
MsgBox "没有找到“波特率”的终端参数"
Else
Combo2.Text = TempStr
End If

Timer2.Enabled = False
End If
End Sub
Private Sub txtS_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call cmdDataS_Click
End If
End Sub
Private Sub txtSeverPortNum_Change()
txtComPortNum.Text = txtSeverPortNum.Text
End Sub
'发送数据子过程
Sub Send()
Dim buf() As Byte
Dim m, n, p As Long
Dim i, j, k As Long
On Error GoTo DoErr
If MSComm1.PortOpen = False Then
MsgBox "请打开串口", vbOKOnly, "错误"
Exit Sub
End If
If Len(DataS) = 0 Then '如果没有数据
MsgBox "请输入数据", vbOKOnly, "错误"
Exit Sub
End If
If Check1.Value = 0 Then '如果没有选择是否以16进制发送
p = Len(DataS)
ReDim buf(p - 1) As Byte
For i = 1 To p
buf(i - 1) = Asc(Mid(DataS, i, 1)) '将每个字符以ASCII码发送
Next i
NumS = NumS + p
txtNumS.Text = NumS
Else '如果选择以16进制发送
DataS = Replace(DataS, " ", "")
DataS = Replace(DataS, vbCrLf, "")
p = Len(DataS) \ 2 - 1
ReDim buf(p) As Byte
For i = 0 To p
buf(i) = CLng("&H" & Mid(DataS, i * 2 + 1, 2)) '以16进制数发送
Next i
NumS = NumS + p
txtNumS.Text = NumS
End If
txtDisplay.Text = txtDisplay.Text & DataS & vbCrLf
'通过串口发送数据
'MSComm1.InputMode = comInputModeBinary '通过 Input 属性以文本方式取回数据
MSComm1.Output = buf()
'已发送字节数
Exit Sub
'出错处理
DoErr:
If Err.Number = 13 Then
MsgBox "数据格式不对", vbOKOnly, "错误"
Else
MsgBox Err.Description
End If
End Sub
'获取参数用到的子过程
Sub Temp()
SignLength = Len(SignStr)
StartIndex = InStr(TempData, SignStr) + SignLength
If StartIndex = SignLength Then
Exit Sub '如果找不到"SignStr",则没有接收到从终端传来的参数,退出Temp子过程
End If
EndIndex = InStr(StartIndex, TempData, vbCrLf)
Length = EndIndex - StartIndex
TempStr = Trim(Mid(TempData, StartIndex, Length))
'TempStr = Trim(Mid(TempData, (InStr(TempData, ":") + 1), (InStr((InStr(TempData, ":") + 1), TempData, vbCrLf) - (InStr(TempData, ":") + 1))))
TempData = Right(TempData, Len(TempData) - EndIndex - 1)
'StartIndex = 0
'EndIndex = 0
'Length = 0
End Sub
' DataR
'show
'
'===== PPP =====
'PPP Status: down
'PPP Local IP: 0.0.0.0
'PPP Dialnumber: *99***1#
'PPP Username:
'PPP Password: ******
'PPP Timeout: 30 second
'PPP Retry Time: 3
'APN: hdgr -sj.he
'user id: 13912345678
'===== TCP =====
'TCP Status: disconnect
'TCP Remote IP: bbs.tsinghua.edu.cn
'TCP Remote Port: 23
'TCP Data Mode: enter
'===== UDP =====
'TCP Status: disconnect
'TCP Remote IP: bbs.t
'TCP Remote Port: 23
'===== FTP =====
'FTP Server IP: 192.168.0.1
'FTP Server Port: 21
'FTP Server Username: test
'FTP Server Password: ******
'FTP Server Directory: /
'Upload Buffer Size: 250
'===== SYS =====
'SYS Mode: manual
'SYS Baudrate: 57600
Private Sub txtUsername_Change()
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式