I’m trying to create a simple product information using livecode. I’m using a database (sqlite) I have 1 table (Product) see below. I want to set my product code into this format “P00000” and every time I will add a product it will increment by 1. The problem I encountered it only increment the last char. How do you do in livecode to increment every digit until it reaches the P99999 and will add another digit. Do I have to check the previous product code before it will increment? This is new to me coz I usually used ID and set it autoincrement from the database. Hope you guide me. Thanks in advance.
here is my codes below
Code: Select all
on mouseUp
DBOpen
CollectAllData
end mouseUp
############################
command CollectAllData
local tProdID, tProdName
put "P" & 00000 into fld "ProdCode"
add 1 to char 6 of fld "ProdCode"
put fld "ProdCode" into tProdID
put fld "ProdName" into tProdName
if tProdID is not empty then
SaveProdInfo tProdID, tProdName
end if
end CollectAllData
############################
command SaveProdInfo pProdID, pProdName
local lSQLStatement
global gDatabaseID
put "INSERT into Product(ProdCode,ProdName)VALUES(" & quote & pProdID & quote & comma & quote & pProdName & quote &")" into lSQLStatement
revExecuteSQL gDatabaseID, lSQLStatement
if the result is an integer then
beep
Answer Info "Hi, information successfully added."
lock screen
DisplayAllProductInfo
DBClose
unlock screen
else
DBClose
Beep
Answer Error "Sorry, there was a problem in adding the information."
end if
end SaveProdInfo