Chanfx
19-07-2006, 10:29 AM
Gimana yah cara bikin object array yg dinamis??
misalnya gw mo pasang button 100 buah gmn codingnya?
sidhi
19-07-2006, 02:52 PM
try to read this :
Dynamic Arrays
Arrays because of their uniqeness can consum alot of memory if your not carefull. For example:
Dim MyArray (10000) As Long
Will require 40,004 bytes of memory. That is 10 x 10,001 because long variables take up 4 bytes of memory. This might not be alot now, but if you start using 10 of these array, they consume 4,000,400 bytes. This is why most of the time it is wise you set large arrays to minimum at the start, and later resize them during runtime. Yes, you can do this! This can be done using the ReDim function. Arrays that change size during runtime are called dynamic arrays. Its that simple.
When you declare a dynamic array, you don't need to declare it like a fixed array. When you declare a dynamic array the size is not specified. Instead you use the following syntax:
Dim ArrayName() As DataType
Every thing here is the same as before, Dim the array (can set to Global if using in a module, or public if in procedure), ArrayName is the name, and DataType is as said before. Heres how to use the ReDim function:
ReDim ArrayName(LowerValue To HigherValue)
You can use this either in a procedure or function. Its almost like when you declare it except you use ReDim, don't use a datatype, and are not declareing it. That is, it must already be declared. Here is an example of how to do this:
Dim Names() As String
Sub Form1_Load()
ReDim Names(1 To 10)
End Sub
This code assigns 10 elements to Names when Form1 loads. Note: When using dynamic arrays, you must set the size of an array using the ReDim statement, before filling the array.
However, when using the ReDim statement, any values already in the array (if it has been resized previously), will be deleted. In some cases, this is not what you would want! So, you use the Preserve keyword:
ReDim Preserve ArrayName(LowerValue To HigherValue)
If the array has grown, there will be a number of blank array spaces at the end of the array. If the array has shrunk, you will lose the end items.
http://www.geocities.com/alpha_productions2/vb_arrays.htm#Dynaming
password
19-07-2006, 04:41 PM
Gimana yah cara bikin object array yg dinamis??
misalnya gw mo pasang button 100 buah gmn codingnya?
coba kamu taruh satu object button di form.. misalnya dikasih nama btnTest
lalu di propertinya indexnya kamu kasih nilai 0..
berarti kamu akan membuat control array utk button ini...
selanjutnya terserah kamu mau dimana initiate button lainnya..
misalnya pada saat load form.. kamu taruh aja kode seperti ini
dim i as integer
For i = 1 To 100
Load btnTest(i)
Next
kamu juga bisa memodifikasi button2 baru tersebut.. misal letaknya dimana dengan menset property left dan top masing2 button tersebut..
Chanfx
20-07-2006, 09:14 AM
terima kasih atas bantuannya sodara2 sekalian.... ^_^
Chanfx
22-07-2006, 09:15 AM
Maaf...tanya lagi. Gimana caranya menghapus object secara coding?
misal button yang 100 buah itu setelah digunakan mau di hapus??
ruboW
18-08-2006, 08:50 AM
kayaknya gak bisa di hapus deh (object khan kalau gak salah)
biasanya pakai perintah destroy??
kalau gak bisa ya terpaksa di HIDE!!
buton(1).hide
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.