繁体   English   中英

Excel 的问题 - 第三方是否篡改了我的计算机?

[英]Problems with Excel - Is a third party tampering with my computer?

今天,以下代码对我不起作用。 我认为有人在篡改我的电脑。 我想知道,这怎么可能被复制,或者我的代码有错误:

'number of rows for a certain column:
dim c as integer
c = WorksheetFunction.counta(columns("A:A"))
'get a value
c = range("A1")

额外的:
我的代码是家庭作业“蒙特卡罗模拟”。 它基本上改变了用于烘焙饼干的项目列表的成本,并使用不同类型的分布(均匀、正态、离散)来做到这一点。 Excel 耗尽了它的资源,因为循环引用的错误格式循环 - 所以错误消息)。 我反复重启Excel。 最后,我使用了教授提供的原始代码,并一步一步地重新插入我已经编写好的函数和程序,以找出我在编码过程中是如何导致 Excel 错误消息的。 我在 1 分钟内完成了 1000 个“蒙特卡罗模拟”,而不是之前观察到的 30 分钟。 我提供的代码我认为是基本的,但我无法解决问题,即使我将旧代码复制到我的 VBA 模块中。 我怎样才能避免 ie 第三方篡改我的计算机?

添加于 2021 年 7 月 20 日
此代码使用控件集合来获取表单上的数据值。 您需要具有两个文本字段的表单,它们应该具有双值内容。 因此,从今天起,控件集合不起作用。

txtPerc1txt1
然后该函数将返回一个值以及离散分布。
控件行被注释掉,因为我收到错误“子或函数未定义。我检查了字段的名称,没问题。

'sample call:
'discreteDistribtion("Hallo", 3)
' So I have six fields named:
' halloPerc1, halloPerc2, halloPerc3 and hallo1, hallo2, and hallo3
' the function takes here "hallo" and generates the names Hallo1, Hallo2, Hallo3 and halloPerc1, halloPerc2, and halloPerc3
' the function takes the value of hallo1, hallo2, or hallo3, each of these fields having doubles as content.
' According to the logic, hallo1, hallo2 or hallo3 values are returned!
' The code does not work on my computer, when I uncomment the controls code, it worked the weeks before.

Function discreteDistribution(strCtrl As String, iEnd As Integer, Optional iStart As Integer = 1)
    Dim i As Integer, sum As Double, r As Double, strTemp As String
    sum = 0
    r = Rnd
    discreteDistribution = 0
    For i = iStart To iEnd
        strTemp = strCtrl & "Perc" & i
        ''''''sum = sum + Controls(strTemp).Value
        If r < sum Then
            strTemp = strCtrl & i
        ''''''    discreteDistribution = Controls(strTemp)
            Exit For
        End If
    Next i
End Function

我在单独的工作表上向我的工作簿添加了第二个用户表单,并且以下代码正在运行:

Option Explicit

Dim i As Integer


Private Sub CommandButton1_Click()
    For i = 1 To 10
        Controls("TextBox" & i).Value = Cells(i + 1, 1).Value
    Next i
End Sub

Private Sub UserForm_Click()

End Sub

此代码用电子表格上收集的电话号码填充一堆文本框。 尽管如此,我还是无法让我的原始代码工作。

代码被 Excel 识别为错误,突出显示了上图中显示的错误的位置:

虽然这里没有回答整个问题,但我今天的问题已经解决了。 控件集合是用户表单的一个属性。 所以为了从模块内部调用这个集合,它需要知道它所关联的表单。 因此,而不是调用controls("Name of Control") = ...调用必须是: form.controls("Name of Control")然后代码工作。

感谢所有回复我的鼓励请求的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM