注册 登录
编程论坛 VB6论坛

调用子工程时,一个实参是自定义机构数组,为什么调用老出错呢?

木吉他ll 发布于 2013-04-24 10:09, 1215 次点击
Call interpolation(Param(10).MOE, TAverage, E)
为什么总是弹出类型不匹配:缺少数组或用户定义类型
但是我已经定义过了
Private Type DataBase
MOE As Single
PR As Single
K As Single
HOT As Single
Drift As Single
Creep As Single
End Type
dim param(10) as database
11 回复
#2
xbj_hyml2013-04-24 11:40
能不能附上 一段全一点的代码
    因为我用你这些代码 测了下 没什么错误...
#3
Artless2013-04-24 12:37
interpolation原形?
#4
风吹过b2013-04-24 15:20
Call interpolation(Param(10).MOE, TAverage, E)

看你的传进去的参数,全是 具体的 参数,没有传数组进去。

interpolation 的定义是什么??
#5
木吉他ll2013-04-24 18:08
回复 2楼 xbj_hyml
Public Sub interpolation(Data() As Single, ByVal T As Single, ByRef Y As Single)

   Dim TT(10) As Integer                     '数据库里边的温度数组
   Dim h(9) As Single
   Dim u(1 To 9) As Single
   Dim λ(1 To 9) As Single
   Dim g(10) As Single
   Dim i As Integer
   Dim j As Integer
   Dim yy0 As Single                         '边界条件
   Dim yy10 As Single                        '边界条件
   Dim gmm As Single                         '中间变量
   Dim p As Single                           '中间变量
   Dim q As Single                           '中间变量
   Dim m(10) As Single                       '解空间
   Dim aa(0 To 10, 0 To 10) As Single        '系数矩阵

   yy0 = 0                                  '自然边界条件
   yy10 = 0

   TT(0) = 20
   TT(1) = 100
   TT(2) = 200
   TT(3) = 300
   TT(4) = 400
   TT(5) = 500
   TT(6) = 600
   TT(7) = 700
   TT(8) = 800
   TT(9) = 900
   TT(10) = 1000

   For i = 0 To 9 Step 1
       h(i) = TT(i + 1) - TT(i)
   Next i
 
   For i = 1 To 9 Step 1
       u(i) = h(i - 1) / (h(i - 1) + h(i))
   Next i

   For i = 1 To 9 Step 1
      λ(i) = h(i) / (h(i - 1) + h(i))
   Next i

   For i = 1 To 9
       gmm = (Data(i + 1) - Data(i)) / h(i) - (Data(i) - Data(i - 1)) / h(i - 1)
       g(i) = 6 * gmm / (h(i) + h(i - 1))
   Next i
   
   g(0) = 6 * ((Data(1) - Data(0)) / h(0) - yy0) / h(0)
   g(10) = 6 * (yy10 - (Data(10) - Data(9)) / h(9)) / h(9)
   
   For i = 0 To 10                     '系数矩阵清零
       For j = 0 To 10
           aa(i, j) = 0
       Next j
   Next i

   aa(0, 0) = 2                       '为系数矩阵赋值
   aa(0, 1) = 1

   For i = 1 To 9
       aa(i, i) = 2
       aa(i, i - 1) = u(i)
       aa(i, i + 1) = λ(i)
   Next i

   aa(10, 9) = 1
   aa(10, 10) = 2
   
   For i = 1 To 10                    '矩阵的对角化
       p = aa(i - 1, i - 1) / aa(i, i - 1)
       g(i) = g(i) * p - g(i - 1)
       For j = 0 To 10
           aa(i, j) = aa(i, j) * p - aa(i - 1, j)
       Next j
   Next i

   m(10) = g(10) / aa(10, 10)
   For i = 9 To 0 Step -1
       q = 0
       For j = 10 To i + 1 Step -1
           q = q + aa(i, j) * m(j)
       Next j
       m(i) = (g(i) - q) / aa(i, i)
   Next i

   For i = 0 To 9
       If T >= TT(i) And T <= TT(i + 1) Then
          Y = (m(i) * (TT(i + 1) - T) ^ 3) / (6 * h(i)) + (m(i + 1) * (T - TT(i)) ^ 3) / (6 * h(i)) + (Data(i) - (m(i) * h(i) ^ 2) / 6) * (TT(i + 1) - T) / h(i) + (Data(i + 1) - (m(i + 1) * h(i) ^ 2) / 6) * (T - TT(i)) / h(i)
       End If
   Next i

End Sub
这是interpolation
#6
木吉他ll2013-04-24 18:19
回复 4楼 风吹过b
Private Sub Edit_Materialparatemer_Click()

   Form4.Show 1

   Dim cn As New ADODB.Connection
   Dim cmd As New
   Dim rs As ADODB.Recordset
   Dim i As Integer
   Dim nMaterial As Integer
   Dim Name As String

   i = 0
   nMaterial =
   Select Case nMaterial
          Case 0:
               Name = "C/SIC"
          Case 1:
               Name = "CH99"
          Case 2:
               Name = "UHTC-A"
   End Select
'///////////////////////////////////////////////////////////////////////////////////////数据库

   cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\material.mdb"          '链接数据库
   Set cmd.ActiveConnection = cn
    = adCmdUnknown
    = "select * from 材料属性 where 材料名='" & Name & "'"
   Set rs = cmd.Execute
   
   Do While Not rs.EOF
      With Parameter(i)
           .MOE = rs.Fields("弹性模量")
           .PR = rs.Fields("泊松比")
      End With
      rs.MoveNext
      i = i + 1
   Loop
   
