Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!-Parsing Character Separated String

Status
Not open for further replies.

ConfusedNAccess

Technical User
Jul 7, 2006
54
CA
Bear with me- I'm a novice when it comes to this subject, I've never been "formally educated" in Access or VBA. I'm learning as I go. So my description may be muddy.

I've got access tables linked to an ODBC database -a program that performs analysis- data is entered for multiple variables in an excel spreadsheet inside the program. Values are entered for multiple variables. These variables have underlying formulas and are automatically calculated in the excel spreadsheet.

These calcualted values are separated by months 1-12 on the spreadsheet (columns). This data is present in a a character separated string inside the ODBC Database in a table. There are 2 tables present- 1)Datatable- shows all the data and a corresponding table- which has fields for defining the layout of the text string in the data table.


ex.DefinitionTable
column1-LayoutVersion---10,11,12
column2-LayoutDefinition---
("10") Title|StandardText

("11")Active|InDefault|GracePeriod|DateDue|DateReceived|Received|SignoffNote

("12")Active|InDefault|RequiredValue|ActualValue|SignoffNote
DataTable
column1-LayoutVersion---10,11,12
column2-Data-- ex.(layoutversion12)(N|N|||~Y|Y|4.0000|14.7083|~N|N|||~N|N|||~N|N|||~N|N|||~N|N|||~Y|N|0.0000|0.0000|~N|N|||~N|N|||~N|N|||~N|N|||~N|N|||
My question--

How do I parse (I guess this is the correct term)this data into fields for reporting? I am somewhat a novice
From what I can tell, the delimiter "~" separates the month from the next.

I'm really not sure of the best route- To be honest I don't know of any route. Again, I have no education on this matter.

I need to separate the character separated string into multiple columns based on the definiton of the value and then separated by month. In text string above, please note there are 13 months of data. THere are columns present in that table as well noting the number of reporting months as well as the last month to count back from.

This is the only indication that I can tell of how to define which month the data belongs to.

I need someone with knowledge of this, and PATIENCE to walk me through this. Thanks for reading.
 
Hi ConfusedNAccess,
The above data sample appears to be:
5 elements separated by VerticalBar(|)
13 sets of elements separated by Tilda(~)
with column headers that correspond to that defined by ("12")
(As far as the other column headers I don't see how they apply to the data.)
For instance:
Active InDefault RequiredValue ActualValue SignOffNote
N | N | | | ~ (Next Record)
Y | Y | 4.0000 | 14.7083 | ~ (Next Record)
... etc...
 
if blank then there isn't one present. the info you have above is correct. sign off note is null.
 
What I need to tell is the difference between the Required and actual value.
 
ConfusedNAccess,
Here is a simple routine that will demonstrate how to parse the data and do your calculation and outputs to the Immediate window in the Visual Basic explorer.
It uses an array structure to break the string into usable chunks much like lamarw detailed. Once this is done I just pulled the two numbers out to do the calculation.
Code:
Sub ParseRec(ODBC_Data As String)
Dim dblRequiredValue As Double, dblActualValue As Double
Dim intRecord As Integer
Dim arrRecords() As String, arrFields() As String
'break the line up based on the tilde character
arrRecords = Split(ODBC_Data, "~")
Debug.Print "Number of Months: " & UBound(arrRecords) + 1
For intRecord = 0 To UBound(arrRecords)
  'now break the line based on bar characters
  arrFields = Split(arrRecords(intRecord), "|")
  Debug.Print "Month: " & intRecord + 1, Join(arrFields, " ")
  'all the fields are string so change them to numbers
  'note in Access you can do this with Nz()
  If arrFields(2) = "" Then
    dblRequiredValue = 0
  Else
    dblRequiredValue = CDbl(arrFields(2))
  End If
  If arrFields(3) = "" Then
    dblActualValue = 0
  Else
    dblActualValue = CDbl(arrFields(3))
  End If
  'do the math
  Debug.Print "difference between Required and Actual:", dblRequiredValue - dblActualValue
Next intRecord
End Sub
And here was my output:
[tt]call ParseRec("N|N|||~Y|Y|4.0000|14.7083|~N|N|||~N|N|||~N|N|||~N|N|||~N|N|||~...)
Number of Months: 13
Month: 1 N N
difference between Required and actual: 0
Month: 2 Y Y 4.0000 14.7083
difference between Required and actual: -10.7083
...[/tt]
Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
I was so excited to get your response! Thank you! This is WONDERFUL!!!! I inserted your code into a new module is there a secret to making this work? Again, I'm a novice when it comes this stuff! I guess my question is, how do I "call" this code to my query? I guess that is the correct term.



 
ConfusedNAccess,

Direct answer, in the QBE pane add a calculated field:
[tt]My_Calculated_Field: ParseRec([Your_ODBC_Field_Name])[/tt]

I'm not sure you can call it directly in your query.

From the data you posted you could potentially have 13 results for each record. If you want a distinct record for each result you would need to house the results for each month in a temporary location (you could use a table or working file [*.csv, *.txt]). If you are looking for the sum of all thirteen months in one field in the query the routine could be easily be changed to keep track of all the calculations and return the total.

What route are you trying to go?

CMP
 
OK, I just realized that the table field that has the string data in it, is a memo type field. Does that have anything to do with how i'm going to parse the data?

I'm frustrated with this because i know that it is possilbe to do what i'm trying to accomplish. I know there is a way.

the field name is monthlyresults. now.. after some reading yesterday, I read something (not exactly a "how to article") but something regarding pulling stored procedures from the ODBC. If this is possible.. how would I go about it? I know there is a procedure of some sorts in there telling how to manipulate the MonthlyResults. I'm I also located all of the programming files for the odbc. I belive i've isolated a .frm file which lists the procedures.. which i think is used in SQL Server. so basically.. how can i use this in my access database to replicate a particular report? The reason for all of this.. i need to modify how the report is made. So if I can extract or parse out in a query- the data in the Monthyresults field and use the query as a "make table" query, i can then query again to set my own criteria.

please someone with a good heart and a lot of patience help! I appreciate all who took the time to read this. I understand that time is valuable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top