佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1008|回复: 4

-- closed --

[复制链接]
发表于 8-2-2010 03:36 PM | 显示全部楼层 |阅读模式
本帖最后由 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) 帶不到下面這里的??
誰可以幫我改改一下
感激不盡
回复

使用道具 举报


ADVERTISEMENT

发表于 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,你可以试一下:

  1. Option Explicit
  2. Dim Xx As Integer
  3. Dim Yy As Integer
  4. Dim I As Integer
  5. Dim J As Integer
  6. Dim TempxArr() As Integer, TempyArr() As Integer
  7. Dim x() As Integer, y() As Integer
  8. Private Sub cmdAdd_Click()
  9. Dim k As Integer
  10. If I > 0 Then
  11.     ReDim TempxArr(I) As Integer
  12.     ReDim TempyArr(I) As Integer
  13.     For k = 1 To I
  14.         TempxArr(k) = x(k)
  15.         TempyArr(I) = y(k)
  16.     Next
  17. End If
  18. I = I + 1
  19. ReDim x(1 To I + 1) As Integer
  20. ReDim y(1 To I + 1) As Integer
  21. ReDim P(1 To I + 1) As Single
  22. x(I) = txtx.Text
  23. y(I) = txty.Text
  24. P(I) = txtp.Text
  25. Label2.Caption = "Station " & I + 1
  26. Label5.Caption = x(I)
  27. List1.AddItem (Label2.Caption) & "          " & (x(I)) & "          " & (y(I)) & "          " & (P(I))
  28. For k = 1 To I - 1
  29.     x(k) = TempxArr(k)
  30.     y(k) = TempyArr(k)
  31. Next
  32. End Sub
  33. Private Sub cmdCalc_Click()
  34. '''Dim x(7) As Single
  35. '''Dim y(7) As Single
  36. '''Dim P(7) As Single
  37. ReDim d2(1 To I) As Single
  38. ReDim di(1 To I) As Single
  39. ReDim perd2(1 To I) As Single
  40. ReDim Pi(1 To I) As Single
  41. Dim W1 As Single
  42. Dim W2 As Single
  43. Dim W3 As Single
  44. Dim W4 As Single
  45. Dim WP1 As Single, WP2 As Single, WP3 As Single, WP4 As Single
  46. Dim Px As Single
  47. '''ReDim x(1 To I)
  48. '''ReDim y(1 To I)
  49. '''ReDim P(1 To I)
  50. Dim max1 As Single
  51. Dim max2 As Single
  52. Dim max3 As Single
  53. Dim max4 As Single
  54. Dim Totald As Single
  55. max1 = 0
  56. max2 = 0
  57. max3 = 0
  58. max4 = 0
  59. For J = 1 To I
  60.     d2(J) = x(J) ^ 2 + y(J) ^ 2
  61. '    Debug.Print d2(J)
  62. Next
  63. End Sub
复制代码


在 Redim x(1 To I + 1) As Integer 之前,先把 x array 的 value 存在一个 Temp Array。 Assign x(I) 之后,再把 Temp Array 的 value 存回去 x array。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 29-11-2025 04:15 PM , Processed in 0.125611 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表