Results 1 to 4 of 4

Thread: [RESOLVED] How to create an array as User Defined Type ?

  1. #1

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    396

    Resolved [RESOLVED] How to create an array as User Defined Type ?

    Hi guys,
    I need to create an array of arrays so that to load 10 charts saved as bmp format in the app folder.
    Each array is loaded as byte array and I want to be considered as element of an UDT array.
    After a brief documentation online - because it is first time when I try this - I have created the following routine :
    Code:
    Private Type udtArray
        elemArray() As Byte
    End Type
    
    Private GreatArray(1 To 10) As udtArray
    
    Private Sub Form_Load()
        Dim B() As Byte, i As Byte
        
        For i = 1 To 10
            B = App.Path & "\chart(" & i & ".bmp"     'load bitmap charts from a folder
            ReDim GreatArray(i).elemArray(UBound(B))  'redim udtArray on each subArray element
            GreatArray(i).elemArray = B
        Next i
    End Sub
    For some reason the code above doesn't work properly. Is anyone who has experience with this type of arrays ? Thank you.

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: How to create an array as User Defined Type ?

    there is nothing wrong with your code. it does what it is supposed to do: store the text resulting from App.Path & "\chart(" & i & ".bmp" in the elements of GreatArray.
    the only thing that might lead you to the assumption that the code does not work is that this:
    B = App.Path & "\chart(" & i & ".bmp"
    is converting the string xxxx.bmp to a bytearray behind the scenes using unicode so the byte array b does contain the ascii values of each letter followed by a zero byte. if you do not want this unicode zero bytes you may use
    B = strconv(App.Path & "\chart(" & i & ".bmp",vbfromunicode)

    if you expect b to hold the binary data of the image rather than the filename (your code comments are not really clear in that) then you are missing the routine to read the bmp file content.

    ah and by the way: the ReDim GreatArray(i).elemArray(UBound(B)) is not required you can just assign b to GreatArray(i).elemArray. this has the same result

  3. #3

    Thread Starter
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    396

    Re: How to create an array as User Defined Type ?

    Hi Shaman,
    Meanwhile I found my bug in a class related to UDT array. The code above is correct and as you said it is not necessary to redim the elemArray. The line B = App.Path & "\chart(" & i & ".bmp", where I transfer the bitmap chart in array, is not real, but I just wanted to present the basic idea...Sorry for confusion. The real process uses a function for this purpose. With this occasion I have jut noted there are not too many vb tutorials regarding UDT arrays : how to redim, preserve, how to handle multidimensional arrays and so on. Thank you for your quick reply. It is impressive, you have joined this forum this month and you have already over 100 posts...

  4. #4
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: How to create an array as User Defined Type ?

    Quote Originally Posted by Daniel Duta View Post
    It is impressive, you have joined this forum this month and you have already over 100 posts...
    yeah, feeling a bit bored the last few weeks and thought i could try and help some others getting a bit to addicted however...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width