Helo, Only me again, from all of my random attempts of trying to find a soultion for this i found one so i thought i would post the solution. when u define the array as a class you have to define it with a random figure i.e. public Temp(0) as Sub_Class then in the subroutine 'New' for the class "Sub_Class" you call a subroutine called create_X() Public Test as new Temp_Class(8,1,2) ..... ..... Public Class Temp_Class ..... public Temp(0) as Sub_Class ..... Private x_Value as integer Private y_Value as integer Private z_Value as integer ..... Public Sub New(ByVal x_val, ByVal y_val, ByVal z_val) ReDim Temp(Temp_Class.X) x_value = x_val y_value = y_val z_value = z_val Create_X() End Sub .... Public Sub Create_X() Dim temp_X As New Sub_Class Dim n As Integer Public Sub Create_X() For n = 0 To Temp_Class.X Me.Sub_Class(n) = temp_X Next End Sub .... .... End Class Public Class sub_Class ..... public Temp2(0) as Sub_Sub_Class ..... Public Sub New() ReDim Temp2(Temp_Class.Y) ..... Create_Y() End Sub .... Public Sub Create_Y() Dim temp_Y As New Sub_Sub_Class Dim n As Integer Public Sub Create_Y() For n = 0 To Temp_Class.Y Me.Sub_Sub_Class(n) = temp_Y Next End Sub .... .... End Class
this relies on the fact hta default values have been put into the sub_Class and Sub_Sub_Class Properties in the subroutine new() and also relies on the fact the initaliation 'Test' class being called with overload. if this approach is then taken you are effectivly creating defualt values for thouse classes and by doesing so removes the problem of the computer bringing up Null References Sorry if this isnt very clear but someone else might be able to write it up more clearly if they can understand what i mean.
bonio55
Posts
-
Array of classes within a Class -
How can I connect WebCam to my ApplicationI have just used the same kind of thing on one of my projects. I cant remember where i got this code from but it works. This is how i decided to implement it you can mess around with it to how u want it once you have it working. 1) Create a picture box and call it "picCapture" 2) Create a list box and call it "Video_Sources" 3) Create a Button Called "Change_Video_Apply" 4) Create a Buttin Called "Change_Video_Source" On the Form designer place the Button and List box 'Behind' the Picture box. Make sure the pic box has a ratio of 4:3 for its Width:Height - stops streching Copy these into your form class Place this with you declerations i.e. before subroutines
#Region "Webcam Defines" Const WM_CAP As Short = &H400S Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10 Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11 Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30 Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50 Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52 Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53 Const WS_CHILD As Integer = &H40000000 Const WS_VISIBLE As Integer = &H10000000 Const SWP_NOMOVE As Short = &H2S Const SWP_NOSIZE As Short = 1 Const SWP_NOZORDER As Short = &H4S Const HWND_BOTTOM As Short = 1 Dim iDevice As Integer = 0 Friend WithEvents SerialPort1 As System.IO.Ports.SerialPort Friend WithEvents Button3 As System.Windows.Forms.Button Friend WithEvents Timer1 As System.Windows.Forms.Timer Friend WithEvents Button4 As System.Windows.Forms.Button ' Current device ID Dim hHwnd As Integer ' Handle to preview window Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _ ByVal lParam As Object) As Integer Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _ ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _ ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _ (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _ ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _ ByVal nHeight As Short, ByVal hWndParent As Inte
-
Array of classes within a ClassHello, I currently have a problem that i have thought of a soultion for but im unsure of how i can implement this. Problem: I have an new instance of a class, lets call it "Temp_Class" and within that class there are some properties x,y,z and say 6 instances of another class "Sub_Class". There may be 1 instance of "Sub_Class" or as many as 100 depending on Property X which is an integer. Just like the "Temp_Class", "Sub_Class" contains some Properties A,B,C and up to 5 instance of a thrid class "Sub_Sub_Class" which just contains properties D,E,F. I wanted to be able to referance each of the "Sub_Sub_Class" properties by using arrays so that i can set a varing amount of Sub_Classes or Sub_Sub_Classes where nessercary but for this i would need to create a new instance of each class. The problem with defining an array as a class is that it wont allow me to define it as a new class for some reason.
Public Temp_Class Private X_Value Private Y_Value Private Z_Value Public Property X .............(Get and Set are tested and are known to work) Public Property Y ............. Public Property Z ............. Public Array_1(X_Value) as Sub_Class End Class Public Sub_Class Private A_Value Private B_Value Private C_Value Public Property A ............. Public Property B ............. Public Property C ............. Public Array_2(Y_Value) as Sub_Sub_Class End Class Public Sub_Sub_Class Private D_Value Private E_Value Private F_Value Public Property D ............. Public Property E ............. Public Property F ............. End Class
The Idea is that you can then Referance any D,E,F propery as follows.Dim Test as new Temp_Class Test.Sub_Class(0).Sub_Sub_Class(0).D = "Hello" '(assuming 'D' is a String) Test.Sub_Class(0).Sub_Sub_Class(1).D = "Test" Test.Sub_Class(0).Sub_Sub_Class(2).D = "Hello" Test.Sub_Class(0).Sub_Sub_Class(3).D = "Test" Test.Sub_Class(1).Sub_Sub_Class(0).D = "Hello" Test.Sub_Class(1).Sub_Sub_Class(1).D = "Test" Test.Sub_Class(2).Sub_Sub_Class(2).D = "Hello" Test.Sub_Class(2).Sub_Sub_Class(3).D = "Test"
I have been able to get this working but only if dont use arrays, but then everything becomes alot more complicated. i.e. (tested and works, where items have been defined as new instances)Test.Sub_Class_0.Sub_Sub_Class_0.D = "Hello" Test.Sub_Class_0.Sub_Sub_Class_1.D = "Test" Test.Sub_Class_1.Sub_Sub_Class_0.D = "Hello" Test.Sub_Class_1.Sub_Sub_Class_1.D = "Test"<