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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving Info

Status
Not open for further replies.

LFC8

Programmer
Nov 18, 2004
45
0
0
GB
Hi

I'm having problems getting this particular piece of information from our database, basically i'm getting my info through a piece function which is numeric but this item is pieced BARC

strPostcode = Split(sDataString, "*")(21)

strBarcode is BARC in the database, could someone point me in the right direction on how to get this value?

Thanks
 
What you have will return the 22nd item in a string because Split returns a zero-based array, formatted like
Code:
abc*xyz*123* ... uvw*012345*xxx ...
 0   1   2   ...  20   21    22 ...
Databases usually don't store and return information in delimited strings like that unless you are using the ADO GetString method.

How are you retrieving the information from your database? The code you have presented isn't code to retrieve information from a database.
 
Have you checked the data in the database?

I suspect you are getting "index out of range" error. Since you are using the 21st element, there must be at least 20 asterisks in the data.

You could prevent this error from occuring by using this...

Code:
If Len(sDataString) - Len(Replace(sDataString, "*", "")) >= 20 Then
  strPostcode = Split(sDataString, "*")(21)
End If

Basically, the IF is comparing the length of the string to a 'version' of the string with asterisk replaced with nothing. If there are not enough asterisks, then the split function does not occur.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
There are 46 items in the database i'm fine getting those 46 but on the 47th line is the barcode value which is piece "BARC" and isnt displayed as 47 (why i dont know). This is how I'm getting them..

Code:
Public Property Let DataString(sData As String)
    Dim i As Integer
  
    sDataString = sData
    strDocRef = Split(sDataString, "*")(1)
    strPages = Split(sDataString, "*")(2)
    strActDate = Split(sDataString, "*")(3)
    strOurRef = Split(sDataString, "*")(4)
    strYourRef = Split(sDataString, "*")(5)
    strFAO = Split(sDataString, "*")(13)
    strCleanmail = Split(sDataString, "*")(14)
    strProceedings = Split(sDataString, "*")(46)
    strPostcode = Split(sDataString, "*")(21)
    strBarcode <<<<<<< PROBLEM IS HERE
    
    For i = 0 To 6
        strAdd(i) = Split(sDataString, "*")(i + 6)
    Next i
    
    For i = 0 To 5
        strDetails(i) = Split(sDataString, "*")(i + 15)
    Next i
    
    For i = 0 To 23
        strDate(i) = Split(sDataString, "*")(i + 22)
    Next i
    
End Property

And here is the structure of the database

Code:
^PDFDOC(1,"060919",1268)=ACEN
^PDFDOC(1,"060919",1268,1)=1268
^PDFDOC(1,"060919",1268,2)=TEST
^PDFDOC(1,"060919",1268,3)=19/09/2006
^PDFDOC(1,"060919",1268,4)=TEST
^PDFDOC(1,"060919",1268,5)=
^PDFDOC(1,"060919",1268,6)=TEST
^PDFDOC(1,"060919",1268,7)=
^PDFDOC(1,"060919",1268,8)=TEST
^PDFDOC(1,"060919",1268,9)=TEST
^PDFDOC(1,"060919",1268,10)=TEST
^PDFDOC(1,"060919",1268,11)=TEST
^PDFDOC(1,"060919",1268,12)=BR9 923
^PDFDOC(1,"060919",1268,13)=JOE BLOGGS
^PDFDOC(1,"060919",1268,14)=TEST
^PDFDOC(1,"060919",1268,15)=TEST
^PDFDOC(1,"060919",1268,16)=
^PDFDOC(1,"060919",1268,17)=TEST
^PDFDOC(1,"060919",1268,18)=TEST
^PDFDOC(1,"060919",1268,19)=TEST
^PDFDOC(1,"060919",1268,20)=
^PDFDOC(1,"060919",1268,21)=L46 929
^PDFDOC(1,"060919",1268,22)=Oct 2004
^PDFDOC(1,"060919",1268,23)=Nov 2004
^PDFDOC(1,"060919",1268,24)=Dec 2004
^PDFDOC(1,"060919",1268,25)=Jan 2005
^PDFDOC(1,"060919",1268,26)=Feb 2005
^PDFDOC(1,"060919",1268,27)=Mar 2005
^PDFDOC(1,"060919",1268,28)=Apr 2005
^PDFDOC(1,"060919",1268,29)=May 2005
^PDFDOC(1,"060919",1268,30)=Jun 2005
^PDFDOC(1,"060919",1268,31)=Jul 2005
^PDFDOC(1,"060919",1268,32)=Aug 2005
^PDFDOC(1,"060919",1268,33)=Sep 2005
^PDFDOC(1,"060919",1268,34)=Oct 2005
^PDFDOC(1,"060919",1268,35)=Nov 2005
^PDFDOC(1,"060919",1268,36)=Dec 2005
^PDFDOC(1,"060919",1268,37)=Jan 2006
^PDFDOC(1,"060919",1268,38)=Feb 2006
^PDFDOC(1,"060919",1268,39)=Mar 2006
^PDFDOC(1,"060919",1268,40)=Apr 2006
^PDFDOC(1,"060919",1268,41)=May 2006
^PDFDOC(1,"060919",1268,42)=Jun 2006
^PDFDOC(1,"060919",1268,43)=Jul 2006
^PDFDOC(1,"060919",1268,44)=Aug 2006
^PDFDOC(1,"060919",1268,45)=Sep 2006
^PDFDOC(1,"060919",1268,46)=20/09/2006
^PDFDOC(1,"060919",1268,"BARC")=A9999999999

Hope this clarifys things

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top