'传递参数,要么直接2个函数之间传递--私下传递其他函数用不了,要么声明变量得形式,公开传
Function jump1(a)
input1 = MsgBox("开始培养?", vbYesNo, "确定则会关闭当前界面, 前往培养界面 ")
If input1 = vbYes Then
index1 = a
Debug.Print "确定后index1= " & index1
Worksheets("petbag").Cells(2, 6) = index1
Unload UserForm1 '不能先关1,否则参数就传递不过去了,因为引用的方式是 userform1.index1,这样依赖好强,不如excel传递
' UserForm1.Visible = False
Load UserForm2
UserForm2.Show
Else
End If
End Function
用其他方法也能传
但是要注意时机问题
'即使从excel中转,也转不过来.,现在必须重开1次才更新?现在好了,之前是时机不对,应该打开2前先写入表里
' index1 = 6
' Debug.Print "开启2时index1=" & UserForm1.index1
index1 = Worksheets("petbag").Cells(2, 6)
' index1 = 6
' Debug.Print "重新赋值后index1=" & index1
' Debug.Print "重新赋值后index1=" & UserForm1.index1 '跨 form引用公共变量必须这样,但是依赖第1个form打开,index1这样不行!
'取数据
l2 = Application.Match("战斗属性1", Worksheets("petbag").Range("2:2"), 0)
m2 = Application.Match("战斗属性2", Worksheets("petbag").Range("2:2"), 0)
h2 = Application.Match("战斗属性3", Worksheets("petbag").Range("2:2"), 0)
ra = Worksheets("petbag").Cells(index1 + 2, l2)
rb = Worksheets("petbag").Cells(index1 + 2, m2)
rc = Worksheets("petbag").Cells(index1 + 2, h2)
x2 = Application.Match("成长率初值", Worksheets("petbag").Range("2:2"), 0)
ry = Worksheets("petbag").Cells(index1 + 2, x2)
x3 = Application.Match("当前累计值", Worksheets("petbag").Range("2:2"), 0)
grow_ac_now = Worksheets("petbag").Cells(index1 + 2, x3)
g_now = ry + grow_ac_now '可能要现从excel取?代码里取,哪种方式更好?--代码还没运行这时候取不到数。。。。差别就是这里-----
a_now = Int(ra + g_now * level_now) & "(" & ra & "+" & g_now * level_now & ")"
b_now = Int(rb + g_now * level_now) & "(" & rb & "+" & g_now * level_now & ")"
c_now = Int(rc + g_now * level_now) & "(" & rc & "+" & g_now * level_now & ")"