| | |
Some Explanation with redim statement
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 292
Reputation:
Solved Threads: 1
can anybody explain me.the use of redim statement and preserve
keyword over here.kindly let me know the idea .any help would be
Highly appreciated.
keyword over here.kindly let me know the idea .any help would be
Highly appreciated.
vb Syntax (Toggle Plain Text)
Public Function LoadData() As Boolean Dim codeString As String On Error GoTo LoadData_Error Dim Obj As IProducts '// The classinterface Dim rs As ADODB.Recordset '// Recordset to hold the class.Getall call Dim inxCode As Integer '// Index / offset for recordset id (code) field Dim i As Integer '// Counter for the array Dim strItem As String '// String we add to combo box Dim J As Integer '// Used for iterating columns of the recordset '// Assume function fails LoadData = False i = 0 Select Case ClassName Case ValidClassNames.cnProducts Set Obj = New Products inxCode = ProductFields.fldProductID Obj.FilterStr = mFilter Case Else Err.Raise Number:=10000, description:="Programming error. Unknown class type." Exit Function End Select cmbCodes.Clear Obj.QueryType = m_queryType Set rs = Obj.GetAll If blnDataReturned(rs) Then If IncludeBlank Then [B][COLOR="Red"]ReDim mClassCodes(0)[/COLOR][/B] cmbCodes.AddItem BLANK mClassCodes(i) = CStr(BLANK_ID) i = i + 1 End If mDontFireClickEvent = True Do Until rs.EOF strItem = "" strItem = rs.Fields(1).Value cmbCodes.AddItem strItem ReDim Preserve mClassCodes(i) codeString = IIf(IsNull(rs.Fields(inxCode).Value), NULL_STRING, rs.Fields(inxCode).Value) codeString = codeString & ";" & m_queryType mClassCodes(i) = codeString i = i + 1 rs.MoveNext Loop If cmbCodes.ListCount > 0 Then cmbCodes.ListIndex = 0 End If mDontFireClickEvent = False Call CloseRecordset(rs) 'Set rs = Nothing '// Now, if we have a design time default, set it! If DefaultCode <> NO_DEFAULT Then Id = DefaultCode End If '// All's well - return True LoadData = True LoadData_Done: Exit Function LoadData_Error: Call Process_Error(MODULE_NAME, "LoadData") Resume LoadData_Done End Function
Hi,
ReDim statement is used to change the size of a dynamic array in procedure level.
Preserve keyword is used to preserve the data in an existing array when you change the size.
Ex
In your code if IncludeBlank flag is set, you are change the size of mClassCodes array to 1 ( 0 to 0).
For the other data of Class Codes, you are changing the size one by one with preserving the existing values.
ReDim statement is used to change the size of a dynamic array in procedure level.
Preserve keyword is used to preserve the data in an existing array when you change the size.
Ex
VB Syntax (Toggle Plain Text)
' ' Declare Dynamic Array ' Dim AnArray() As Integer ' ' Now allocate the size ' ReDim AnArray(2) As Integer ' 'Now An Array has bound 0 to 2 ' AnArray(0) = 100 AnArray(1) = 300 AnArray(2) = 400 ' ' Change the size ' ReDim AnArray(10) As Integer ' ' Now AnArray size is changed but all the values in that array are lost ' ' To preserve the existing values use Preserve keyword ' ' Change the previous code as ReDim Preserve AnArray(10) As Integer
In your code if IncludeBlank flag is set, you are change the size of mClassCodes array to 1 ( 0 to 0).
For the other data of Class Codes, you are changing the size one by one with preserving the existing values.
Last edited by selvaganapathy; Jul 30th, 2009 at 10:34 am.
KSG
•
•
Join Date: Dec 2008
Posts: 292
Reputation:
Solved Threads: 1
'
Still doubt kindly explain this also.
Still doubt kindly explain this also.
If blnDataReturned(rs) Then If IncludeBlank Then ReDim mClassCodes(0) cmbCodes.AddItem BLANK mClassCodes(i) = CStr(BLANK_ID) i = i + 1 End If![]() |
Similar Threads
- Help with my program! (VB.NET)
- ReDim error! (Visual Basic 4 / 5 / 6)
- Declaring multidimensional array in VBA (Visual Basic 4 / 5 / 6)
- How to Make Encrytion on Database? using VB (Visual Basic 4 / 5 / 6)
- Copy info from one form to another VB 6 (Visual Basic 4 / 5 / 6)
- Outputting "Yes" (Java)
- dynamic 2 dimensional array in vb 6 (Visual Basic 4 / 5 / 6)
- About Comm Port (Visual Basic 4 / 5 / 6)
- Help with simple Array program (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how toconvert vb file into exe
- Next Thread: Enter Key use in my Project
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





