VBA里变量传递总是出问题,为什么?
VBA里变量传递总是出问题,为什么?有时同一变量,如果不再次对其定义,在使用时总是说变量类型不对,下面的程序供参考
Dim pp, pc, ct, tc, mm, fm, angle As Double<BR>TextBox1.text = 4450<BR>TextBox2.text = 132<BR>TextBox3.text = 293<BR>TextBox4.text = 620<BR>TextBox5.text = 900<BR>TextBox6.text = 2000<BR>pp = Round(Val(TextBox1), 4)<BR>pc = Round(Val(TextBox2), 4)<BR>ct = Round(Val(TextBox3), 4)<BR>tc = Round(Val(TextBox4), 4)<BR>fm = Round(Val(TextBox5), 4)<BR>mm = Round(Val(TextBox6), 4)<BR>必须在此定义
Dim ppm As Double<BR> Dim mmm As Double<BR> Dim fmm As Double<BR> Dim tcm As Double<BR> ppm = pp<BR> mmm = mm<BR> fmm = fm<BR> tcm = tc<BR>"For i = 0 To Int(ObjCurve.length / pp)" 如果不再次定义会出问题<BR>
"For i = 0 To Int(ObjCurve.length / ppm)" 这样就好了<BR> 你是在同一个sub里面写的上面的代码吗?
把你的dvb传上来看看 我也遇到这种情况。看程序没有问题。 pp, pc, ct, tc, mm, fm这几个变量其实是变体型的,Variant。它随后面赋值时的数据类型而变化,所以最好定义成固定的类型。 Dim pp, pc, ct, tc, mm, fm, angle As Double很多初学者可能都会认为,以上的语句是将所有的变量均设置为Double型,其实不是这样的,该语句只将最后的angle设置为Double型,而前面的pp, pc, ct, tc, mm, fm都没有定义其数据类型,所以这些变量均按缺省设置为 Variant 类型。'在一行中声明多个变量。AnotherVar 为 Variant 类型,
'因为它的类型被省略了。
Dim AnotherVar, Choice As Boolean, BirthDate As Date
页:
[1]