Function getMaxMinAvg(Arr,cttRead) max = CDbl(arr(0)) min = CDbl(arr(0)) sum = CDbl(arr(0)) ctra = -26 ctr27 = -27 ctrb = 0 ctrb27 = 0 For i = 0 to UBound(Arr) If CDbl(Arr(i)) < ctra Then ctrb = ctrb + 1 end if if CDbl(Arr(i)) < ctr27 Then ctrb27 = ctrb27 + 1 end if Next For i = 1 To UBound(Arr) If CDbl(Arr(i)) > max Then max = CDbl(Arr(i)) End If If Arr(i) < min Then min = CDbl(Arr(i)) End If sum = sum +CDbl(Arr(i)) Next getMaxMinAvg = Array(max,min,Round(sum/(UBound(Arr)+1),2),ctrb,i,Round(ctrb/(UBound(Arr)+1),2),ctrb27,cttRead) End Function 'Function zte_Send(oltname,iP,port,iPLast,iPnxt,sLot,fso,eXclPath,LOgfilePath,cnt,re,reNot) Function zte_Send(oltname,iP,port,iPLast,iPnxt,fso,eXclPath,LOgfilePath,cnt,re,reNot) port = Split(port,"/") s = port(1) p = port(2) If iPLast <> iP Then crt.session.Connect("/telnet "&iP) crt.Screen.WaitForString "Username:" crt.Screen.Send "tzztesuper" & vbcr crt.Screen.WaitForString "Password:" crt.Screen.Send "ZTE@suer2019" & vbcr crt.Screen.WaitForString "#" crt.Screen.Send "configure t" & vbcr crt.Screen.WaitForString "#" End If If crt.GetScriptTab.Session.Logging = True Then crt.GetScriptTab.Session.Log False End If crt.Session.LogFileName = LOgfilePath crt.GetScriptTab.Session.Log True if InStr(oltname,"中兴600") <> 0 or InStr(oltname,"C600") <> 0 then code = "show pon power onu-rx gpon_olt-1/" Else code = "show pon power onu-rx gpon_olt-1/" End If crt.Screen.send code & s & "/" & p & vbCr t = crt.Screen.WaitForStrings("--More--",")#") Do while t = 1 crt.Screen.Send " " t = crt.Screen.WaitForStrings("--More--",")#") Loop crt.GetScriptTab.Session.Log False cttRead = fso.OpenTextFile(LOgfilePath).ReadAll If reNot.Test(cttRead) Then MaxMinAvg =Array("无ONU","0","0","0","0","0",cttRead) Elseif re.test(cttRead) Then 'rxArr = Split(re.Replace(Split(cttRead,String(77,"-"))(2),"$1"),vbCrLf) Set Matches = re.Execute(cttRead) tmpcnt = 0 For Each Match In Matches ReDim Preserve rxCDblArr(tmpcnt) rxCDblArr(tmpcnt) = CDbl(Match.SubMatches(0)) tmpcnt = tmpcnt +1 Next MaxMinAvg = getMaxMinAvg(rxCDblArr,cttRead) else MaxMinAvg =Array("所有ONU离线","0","0","0","0","0",cttRead) End If If iPnxt <> iP Then crt.Screen.Send "exit"&vbCr crt.Screen.WaitForStrings "#" crt.Screen.Send "exit"&vbCr if InStr(oltname,"中兴600") <> 0 or InStr(oltname,"C600") <> 0 then crt.session.Disconnect else crt.Screen.WaitForStrings "[yes/no]:" crt.Screen.Send "yes"&vbCr crt.session.Disconnect End If crt.sleep(500) End If zte_Send = MaxMinAvg End Function
时间: 2024-04-20 20:22:52 浏览: 25
这段代码定义了两个函数。首先是 `getMaxMinAvg` 函数,它接受一个数组 `Arr` 和一个整数 `cttRead` 作为参数。该函数用于计算数组中的最大值、最小值和平均值,并返回一个包含这些值的数组。
在函数内部,它首先初始化 `max`、`min` 和 `sum` 为数组第一个元素的值。然后通过一个循环遍历数组,比较每个元素与 `max` 和 `min` 的大小,并更新它们的值。同时,累加所有元素的值到 `sum` 中。
在循环结束后,它使用 `Round` 函数计算平均值,并将所有计算结果以及其他计数器的值存储在一个数组 `getMaxMinAvg` 中,并返回该数组。
接下来是 `zte_Send` 函数,它接受多个参数用于执行某些操作。该函数主要用于与设备进行通信,并根据通信结果调用 `getMaxMinAvg` 函数来计算最大、最小和平均值。
函数内部首先根据条件判断是否需要建立 telnet 连接。然后根据设备类型拼接命令字符串,并发送命令到设备。接着使用 `WaitForStrings` 方法等待设备返回结果,并根据结果进行相应的处理。
最后,根据不同的结果情况,调用 `getMaxMinAvg` 函数或直接返回相应的结果数组。
这段代码看起来是一个用于对中兴设备进行操作的函数,其中涉及了 telnet 连接、命令发送和结果处理等操作。
相关问题
c语言中max=arr[i]与arr[i]=max有什么区别吗
有区别。
max=arr[i]表示将数组arr的第i个元素的值赋给变量max。
arr[i]=max表示将变量max的值赋给数组arr的第i个元素。
例如:如果数组arr为{3, 5, 2, 7, 1},变量max为4,执行max=arr[2]后,max的值为2;执行arr[2]=max后,数组arr变为{3, 5, 4, 7, 1}。
temp = arr[i]; arr[i] = arr[max_index]; arr[max_index] = temp;
This code snippet is likely part of a sorting algorithm that swaps the values of two elements in an array.
`temp = arr[i];` assigns the value at the `i`th index of the array `arr` to a temporary variable `temp`.
`arr[i] = arr[max_index];` assigns the value at the `max_index`th index of the array `arr` to the `i`th index of the array `arr`.
`arr[max_index] = temp;` assigns the value of `temp` (which was the original value at the `i`th index of `arr`) to the `max_index`th index of `arr`.
Overall, this code snippet effectively swaps the values of the elements at indices `i` and `max_index` in `arr`.
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)