Linux Basic
September 05, 2010, 11:05:40 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Linux Basic forums have just been installed. This, I hope, will be the place to talk about the new breed of Basics coming out for the Linux operating system. A place to get informed as well as help each other out with programming and installation issues. Be warned, I am as green as you are. I am here to learn as well.
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: How do I declare & use array properties in a class?  (Read 1035 times)
SteveDee
Newbie
*
Posts: 26


« on: December 07, 2009, 06:40:44 AM »

I know I'm still locked into my old VB.Classic mind set, but how should you code for array properties in a class?

In VB I would do something like this:-

Code:
Dim mstrContactName(100)as string

Public Property Get strContactName(ByVal lngIndex As Long) As String

    strContactName = mstrContactName(lngIndex)

End Property

Private Property Let strContactName(ByVal lngIndex As Long, ByVal strNew As String)

    mstrContactName(lngIndex) = strNew

End Property

But in Gambas you can't pass variables to a Property. So I have to result to using a method like this:-

Code:
PUBLIC FUNCTION GetContactName(lngIndex AS Long) AS String
 
  RETURN strContact[lngIndex]
 
END

PUBLIC FUNCTION LetContactName(lngIndex AS Long, strNew as String) AS String
 
  strContact[lngIndex] = strNew
 
END

So my question: Is there a better way?
Logged
Linux Basic
« on: December 07, 2009, 06:40:44 AM »

Create 3D Art for Free
 Logged
enricopallawitschini
Newbie
*
Posts: 5


« Reply #1 on: February 17, 2010, 01:40:45 PM »

Just declare Property as String[]!?

Like:

Property Something as String[]

Private $Something as String[]
PUBLIC FUNCTION Something_Read() AS String[]
 
  RETURN $Something
 
END

PUBLIC SUB Something_Write(Value as String[])
 
  $Something=Value = strNew
 
END


And from Outside just use it like an array(which it is).

MyClass.Something.Add(Value,Index)
MyString=MyClass.Something[index]
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!