Results 1 to 5 of 5

Thread: Retrieving values from an array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    101

    Retrieving values from an array

    I know this must be simple but I can't work it out. I have stored a range of data in an array, with variables according to the following construction, stored in a datagridtable:

    Code:
    datarowview("Store") = (DateProcessed, Outcome1, Benefit, Location, transaction)  'these are the items into which data are added
    I then need to retrieve the value of the elements.
    Code:
    Dim TransSDD As String 'The final destination for the retrieved data
            For Each Datarowview In MyGrid.View 'locates the correct record
                If PtCode = Datarowview("PtCode") Then 'locates the correct record
                    TransSDD = Datarowview("Store")  'locates the correct column and therefore the cell in which the array sits
                 End If
            Next
    This construct returns correct values for the single element in the datarowview, with the returned data having, for example, this construct:

    Code:
    (14052022, Pass, $40.00, Rome, A001)
    But I want to retrieve individual element values, eg just the 'location' or 'location and transaction number'. If I try to specify the element, eg with:

    Code:
     Dim DateProcessed As String
                    Dim TransS As String
                    TransS = TransSDD(DateProcessed)
    then I only get a single bracket "(" returned.

    Can anyone help?
    Last edited by Bear89; May 18th, 2022 at 08:44 AM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,963

    Re: Retrieving values from an array

    Tell me if I understand your issue properly.

    You are storing an array in a single cell of a DataGridView, but when you get the cell back from the DataGridView it is not being returned as an array?
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    101

    Re: Retrieving values from an array

    Well I was wondering if thats the case, because I had thought my syntax was OK, but may just be a string?

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,805

    Re: Retrieving values from an array

    You've returned the value into a string...
    Code:
    Dim TransSDD As String
    ...
    TransSDD = Datarowview("Store")
    DateProcessed isn't an index, presumably it is a variable (it's what you used to write the "array" in the first place.
    But TransDD is a string anyways, so this: TransS = TransSDD(DateProcessed) isn't accessing an artray. It's accessing a substring of TransDD ... My guess is that you think you're storing an array, but what you have is in fact a string. If that's the case, then you'll want to drop the parenthesis and then split on the comma.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    101

    Re: Retrieving values from an array

    Perfect, thanks tg and dday!

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