我已经尝试了与此ByRef错误相关的所有内容,其他程序员提到我必须设置我创建的每个变量的值类型,其他人说要删除这些变量的类型。
我真的需要一些帮助,因为这是我与VB的第一天。
代码的主要思想下面是制作一个小形式,点击后,word文档上的线条将向下或向上顺利向下滚动,当然他有能力增加/减少这个动作的速度。
以下是主要功能:
Function GoDown(ByRef Speed As Integer, ByRef CounterUp As Integer, ByRef CounterDown As Integer)
CounterUp = 0
CounterDown = 1
Dim NumberOfPages As Integer
Set NumberOfPages = ActiveDocument.ComputeStatistics(wdStatisticPages)
Dim NumberOfLines As Range
Set NumberOfLines = ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)
Dim Multiplicate As Integer
Set Multiplicate = NumberOfPages * NumberOfLines
Dim Counter As Integer
Set Counter = 0
While (Counter < Multiplicate):
ActiveWindow.SmallScroll down:=1
Counter = Counter + 1
Call Application.Wait(Now + TimeValue("0:00:'&Speed&'"))
Call ActiveWindow.Close
Call Application.Quit
End Function
Function GoUp(ByRef Speed As Integer, ByRef CounterUp As Integer, ByRef CounterDown As Integer)
Dim NumberOfLines As Range
Set NumberOfLines = ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)
Set CounterUp = 1
Set CounterDown = 0
Dim Counter As Integer
Set Counter = 0
While (Counter < NumberOfLines):
ActiveWindow.SmallScroll up:=1
Counter = Counter + 1
Call Application.Wait(Now + TimeValue("0:00:'&Speed&'"))
End Function
Function GoFaster(ByRef Speed As Integer, ByRef CounterUp As Integer, ByRef CounterDown As Integer)
Speed = Speed - 1
If (CounterUp > 0 & CounterDown = 0) Then
Call Application.Run("btnUp_Click")
Else: Call Application.Run("btnDown_Click")
End Function
Function GoSlower(ByRef Speed As Integer, ByRef CounterUp As Integer, ByRef CounterDown As Integer)
Speed = Speed + 1
If (CounterDown > 0 & CounterUp = 0) Then Call Application.Run("btnDown_Click")
Else: If (CounterDown = 0 & CounterUp > 0) Then Call Application.Run("btnUp_Click")
End Function
我已尝试使用而不是功能来放置Sub,没有任何反应。我也试过&#34; cint&#34;并没有成功。
以下是点击事件的实施:
Sub Main()
Dim Speed As Integer
Set Speed = 3
Dim CounterUp As Integer
Set CounterUp = 0
Dim CounterDown As Integer
Set CounterDown = 0
Public Sub btnDown_Click_Click()
Call GoDown(Speed as Integer, CounterUp as Integer, CounterDown)
End Sub
Public Sub btnLeft_Click_Click()
Call GoSlower(Speed, CounterUp, CounterDown)
End Sub
Public Sub btnRight_Click_Click()
Call GoFaster(Speed, CounterUp, CounterDown)
End Sub
Public Sub btnUp_Click_Click()
Call GoUp(Speed, CounterUp, CounterDown)
End Sub
End Sub
正如您所看到的,我已经尝试过在MSDN和这里提到过两种方法,但没有一种方法解决了我的&#34; ByRef参数类型不匹配&#34;。
答案 0 :(得分:0)
你可以像这样调用一个子:
GoDown Speed, CounterUp, CounterDown
或使用函数:
x = GoDown(Speed, CounterUp, CounterDown)
在附加示例中,子主体中有子嵌套。它不能像这样工作,任何由点击触发的程序都需要分开。
而不是Integer,总是使用Long,否则您将遇到超出Integer限制的数据问题(最大值32767,最小值为-32768)。
答案 1 :(得分:-2)
感谢所有帮助我解决问题的人,以及无偿的哲学家。 无论如何。 任何时候您需要将变量用于多个事件或多个函数。 你必须:
`Public ThisVariable As String`
在这样的表单的load事件中:
FormName_Initialize()
{
ThisVariable = "The Starting value you want :)"
}
谢谢