|
查看: 1008|回复: 4
|
-- closed --
[复制链接]
|
|
|
本帖最后由 giller 于 22-11-2010 01:15 PM 编辑
Option Explicit
Dim Xx As Integer
Dim Yy As Integer
Dim I As Integer
Dim J As Integer
Private Sub cmdAdd_Click()
I = I + 1
ReDim x(1 To I + 1) As Integer
ReDim y(1 To I + 1) As Integer
ReDim P(1 To I + 1) As Single
x(I) = txtx.Text
y(I) = txty.Text
P(I) = txtP.Text
List1.AddItem (Label2.Caption) & " " & (x(I)) & " " & (y(I)) & " " & (P(I))
Label2.Caption = "Station " & I + 1
Label5.Caption = x(I)
End Sub
Private Sub cmdCalc_Click()
Dim x(7) As Single
Dim y(7) As Single
Dim P(7) As Single
ReDim d2(1 To I) As Single
ReDim di(1 To I) As Single
ReDim perd2(1 To I) As Single
ReDim Pi(1 To I) As Single
Dim W1 As Single
Dim W2 As Single
Dim W3 As Single
Dim W4 As Single
Dim WP1 As Single, WP2 As Single, WP3 As Single, WP4 As Single
Dim Px As Single
ReDim x(1 To I)
ReDim y(1 To I)
ReDim P(1 To I)
Dim max1 As Single
Dim max2 As Single
Dim max3 As Single
Dim max4 As Single
Dim Totald As Single
max1 = 0
max2 = 0
max3 = 0
max4 = 0
For J = 1 To I
d2(J) = x(J) ^ 2 + y(J) ^ 2
End Sub
我想請問一下 為什么上面的x(I) 帶不到下面這里的??
誰可以幫我改改一下
感激不盡 |
|
|
|
|
|
|
|
|
|
|
发表于 8-2-2010 04:46 PM
|
显示全部楼层
本帖最后由 雪儿与小鱼儿 于 8-2-2010 04:56 PM 编辑
Option Explicit
Dim Xx As Integer
Dim Yy As Integer
Dim I As Integer
Dim J As Integer
Private S ...
giller 发表于 8-2-2010 03:36 PM 
因为你的 x(I) 在 cmdAdd_Click 的时候用 ReDim,全部 value 会被 reset 过。
为什么在 cmdCalc_Click 里又有一个 Dim x(7) As Single 呢? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-2-2010 06:02 PM
|
显示全部楼层
我是想要按add的時候,就有一個數字加進去
可是我又不知道要怎樣不放upper boundary。。
不要有限制幾個array的 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-2-2010 06:04 PM
|
显示全部楼层
|
我用不到preserve 我也不知道要怎樣用preserve的 |
|
|
|
|
|
|
|
|
|
|
发表于 8-2-2010 07:01 PM
|
显示全部楼层
我用不到preserve 我也不知道要怎樣用preserve的
giller 发表于 8-2-2010 06:04 PM 
VB 没有 preserve 的。
以下是改正过的 code,你可以试一下:
-
- Option Explicit
- Dim Xx As Integer
- Dim Yy As Integer
- Dim I As Integer
- Dim J As Integer
- Dim TempxArr() As Integer, TempyArr() As Integer
- Dim x() As Integer, y() As Integer
- Private Sub cmdAdd_Click()
- Dim k As Integer
- If I > 0 Then
- ReDim TempxArr(I) As Integer
- ReDim TempyArr(I) As Integer
- For k = 1 To I
- TempxArr(k) = x(k)
- TempyArr(I) = y(k)
- Next
- End If
- I = I + 1
- ReDim x(1 To I + 1) As Integer
- ReDim y(1 To I + 1) As Integer
- ReDim P(1 To I + 1) As Single
- x(I) = txtx.Text
- y(I) = txty.Text
- P(I) = txtp.Text
- Label2.Caption = "Station " & I + 1
- Label5.Caption = x(I)
- List1.AddItem (Label2.Caption) & " " & (x(I)) & " " & (y(I)) & " " & (P(I))
- For k = 1 To I - 1
- x(k) = TempxArr(k)
- y(k) = TempyArr(k)
- Next
- End Sub
- Private Sub cmdCalc_Click()
- '''Dim x(7) As Single
- '''Dim y(7) As Single
- '''Dim P(7) As Single
- ReDim d2(1 To I) As Single
- ReDim di(1 To I) As Single
- ReDim perd2(1 To I) As Single
- ReDim Pi(1 To I) As Single
- Dim W1 As Single
- Dim W2 As Single
- Dim W3 As Single
- Dim W4 As Single
- Dim WP1 As Single, WP2 As Single, WP3 As Single, WP4 As Single
- Dim Px As Single
- '''ReDim x(1 To I)
- '''ReDim y(1 To I)
- '''ReDim P(1 To I)
- Dim max1 As Single
- Dim max2 As Single
- Dim max3 As Single
- Dim max4 As Single
- Dim Totald As Single
- max1 = 0
- max2 = 0
- max3 = 0
- max4 = 0
- For J = 1 To I
- d2(J) = x(J) ^ 2 + y(J) ^ 2
- ' Debug.Print d2(J)
- Next
- End Sub
复制代码
在 Redim x(1 To I + 1) As Integer 之前,先把 x array 的 value 存在一个 Temp Array。 Assign x(I) 之后,再把 Temp Array 的 value 存回去 x array。 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|