CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    17

    converting into array:

    the connection between the access database and the vb is successfully done , now i want to convert the field set into 2d array or matrix. following is the code i'm using for the conversion.
    Code:
    Dim x as long,y as long,xupper as long, yupper as long
    Dim temparray as Variant
    recarray =  objRs.GetRows
    xupper=UBound(recarray,2)
    yupper=UBound(recarray,1)
    ReDim temparray(xupper + 10, yupper + 10)
    for x = 1 to xupper
            for y = 1 to yupper
                temparray(x,y)=recarray(x,y)
             next
    next
    
    Convert = temparray
    there is no error in the code. but this is not reading the first row...

    please tell me what could be possible problem with this code....
    Last edited by WizBang; May 7th, 2009 at 07:56 AM. Reason: Added [code] tags

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: converting into array:

    Please use code tags [ code ] and [ /code ] to enclose your code block. It makes it more readable.

    What do you mean? The first row is not read from your database?
    Maybe it's just an indexing problem. You go for x=1 to xupper but you should start at 0
    Your sample skips the elements recarray(0,..) and recarray (..,0)
    for x=0 to xupper-1 should improve matters.

    By default arrays start with element 0 if you
    Dim Arr(2)
    you have three elements Arr(0), Arr(1), Arr(2) UBound(Arr) will return 2. Check LBound of the arrays like
    For i= LBound(recarray,2) to UBound(recarray, 2)...
    Last edited by WoF; May 4th, 2009 at 07:41 AM.

  3. #3
    Join Date
    Apr 2009
    Posts
    17

    Re: converting into array:

    basically i have similarity matrix i,e in the diagonal there are 0 values.

    e.g 0 1 2 3
    1 0 2 3
    2 2 0 3
    3 3 3 0
    this database i have imported in access database and want to do some basic calculation for that i need to change it in matrix which will make my work easy.
    i want to retrieve these values in temparray(i,j) form

    i have tried all the changes that u have suggested. but it is not giving me the values that i expect to be in that position.



    Dim x As Long, y As Long, xupper As Long, yupper As Long
    Dim temparray As Variant
    recarray = objRs.GetRows
    xupper = UBound(recarray, 2)
    yupper = UBound(recarray, 2)
    MsgBox xupper
    'output maximum value

    MsgBox yupper
    'output maximum value

    ReDim temparray(xupper + 10, yupper + 10)
    nn = LBound(recarray, 2)
    MsgBox nn
    'output 0

    For x = nn To xupper
    For y = nn To yupper
    temparray(x, y) = recarray(y, x)
    Next
    Next

    Convert = temparray

    MsgBox temparray(1, 1)

    but when i try to print one value it is not giving me the apt result/......
    please suggest

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: converting into array:

    First I suggest you are using [ code ] [ /code ] tags to enclose your code for better readability.

    Next you examine your code regarding the dimensions of the array.
    nn=LBound(recarray,2)
    thats okay.
    but to determine the proper y value you need something like
    mm=LBound(recarray,1)
    so you can go
    Code:
    For x=nn to xupper
      For y=mm to yupper

  5. #5
    Join Date
    Apr 2009
    Posts
    17

    Re: converting into array:

    thank you so much your suggestion really helped me out..
    thank you....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured