| | |
2-dimentinal dynamic array
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
•
•
can I use array list as 2- dimensinal ??
VB.NET Syntax (Toggle Plain Text)
Dim MyList As New ArrayList() Dim Arr1() As Integer = {1, 2, 3} Dim Arr2() As Integer = {4, 5, 6} MyList.Add(Arr1) MyList.Add(Arr2) MsgBox(CType(MyList.Item(1), Integer())(2)) ' -> Second item (array) and third item in the array, output: 6
HTH
Teme64 @ Windows Developer Blog
•
•
•
•
Originally Posted by Nada_ward
can I use 2-dimensinal array and resize it when I need ??
•
•
•
•
Originally Posted by adatapost
Use redim statement.
For example
VB.NET Syntax (Toggle Plain Text)
Dim Matrix(,) As Integer ReDim Preserve Matrix(0, 0) Matrix(0, 0) = 1 ' Matrix: (0,0) = 1 ReDim Preserve Matrix(0, 1) Matrix(0, 1) = 2 ' Matrix: (0,0) = 1 and (0,1) = 2 ReDim Preserve Matrix(1, 1) ' <- This raises error: "'ReDim' can only change the rightmost dimension" Matrix(1, 1) = 3 ' Code never reaches here
Teme64 @ Windows Developer Blog
•
•
•
•
I don't know how many input will request user
ReDim Preserve to resize array/matrix and to preserve previously entered data.•
•
•
•
the rightmost dimention will be fixed
Here's another example
VB.NET Syntax (Toggle Plain Text)
Const FIRST_DIM As Integer = 9 ' First dimension gets fixed to ten elements Dim Matrix(,) As Integer Dim Counter As Integer ' Counter for the second dimension of the matrix Counter = 0 ' Reset counter ' A loop to process user input Do Until <some condition> ' Resize second dimension ReDim Preserve Matrix(FIRST_DIM, Counter) ' ReDim Preserve preserves previous data in the matrix ' Process/add user data here Counter += 1 ' Increase counter! Loop

HTH
Teme64 @ Windows Developer Blog
•
•
Join Date: Jul 2009
Posts: 47
Reputation:
Solved Threads: 0
Ok
I though on that
but when I do it , the text of label is not appearing completly
I didn't change any thing except replacing the place of dimension for array ..??
see the code ..
I though on that
but when I do it , the text of label is not appearing completly
I didn't change any thing except replacing the place of dimension for array ..??
see the code ..
vb .net Syntax (Toggle Plain Text)
Public Class Form1 Dim counter As Integer=3 'suppose counter=number of columns in 2-dimention Dim g As Graphics Dim d As Integer Dim s As SizeF Dim l1 As Label Dim array1() = {"c1", "c2", "c3"} Dim frag_des(,) As String = {{"c1", "c2", "c3"}, {"ddddddddddd ", "ffffffffff ", "ggggggggggggggg"}} Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For j As Integer = 0 To array1.Length - 1 d = 0 l1 = New Label() While Not (array1(j) = frag_des(0, d)) And d < counter 'frag_des.GetUpperBound(0) d += 1 End While If Not (array1(j) = frag_des(0, d)) Then g = l1.CreateGraphics s = g.MeasureString(array1(j), l1.Font) l1.Height = s.Height l1.Width = s.Width l1.Text = array1(j) Else g = l1.CreateGraphics s = g.MeasureString(array1(j) & ": " & frag_des(1, d), l1.Font) l1.Height = s.Height l1.Width = s.Width l1.Text = array1(j) & ": " & frag_des(1, d) MsgBox(array1(j) & ": " & frag_des(1, d)) End If l1.Location = New Point(5, (j * 25) + 3) Me.Controls.Add(l1) Next End Sub End Class
Last edited by Nada_ward; Aug 3rd, 2009 at 8:51 am.
•
•
•
•
the text of label is not appearing completly
I slightly modified the code
VB.NET Syntax (Toggle Plain Text)
Else g = l1.CreateGraphics s = g.MeasureString(array1(j) & ": " & frag_des(1, d), l1.Font) g = Nothing l1.Height = CInt(s.Height) l1.Width = CInt(s.Width) + 5 l1.Text = array1(j) & ": " & frag_des(1, d) 'MsgBox(array1(j) & ": " & frag_des(1, d)) End If
Teme64 @ Windows Developer Blog
![]() |
Similar Threads
- get length of a dynamic array (C++)
- Sorting 2D Dynamic array of integers , Snake Style (C)
- works for static need help to make it dynamic (C++)
- dynamic array of structures problem (C++)
Other Threads in the VB.NET Forum
- Previous Thread: DateTime stamp or Code?
- Next Thread: the text of dynamic label is not complete
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






