Originally posted by GMcCartney0607 on July 24, 2025
I have created a Keyword test that reads a CSV file for a data-driven loop. The file has string values enclosed in quotes, such as;
ID, Area, Name
“123435”,“001”,“John Doe”
When reading the file, the values are stripped of their leading zeros. My application expects the leading zero so I need it to stay. Do I have any options?
… Ok, my first hit is dealing with string conversion to integer at some point. Could you show us a code snip? I would expect that 0 in, “0John Doe” would not be removed.
P.S. I am thinking of the file read process here. Let me know?
… If you find my posts helpful drop me a like! Be sure to mark or post the solution to help others out and/or to credit the one who helped you.
TestComplete uses DDT Drivers to retrieve information from a storage. In most cases, the data is retrieved as a string. However, it can also be retrieved as an integer. Some methods perform different actions depending on whether you use integers or strings. For example, the ClickItem action performs a touch on an item using its index if you use an integer, but if you use a string, it searches for the corresponding item caption.
If you need to change the data type, use the VarToStr and VarToInt methods to make sure that you use a string or an integer value.
To use these methods in keyword tests, do the following:
Double-click the Value cell of the Keyword Test operation to open the Parameters Editor.
Click the ellipsis button.
Copy the contents of the Value field to the Clipboard.
Change the Mode option to Code Expression.
In the value column, type in either VarToStr() or VarToInt().
Paste the Clipboard contents inside the parentheses and click OK.
In scripts, use these methods to change the data type of the value you retrieve, for example, VarToStr(Driver.Value(5)).
Originally posted by GMcCartney0607 on July 28, 2025
I have a schema.ini, but it only specifies the delimiter. Are you saying that I need to specify the field type (string) and length so that TC it will not convert and drop the leading zero for the quoted strings?
Originally posted by Hassan_Ballan on July 29, 2025
Forcing the “Area” column to stay as text
TestComplete uses the OLE DB Text driver under the hood to read CSVs, and by default that driver “guesses” each column’s data type by scanning the first few rows. If it thinks a column is numeric, it will strip leading zeros. You can override that behavior in schema.ini by explicitly declaring each column as Text.
Update your schema.ini, it should look something like this:
[YourFileName.csv]
Format=CSVDelimited
ColNameHeader=True
MaxScanRows=0
; force all three columns to be treated as text
Col1=ID Text
Col2=Area Text
Col3=Name Text
Format=CSVDelimited tells the driver it’s a comma-delimited file.
ColNameHeader=True makes the first row your header.
MaxScanRows=0 forces the driver to scan all rows (not just the first 8) when inferring types.
ColN=… Text explicitly sets that column to text, preserving leading zeros.
If a response helped you out, don’t forget to Like it! And if it answered your question, mark it as the solution so others can benefit too.
The screenshot that I have provided, is the exact settings you require - the preview actually shows ID, Area and Name being read as strings, and maintaining leading zeros. Which can be seen in the output results.
Originally posted by Hassan_Ballan on July 29, 2025
There are two parts to validate: reading the CSV value as text (validated in the Data Driven Loop dialogue as rraghvani stated, if it reads it and retain the leading zeros then it is correct), and then using the text value in TestComplete (may need to specify it’s String not Variant as it would convert it automatically).
If you are using https://support.smartbear.com/testcomplete/docs/testing-with/variables/data-types/table.html the default is Variant.