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!

Data Type Mismatch

Status
Not open for further replies.

ninjaman01

Programmer
Aug 11, 2021
14
PH
Hi Guys Please help!

whenever I try to run my program I always get a "Data Type Mismatch Error" when im adding records to my table.
this is my code:

if thisform.cmdAdd.caption = "ADD"
thisform.txtBrcode.enabled = .T.
thisform.txtDistrict.enabled = .T.
thisform.txtSeqcu.enabled = .T.
thisform.cmdAdd.caption = "SAVE"
thisform.cmdClose.caption = "CANCEL"
thisform.txtBrcode.value = " "
thisform.txtDistrict.value = " "
thisform.txtSeqcu.value = " "
thisform.cmdEdit.enabled = .f.
thisform.cmdDel.enabled = .f.
thisform.cmdSend.enabled = .f.
thisform.Grid1.enabled = .f.
else
if empty(thisform.txtBrcode.value)
m = messagebox("Please provide the branch number.",64,+"Validation")
if empty(thisform.txtDistrict.value)
m = messagebox("Please provide the district.",64,+"Validation")
if empty(thisform.txtSeqcu.value)
m = messagebox("Please provide the seqcus.",64,+"Validation")
return
endif
endif
endif
select brdist
append blank
if .not. found()
replace Bcode with thisform.txtBrcode.value, Branch with allt(thisform.txtDistrict.value), Seqcus with allt(thisform.txtSeqcu.value)
m = messagebox(allt(thisform.txtBrcode.value)+allt(thisform.txtDistrict.value)+allt(thisform.txtSeqcu.value)+" has been added.",64,"System Validation")
else
m = messagebox(allt(thisform.txtBrcode.value)+allt(thisform.txtDistrict.value)+allt(thisform.txtSeqcu.value)+"already exist.",64,"System Validation")
endif
thisform.txtBrcode.enabled = .F.
thisform.txtDistrict.enabled = .F.
thisform.txtSeqcu.enabled = .F.
thisform.cmdAdd.caption = "ADD"
thisform.cmdClose.caption = "CLOSE"
thisform.cmdEdit.enabled = .T.
thisform.cmdDel.enabled = .T.
thisform.cmdSend.enabled = .T.
thisform.Grid1.enabled = .T.
endif
thisform.refresh
 
It would help us to know which line of your code causes the error.

Run the code in the development environment. When the error message appears, click Suspend. You should then see the offending line highlighted. If you can't see the code at that point, open the Debugger (from the Tools menu) and view the Trace window.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
One other thing that I see is, you always append blank, before even checking whether a matching record already exists.

Your [tt]if not found()[/tt] will always be .t., as FOUND() is .f. because FOUND() just checks if you're not at then end of the dbf file, and after an APPEND BLANK you are not at the end of the file, you're on the last record, but the end is past that record, the file ends on a single byte (EOF marker) after the last record.

The error points out that the datatype of one of the input values doesn't match the datatype of one of the fields you REPLACE. If, for sake of giving an example, the Bcode field is numeric, but the txtBcode.value is string, the replace fails for that data type mismatch. There is no implicit conversion of string to number in REPLACE, even if the string only consists of an EAN13 barcode, ie only has digits. VFP is not strictly typed in general, but regarding tables it is, with few exceptions, but that leads too far off.

A textbox itself does only take on a specific data type when its value property is preset to it. So if you would set txtBcode to 0 in the form designer or in the init code of the form, then scanning a barcode would read in the digits into the field and though leading zeros will disappear it will keep the datatype numeric. You just face the problem a barcode reader might send other characters than digits, often enough ASCII control codes like ESC or CR or LF before or after the barcode digits.

Not knowing your table structure it's impossible to tell which field has the data type mismatch, but very likely all the textboxes just have strings in them and could only be replaced into char fields (and varchar, memo,...).

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top