OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Problems accessing array of user type by index

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
daikcu
Newbie
Newbie


Joined: 10 Feb 2011
Posts: 2

PostPosted: Thu Feb 10, 2011 4:37 am    Post subject: Problems accessing array of user type by index Reply with quote

I have problems accessing an array of user define type by index. If I access through a For Each loop, I don't have the problem.

This is my code:
Code:

Type UserType
   number As Integer
   content As String
End Type

Sub Test
Dim userTypeArray(2) As UserType
For i = 0 To 2
   Dim myVar As UserType
   myVar.number = i
   myVar.content = "Content#" & i
   userTypeArray(i) = myVar
Next i
msg = "Index access" & Chr(13)
For i = LBound(userTypeArray) To UBound(userTypeArray)
   msg = msg & userTypeArray(i).number & "+" & userTypeArray(i).content & Chr(13)
Next i
msg = msg & "For-each access" & Chr(13)
For each element in userTypeArray
   msg = msg & element.number & "-" & element.content & Chr(13)
Next element
MsgBox msg
End Sub


The result of the msgbox is:
Quote:
Index access
0+
0+
0+
For-each access
0-Content#0
1-Content#1
2-Content#2


I need index access, so any idea will be appreciated.

Thank you
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Thu Feb 10, 2011 5:21 am    Post subject: Reply with quote

Hi,
User types are hardly supported in OOoBasic...
However, change one instruction to solve your problem:
Code:
Dim userTypeArray(2) As Variant

_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
daikcu
Newbie
Newbie


Joined: 10 Feb 2011
Posts: 2

PostPosted: Thu Feb 10, 2011 5:43 am    Post subject: Reply with quote

That solved the problem. Thank you very much.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group