End Sub
#7
木吉他ll2013-04-24 18:20
回复 4楼 风吹过b
以上是我写的函数,就是不知道哪里出错了
#8
木吉他ll2013-04-24 20:30
回复 4楼 风吹过b
Public Sub interpolation(Data() As Single, ByVal T As Single, ByRef Y As Single)

   Dim TT(10) As Integer                     '数据库里边的温度数组
   Dim h(9) As Single
   Dim u(1 To 9) As Single
   Dim λ(1 To 9) As Single
   Dim g(10) As Single
   Dim i As Integer
   Dim j As Integer
   Dim yy0 As Single                         '边界条件
   Dim yy10 As Single                        '边界条件
   Dim gmm As Single                         '中间变量
   Dim p As Single                           '中间变量
   Dim q As Single                           '中间变量
   Dim m(10) As Single                       '解空间
   Dim aa(0 To 10, 0 To 10) As Single        '系数矩阵

   yy0 = 0                                  '自然边界条件
   yy10 = 0

   TT(0) = 20
   TT(1) = 100
   TT(2) = 200
   TT(3) = 300
   TT(4) = 400
   TT(5) = 500
   TT(6) = 600
   TT(7) = 700
   TT(8) = 800
   TT(9) = 900
   TT(10) = 1000

   For i = 0 To 9 Step 1
       h(i) = TT(i + 1) - TT(i)
   Next i

   For i = 1 To 9 Step 1
       u(i) = h(i - 1) / (h(i - 1) + h(i))
   Next i

   For i = 1 To 9 Step 1
      λ(i) = h(i) / (h(i - 1) + h(i))
   Next i

   For i = 1 To 9
       gmm = (Data(i + 1) - Data(i)) / h(i) - (Data(i) - Data(i - 1)) / h(i - 1)
       g(i) = 6 * gmm / (h(i) + h(i - 1))
   Next i
   
   g(0) = 6 * ((Data(1) - Data(0)) / h(0) - yy0) / h(0)
   g(10) = 6 * (yy10 - (Data(10) - Data(9)) / h(9)) / h(9)
   
   For i = 0 To 10                     '系数矩阵清零
       For j = 0 To 10
           aa(i, j) = 0
       Next j
   Next i

   aa(0, 0) = 2                       '为系数矩阵赋值
   aa(0, 1) = 1

   For i = 1 To 9
       aa(i, i) = 2
       aa(i, i - 1) = u(i)
       aa(i, i + 1) = λ(i)
   Next i

   aa(10, 9) = 1
   aa(10, 10) = 2
   
   For i = 1 To 10                    '矩阵的对角化
       p = aa(i - 1, i - 1) / aa(i, i - 1)
       g(i) = g(i) * p - g(i - 1)
       For j = 0 To 10
           aa(i, j) = aa(i, j) * p - aa(i - 1, j)
       Next j
   Next i

   m(10) = g(10) / aa(10, 10)
   For i = 9 To 0 Step -1
       q = 0
       For j = 10 To i + 1 Step -1
           q = q + aa(i, j) * m(j)
       Next j
       m(i) = (g(i) - q) / aa(i, i)
   Next i

   For i = 0 To 9
       If T >= TT(i) And T <= TT(i + 1) Then
          Y = (m(i) * (TT(i + 1) - T) ^ 3) / (6 * h(i)) + (m(i + 1) * (T - TT(i)) ^ 3) / (6 * h(i)) + (Data(i) - (m(i) * h(i) ^ 2) / 6) * (TT(i + 1) - T) / h(i) + (Data(i + 1) - (m(i + 1) * h(i) ^ 2) / 6) * (T - TT(i)) / h(i)
       End If
   Next i

End Sub
这是interpolation  
我感觉没有错呀,为什么老有问题,谢谢指点  
#9
lowxiong2013-04-24 20:48
过程interpolation第一个参数是浮点类型的数组,而你传进去的是一个浮点类型的单个变量(Param(10).MOE是一个属于Param数组中的单个浮点变量),当然提示类型不匹配了。
#10
木吉他ll2013-04-24 21:02
回复 9楼 lowxiong
那应该怎样写呀,难道要写成 Call interpolation(Parameter().MOE, TAverage, E),我也试过,还是有错误弹出
#11
风吹过b2013-04-25 08:13
那你整个传 DataBase 类型的数组进去吧。
在使用时,引用其对象就是了。有可能这个 结构的定义要放到模块里,并且定义为 公用 结构。

Public Sub interpolation(Data() As DataBase, ByVal T As Single, ByRef Y As Single)
................
   For i = 1 To 9
       gmm = (Data(i + 1).MOE - Data(i).MOE) / h(i) - (Data(i).MOE - Data(i - 1)).MOE / h(i - 1)
       g(i) = 6 * gmm / (h(i) + h(i - 1))
   Next i
   
   g(0) = 6 * ((Data(1).MOE - Data(0).MOE) / h(0) - yy0) / h(0)
   g(10) = 6 * (yy10 - (Data(10).MOE - Data(9).MOE) / h(9)) / h(9)
.................
#12
xbj_hyml2013-04-25 11:51

1、Call interpolation(Param(10).MOE, TAverage, E)——这个传进去的是 Param 数组中 下标=10 的元素的MOE 属性值,只是一个Single类型的值
2、Public Sub interpolation(Data() As Single, ByVal T As Single, ByRef Y As Single)——这个是要求传递一个 Single类型的数组
Param 跟Data的关系:Param(1).MOE = Data(1) ,作为形参 ,2者不能关联上(在我看来)
所以 如果你的Interpolation 需要保留的话 ,就再声明一个 Single类型的数组temp() as Single,然后 将Param(i).MOE赋给 temp(i)

1