Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello.

I want to access a 2D array with only one Index.

This approach is made possible in "C++", I do not know how to in "VB"..

Thank you..


In C++>
C++
char cTestArr[2][10];
strncpy(cTestArr[0],"123456789\0",10);      // Data -> char array ( PASS! )
CString strTest(cTestArr[0]);				// char array -> CString ( PASS! )


In VB>
VB
Dim strTemp As String
Dim cTestArr(2, 10) As Char ' Must not be a String Type

cTestArr(0) = "123456789"   ' Data -> char array  ( FAIL!!! )
strTemp = cTestArr(0)       ' char array -> String ( FAIL!!! )
Posted
Updated 22-Dec-15 17:17pm
v3
Comments
Sergey Alexandrovich Kryukov 23-Dec-15 1:18am    
Why?
—SA

1 solution

You don't. You have to use two indexes. In C, you can get away with it, but VB is a lot more strict.

The solution if you want to use one index is to make it a one dimensional array. You'll have to do some additional mathematical coding to access the array using two indexes and generate a single index value to get the correct item from the array.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Dec-15 1:18am    
5ed.
—SA
Member 11153736 23-Dec-15 1:19am    
Despite the basics questions, thank you for the answers.
I sincerely hope you have a good day!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900