-
May 18th, 2022, 08:24 AM
#1
Thread Starter
Lively Member
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.
-
May 18th, 2022, 08:31 AM
#2
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?
-
May 18th, 2022, 08:41 AM
#3
Thread Starter
Lively Member
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?
-
May 18th, 2022, 09:18 AM
#4
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
-
May 18th, 2022, 08:41 PM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|