This topic is locked

Function to exclude characters

6/30/2010 12:05:11 PM
ASPRunnerPro General questions
M
mfred author

I have an application where we scan and save package tracking barcodes. DHL, UPS and USPS all scan fine. But the FedEx barcode enters too many characters. If a tracking number is 793656940953, then the scanned barcode results in 37704674520000017936569409532015. So I need to add an event for checking if an entry into the "TrackingNo" field has 32 characters. It it does, then the first 16 and last 4 characters need to be removed. An additional factor is that I already have the even below for ensuring no duplicate entries occur. So I am having a tough time combining a function for the new need and keeping this. Any help in adding the new feature to the code below would be appreciated.
' Before record added

Function BeforeAdd(ByRef values,ByRef message,inline)
Dim dict

Set dict = values
'** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("MailQuery1")

set rsExists = dal_table.Query("TrackingNo='" & values("TrackingNo") & "'","")

if not rsExists.eof then

BeforeAdd=false

message = "This tracking number has already been entered."
else

BeforeAdd = true
end if

rsExists.Close : set rsExists = Nothing
End Function ' BeforeAdd

arrEventTables("BeforeAdd")="MailQuery1se"

arrAvailableEvents("BeforeAdd")=true

A
ann 7/1/2010

Hi,
you need to execute 'Check if specific record exists' code again to check second condition.

Just create a flag variable to verify conditions (instead of returning value for the function BeforeAdd).

Set up at the end:

if flag=1 then

BeforeAdd = true

else

BeforeAdd = false

end if
M
mfred author 7/1/2010

You lost me. I've not dealt with flag variables so I am unsure what to compose or where to insert it. Also, you code indicated BeforeAdd = false but I want the system to add the record if 32 characters exist but I want the erroneous characters removed.
Below is code that someone supplied from another forum. It looks correct but I can't get it to function.
Function FormatTrackingNumber(TrackingNo)

chars = Len(TrackingNo)
If chars = 32 Then TrackingNo = Mid(TrackingNo,17,12)
FormatTrackingNumber = TrackingNo

End Function

A
ann 7/2/2010

Hi,
publish your project on Demo Account and open a ticket at http://support.xlinesoft.com. 'Demo Account' button can be found on the last screen in the program.