发新话题
打印

自定义类型数组怎么付值

自定义类型数组怎么付值

private type fs
fz as vriant
fm as integer
end type
dim sz() as fs
n=gesuo(text1.text)     '一个得到字符串内数字和符号个数的函数
redim sz(n) as fs
for i=1 to n
fz.sz(i)=mid(text1.text,i,1)
next i
for i=n to 1 step -1
text2.text=text2.text&fz.sz(i)
next i
请高手指点,哪里错了啊?
系统提示fz.sz(i)末定义,可定义了呀

TOP

不行啊
数组里的内容是空啊
不管是哪个,返回的都是0
是不是在一开始给动态数组分配了空间,再向里面写数据不行啊

TOP

请高手看看,哪里错了啊

看看动态数组应该定义多大
Public Function gesuo(text As String) As Integer
Dim i, n As Integer
Dim fh As String
n=1
For i = 1 To Len(text)

fh = Mid(text, i, 1)
Select Case fh
Case Is = "+"
n = n + 2

Case Is = "-"
n = n + 2

Case Is = "*"
n = n + 2

Case Is = "/"
n = n + 2

Case Is = "^"
n = n + 2

Case Is = "("
n = n + 2

Case Is = ")"
n = n + 2
End Select
Next i
gesuo = n + 2
End Function

把字符串中的数字给数组

Public Sub tiqu(n As Integer)
n = gesuo(Text1.text)
ReDim sz(n) As fs
Dim xiaosuo, fensuo As Boolean
Dim fh, kong As String
Dim a, b As Integer
a = 1
b = 1
Dim temp, temp1, temp2 As String
For i = 1 To Len(Text1.text)
fh = Mid(Text1.text, i, 1)
If Val(fh) >= 0 And Val(fh) <= 9 Then
temp = temp + fh
  If xiaosuo = True Then
  b = b * 10
  End If
Else: Select Case fh
Case Is = "."
xiaosuo = True
Case Is = ","
temp1 = temp
temp = kong
Case Is = "_"
temp2 = temp
temp = kong
fensuo = True
Case Else
   If xiaosuo = True Then
   sz(a).fz = Val(temp)
   sz(a).fm = b
   b = 1
   temp = kong
   xiaosuo = False
   a = a + 1
   sz(a).fz = fh
   a = a + 1
   Else
     If fensuo = True Then
     sz(a).fz = Val(temp1) * Val(temp) + Val(temp2)
     sz(a).fm = Val(temp)
     temp = kong
     temp1 = kong
     temp2 = kong
     a = a + 1
     sz(a).fz = fh
     a = a + 1
   Else
     sz(a).fz = Val(temp)
     sz(a).fm = 1
     a = a + 1
     sz(a).fz = fh
     a = a + 1
     End If
End Select
End If
Next i
End Sub

TOP

n的值没事啊,我试过了.最后还是提示下标越界
为什么啊
我感觉是给sz()付值 的时候出问题了,可问题是不知道问题出在哪里了啊

TOP

For i = 1 To Len(Text1.text)
能有什么问题啊
还有就是我在一开始就用option base 1定义了数组下标
问题主要是不能给数组付值,但有的时候能成功,但结果是0
这个问题不解决,下面的工作没法作啊!还望班主再想想法啊

TOP

发新话题