Solved

PREVENTING BREAKOFF STRINGS WITH CHR(0) IN  RECORDS-SETS

Posted on 2004-08-24
9
237 Views
Last Modified: 2010-04-17
I have a ADO.recordset open on een database (pervasive)
I read record to this set.
one field is fixed to 8 bytes
we use this to put in MKD-style
if the string does not contain any chr$(0) value all is ok,
but the moment it contains 1 or more chr$(0) the string during
update or reading will be cut off at postion chr$(0)
Using random file with fielded  string 8 bytes goes ok
0
Comment
Question by:BIAPRO
  • 5
  • 3
9 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11884031
You must use a binary field
0
 

Author Comment

by:BIAPRO
ID: 11884074
Do you mean that in my recordset DNS resources i must define the field not as char?
I'am not sure if a understand you, sorry .

Jack
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11884131
I don't know your database details but if you want to store a chr$(0) in a database you must do it in a binary field. The NULL character has a special meaning in some systems. It is used to signal end-of-string, so, don't store it in a string field but in a binary field.
0
 

Author Comment

by:BIAPRO
ID: 11884211
Ok, the VBdatabase is pervasive,  the Dosdatabase is Btrieve , or just
plain 'old'  likewise  Field #1, 8 as Money$, 30 as text$
then:  LSET Money$ = MKD$(amount#) :  
I  can read these files in VB ok,  and convert back  as Money#=CVD(rs.name)
but  msoft MKD double prec. will contain sometimes in the 8 byte a '0' byte
If i do reading in VB with old-plain fielding all ok,
as soon as it is redirected to ADO.recordset, at chr(0) point in a string it
will break off. so sometimes  7 bytes, then 5 bytes or if at leading pos.  zero bytes
returned. in all other case CVD(rsrecord) is ok
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11884275
I am not sure if you are refering actually to CHR$(0), the null character, or CHR$(48), the zero digit character.
If the first, maybe you can replace the CHR$(0) with a space or a zero character.
0
 

Author Comment

by:BIAPRO
ID: 11884352
chr$(zero),  you can't replace, i did a test run on a loop from -99999999 to +999999999
the full asci set is used in combination with all these amounts
0
 
LVL 3

Accepted Solution

by:
IceColdas earned 500 total points
ID: 11902294
well, you know, a string is terminated by a null character ( a  zero  byte), that`s why it breaks.
So you probably need to read the field from the database as an array of chars, not as a string.
Then create a string from that array, eliminating the zeros.

this is a c# version of how you should read a row from the database:

int fieldSize = 8;  //the size of the field
char [] charArray = new char(fieldSize);  //variable to store the field value
....
//read a row in charArray from the database
....
string s = null;
for ( int i = 0; i< fieldSize; i++)
    if (charArray[i] != 0)
           s += charArray[i];

s += "\0"; //to end the string;
0
 

Author Comment

by:BIAPRO
ID: 11903703
when i use the commands
cn.MoveNext
dummy$= cn.Fields(21)  ' (fields(21) contains a binary value  8 bytes
the string will contain  chr(0) postitions, but is not terminated and has 8 bytes
the I can use the CVD(dummy$)  function to get the money value , double preciscion
Only when I retrieve a record form ADOset is terminated.

0
 

Author Comment

by:BIAPRO
ID: 11930578
it is solved in a mayby dum way,
I do this but not really smart I think suggested solutions sofar in this question block
did not work

Private Sub brokergrid_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
brNum = brokergrid.Text
If rsBrokers.BOF = False And rsBrokers.EOF = False Then
   If brokergrid.Text > LastKey Then
     While rsBrokers.Fields(0) < brokergrid.Text
      If rsBrokers.EOF Then Exit Sub
          rsBrokers.MoveNext
     Wend
           Else
        If rsBrokers.BOF Then Exit Sub
     While rsBrokers.Fields(0) > brokergrid.Text
     rsBrokers.MovePrevious
    Wend
 End If
sftBeginSaldo.Text = STR(CVD(rsBrokers.Fields(21)))
End If











0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adobe Customization Wizard XI issues 26 169
scores100 challenge 3 84
mergeTwo  challenge 13 72
noX challenge 17 77
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now