指数不允许定义variables?

我有创build真值表的简单的VBA程序。 这些行是红色的(某种语法错误):

end0=2^power/2 

 end1=2^power 

在这里他们是在上下文中:

 Sub filltruthtable() cases = 2 * inputnum Dim power power = inputnum - colcounter Dim end0 end0=2^power/2 Dim start1 start1 = end0 + 1 Dim end1 end1=2^power For counterrow = 1 To inputnum For counterrow = 1 To end0 Cells(counterrow, countercol).Value = 0 Next For counterrow = start1 To end1 Cells(counterrow, countercol).Value = 0 Next Next End Sub 

指数是允许定义variables,但你必须确保它实际上是一个数字,而不是包含一个数字的string。

我已经将filltruthtable()中使用的所有variables声明为long整数,但这仅仅是因为我不知道你将使用什么types的数字,或者如果你已经用public或者module作用域来声明variables。

另外,当给variables赋值时,我会一直确保这个值是我想要的那种

 Sub Demo() Dim Demo_Num As Integer Demo_Num = CInt(Application.InputBox ("Please give an input.", "Input") end sub 

现在Demo_Num是一个长整数,可以用作指数。

 Sub filltruthtable() Dim cases As Long, Dim inputnum As Long, Dim power As Long, Dim end0 As Long, Dim start1 As Long, Dim end1 As Long, Dim colcounter As Long, Dim counterrow As Long, Dim countercol As Long cases = 2 * inputnum power = inputnum - colcounter end0 = 2 ^ power / 2 start1 = end0 + 1 end1 = 2 ^ power For counterrow = 1 To inputnum For counterrow = 1 To end0 Cells(counterrow, countercol).Value = 0 Next For counterrow = start1 To end1 Cells(counterrow, countercol).Value = 0 Next Next End Sub