|
-
May 31st, 2007, 04:15 AM
#1
Thread Starter
Addicted Member
How to use ReDim in vb.net+ Sourabh Das
Hi,
This code is in vb6. How do I use the redim keyword in vb.net.
Code:
Public Sub FillVendor()
On Error GoTo err
I = 0
Set rs = New ADODB.Recordset
rs.Open "select * from tbl_vendor where isdeleted=0", cn, 1, 1
ReDim arrVendorId(rs.RecordCount)
While Not rs.EOF = True
cmbVendor.AddItem rs("Vendor_name")
arrVendorId(I) = rs("Vendor_Id")
I = I + 1
rs.MoveNext
Wend
Exit Sub
err:
MsgBox err.Number & "- " & err.Description, vbInformation, err.Source
Call I_Process_Errors("frmItem:FillVendor", err.Number, err.Description, err.Source)
End Sub
Regards,
-
May 31st, 2007, 04:17 AM
#2
Re: How to use ReDim in vb.net+ Sourabh Das
ReDim does in VB.NET exactly what it did in VB6. If you want to know how to use any key word, statement, property or method then just look it up in the MSDN library.
http://search.msdn.microsoft.com/sea...=00&lang=en-us
-
May 31st, 2007, 04:23 AM
#3
Fanatic Member
Re: How to use ReDim in vb.net+ Sourabh Das
vb Code:
dim string() as string
dim counter = 6
redim string(counter)
for i as integer = 0 to 6
string(i) = "whatever"
next i
-
May 31st, 2007, 04:30 AM
#4
Frenzied Member
Re: How to use ReDim in vb.net+ Sourabh Das
Note that ReDim will reset any existing elements of the array to the default values. If you wish to keep the existing values then use the Preserve keyword.
eg. ReDim Preserve sArray(20)
-
May 31st, 2007, 04:36 AM
#5
Thread Starter
Addicted Member
Re: How to use ReDim in vb.net+ Sourabh Das
Hi,
I am unable to understand it.
Please help me giving a small piece of code.
Its urgent.
Regards,
-
May 31st, 2007, 05:37 AM
#6
Thread Starter
Addicted Member
Re: How to use ReDim in vb.net+ Sourabh Das
Hi TalkRo,
Why did you take counter as 6.
actually this count should be the number of rows present in the table if i am not wrong..
so instead of that should i write the count of records and if yes then
what will be the change in the for loop.
-
May 31st, 2007, 05:37 AM
#7
Frenzied Member
Re: How to use ReDim in vb.net+ Sourabh Das
Code:
'declare and allocate 2 elements to a string array
Dim sArray(1) As String
'assign values to the 2 elements
sArray(0) = "yes"
sArray(1) = "no"
'redimension the array allocating a third element
ReDim Preserve sArray(2)
'assign a value to the third elements
sArray(2) = "hello"
If you weren't to use the Preserve keyword above, the values "yes" and "no" would be lost and replaced with Nothing.
-
May 31st, 2007, 05:52 AM
#8
Fanatic Member
Re: How to use ReDim in vb.net+ Sourabh Das
vb Code:
dim i as integer = 0
dim str() as string
dim counter as integer = ds.tables("yourTableName").Rows.count
redim str(counter)
for each row as datarow in ds.tables("yourTableName").Rows
string(i) = row("ID").toString()
i += 1
next row
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|