Vb structure in the body can define an array? Why I don't change the structure dimension of an array of upper and lower, led to the back when I assigned to the "" System. NullReferenceException" type of untreated exception ", the HTML code is as follows, wish you a great god help solve, the younger brother grateful!
Structure chorm
Dim bit () As an Integer
Dim fit As Single
End Structure
Public popcurrent (3) As chorm
Public Sub startpop ()
Dim I As an Integer, j As an Integer, the random As an Integer, the value As Single
For I=0 To 3
For j=0 To 5
The random=Rnd ()
The random=random Mod 2
Popcurrent (I) - (j)=random
Next
'modelvalue (popcurrent (I))
'popcurrent (I)=the fit the fitness ()
Next
End Sub
CodePudding user response:
Dim bit (5) As an Integer 'using fixed-length Integer array
CodePudding user response:
Don't listen to zhao four, the type can be defined inside the dynamic array,
Take a chestnut
Private Type test Inttst As Integer 'plastic member Arytst () As an Integer members' dynamic array End Type Private Sub Command1_Click () Dim As Integer I Dim As a test ReDim a.a rytst (5) members' define array Anderson NTTST=100 'integer members assignment For I=0 To 5 'members of the array assignment A.a rytst (I)=I * 2 Next The Debug. Print a.a rytst (5) 'test results ReDim a.a rytst (10) 'again redefine array members For I=0 To 10 'members of the array assignment A.a rytst (I)=I * 3 Next The Debug. Print a.a rytst (10) 'test results End Sub CodePudding user response:
refer to the second floor chewinggum response: , don't listen to zhao four type can be defined inside a dynamic array, Take a chestnut Private Type test Inttst As Integer 'plastic member Arytst () As an Integer members' dynamic array End Type Private Sub Command1_Click () Dim As Integer I Dim As a test ReDim a.a rytst (5) members' define array Anderson NTTST=100 'integer members assignment For I=0 To 5 'members of the array assignment A.a rytst (I)=I * 2 Next The Debug. Print a.a rytst (5) 'test results ReDim a.a rytst (10) 'again redefine array members For I=0 To 10 'members of the array assignment A.a rytst (I)=I * 3 Next The Debug. Print a.a rytst (10) 'test results End Sub And external DLL or Windows API properly defined in the structure of a communication? CodePudding user response:
See "code syntax" of the building Lord, should be VB.NET! In VB6, "structure" defined in the dynamic array, fixed array is no problem, Difference is that: with fixed array, "data element space" is according to the type, quantity, etc., directly in the "structure" members of the space; But with "dynamic array", it is just a "array pointer" (no matter what type, whether "has an array element", etc.), always occupied space of 4 bytes, Estimated at VB.NET, the characteristics, should with VB6 is the same, only the specific "use details" might be a little difference on Even "is a little difference is mainly due to differences in grammar, you can ignore, CodePudding user response:
reference zhao4zhong1 reply: 3/f Quote: refer to the second floor chewinggum response: Don't listen to zhao four, the type can be defined inside the dynamic array, Take a chestnut Private Type test Inttst As Integer 'plastic member Arytst () As an Integer members' dynamic array End Type Private Sub Command1_Click () Dim As Integer I Dim As a test ReDim a.a rytst (5) members' define array Anderson NTTST=100 'integer members assignment For I=0 To 5 'members of the array assignment A.a rytst (I)=I * 2 Next The Debug. Print a.a rytst (5) 'test results ReDim a.a rytst (10) 'again redefine array members For I=0 To 10 'members of the array assignment A.a rytst (I)=I * 3 Next The Debug. Print a.a rytst (10) 'test results End Sub And external DLL or Windows API properly defined in the structure of a communication? "External DLL or Windows API defined structure" are almost always "to determine the structure length", if there are members of the "array" is done with fixed array; But in "VB6 project within the" custom data types, using an array of members, the vast majority of cases must be using dynamic array, This is not to be confused with the two! CodePudding user response:
reference zhao4zhong1 reply: 3/f Quote: refer to the second floor chewinggum response: Don't listen to zhao four, the type can be defined inside the dynamic array, Take a chestnut Private Type test Inttst As Integer 'plastic member Arytst () As an Integer members' dynamic array End Type Private Sub Command1_Click () Dim As Integer I Dim As a test ReDim a.a rytst (5) members' define array Anderson NTTST=100 'integer members assignment For I=0 To 5 'members of the array assignment A.a rytst (I)=I * 2 Next The Debug. Print a.a rytst (5) 'test results ReDim a.a rytst (10) 'again redefine array members For I=0 To 10 'members of the array assignment A.a rytst (I)=I * 3 Next The Debug. Print a.a rytst (10) 'test results End Sub And external DLL or Windows API properly defined in the structure of a communication? Whether an chestnuts which the inside of the Windows API struct array are there? I currently use API involves long information uncertainty in the function prototype is a pointer, Requirements of the building Lord now only used within a program, demand is uncertain array! In view of the need to solve the problem, not to expand application scenario for the increased meaningless debate is unnecessary, CodePudding user response:
reference 4 floor Chen8013 response: see "code syntax" of the building Lord, should be VB.NET! In VB6, "structure" defined in the dynamic array, fixed array is no problem, Difference is that: with fixed array, "data element space" is according to the type, quantity, etc., directly in the "structure" members of the space; But with "dynamic array", it is just a "array pointer" (no matter what type, whether "has an array element", etc.), always occupied space of 4 bytes, Estimated at VB.NET, the characteristics, should with VB6 is the same, only the specific "use details" might be a little difference on Even "is a little difference is mainly due to differences in grammar, you can ignore,