Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

declaring public array

DorisTanDorisTan Posts: 12Member
Hi;

i search thru the forum but failed to find the solution that i want...
i am using vb6, my problem is i would like to declare a public array with 2 dimension, but an error message prompted and tell me that it is not allowed to do so, so after searching the net i using the LET and GET method but i still not really know how to use it, can someone help? below is my code:

***********************************************************************
in my class1:

Private GraphicArr(1 To 2, 50) As String

Public Property Get GArray(ShpType As Integer, ShpNo As Integer) As String
GArray = GraphicArr(ShpType, ShpNo)
End Property

Public Property Let GArray(ShpType As Integer, ShpNo As Integer, Value As String)
GraphicArr(ShpType, ShpNo) = Value
End Property

***********************************************************************

i would like to know in my main form, how can i set the value by calling the GArray and how do i call back to retrieve the value?

really need your help, please......

Thanks :)

Comments

  • GenjuroGenjuro Posts: 913Member
    [b][red]This message was edited by Genjuro at 2005-1-4 9:31:9[/red][/b][hr]
    : Hi;
    :
    : i search thru the forum but failed to find the solution that i want...
    : i am using vb6, my problem is i would like to declare a public array with 2 dimension, but an error message prompted and tell me that it is not allowed to do so, so after searching the net i using the LET and GET method but i still not really know how to use it, can someone help? below is my code:
    :
    : ***********************************************************************
    : in my class1:
    :
    : Private GraphicArr(1 To 2, 50) As String
    :
    : Public Property Get GArray(ShpType As Integer, ShpNo As Integer) As String
    : GArray = GraphicArr(ShpType, ShpNo)
    : End Property
    :
    : Public Property Let GArray(ShpType As Integer, ShpNo As Integer, Value As String)
    : GraphicArr(ShpType, ShpNo) = Value
    : End Property
    :
    : ***********************************************************************
    :
    : i would like to know in my main form, how can i set the value by calling the GArray and how do i call back to retrieve the value?
    :
    : really need your help, please......
    :
    : Thanks :)

    I am assuming that code is written inside a "class module" ("class1" hints to that), in a standard EXE project.

    To use that array, first of all, you should declare your "class1" object, so put:
    [code]private GraphHelper as class1[/code]
    in your "global declarations" section of the form.

    Then you should instance it inside your Form_Load procedure:
    [code]Set GraphHelper = new class1[/code]

    Once you do so, you can freely use your array.
    VB will call let and get when you try to assign a value to an array item (Let) or read an item from the array (Get). if you're unsure of how it works, just put in the Get and Let procedures a breakpoint.

    Anyway, if you write:
    [code] GraphHelper.GArray(1, 2) = "MyValue"[/code]
    VB, upon compiling, will roughly translate this to:
    [code] GraphHelper.Let_GArray(1, 2, "MyValue")[/code]
    which explains about the extra parameter in the Let property.

    Writing:
    [code]
    Dim s as string
    s = GraphHelper.GArray(1, 2)[/code]
    will translate to:
    [code] s = GraphHelper.Get_GArray(1, 2)[/code]

    I hope it's clearer. Now for a few more hints:

    - Using a standard module instead of a class module might be handier, since it means you don't have to declare and instance it (and use the "object.property" call either). Class modules are meant for classes - things you can have multiple "copies" of. You can simply cut and paste the code in your "class1" module (the same you posted here) into a standard module, and then forget about everything said above and use it like you would with any global array named GArray (well, except ReDim).

    - The array declaration you posted is fine and well, but the second dimension has no lower bound. I'd declare it as "Private GraphicArr(1 To 2, [b]1 to[/b] 50) As String ". More like a style thing, but are you sure that lower array bounds are the ones you expect them to be? As a rule of thumb, when in doubt, always specify.

    - Again for the array declaration: defining a lower bound of 1 for arrays is fine and well; however, it your program has a future, you'd better plan for VB.NET compatibility in advance and save pain later. In VB.NET ("VB7", although actually no VB at all), all arrays are zero-based, so it's safer to zero-base them ("Private GraphicArr(0 To 1, 0 to 49) As String "). While it's pretty painless for you to do so in VB6, it won't be as painless if you will ever need to find all the indexes in your code to decrease them by one to convert it to VB.NET. Again, it might not be your case. On a side note, I'm not sure about Option Base in VB.NET, so if you're using it, don't trust it too much.

    EDIT: infidel pointed me out a copy-and-paste error :/
  • infidelinfidel Posts: 2,900Member
    : Writing:
    : [code]
    : Dim s as string
    : s = GraphHelper.GArray(1, 2) = "MyValue"[/code]
    : will translate to:
    : [code] s = GraphHelper.Get_GArray(1, 2)[/code]

    Are you sure about that? Won't s hold a boolean value?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • GenjuroGenjuro Posts: 913Member
    : : Writing:
    : : [code]
    : : Dim s as string
    : : s = GraphHelper.GArray(1, 2) = "MyValue"[/code]
    : : will translate to:
    : : [code] s = GraphHelper.Get_GArray(1, 2)[/code]
    :
    : Are you sure about that? Won't s hold a boolean value?
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]

    Well, yes and no.
    It would contain a boolean value converted to a string.

    Actually, I edited the post... I made a copy-and-paste typo back there, thank you for pointing it out :/
Sign In or Register to comment.