of a variable from the first card the "datagrid card" to the "edit card" card. Can someone please help me

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Code: Select all
send (CurrentID && CurrentID) to card "Edit Card"
Code: Select all
global CurrentID
Code: Select all
on OpenCard -- highlight the "go to this card" button in a set
set the text of field "Field" to CurrentID
answer CurrentID
pass OpenCard
end OpenCard
Code: Select all
on OpenCard
global CurrentID
set the text of field "Field" to CurrentID
answer CurrentID
pass OpenCard
end OpenCard
Code: Select all
on OpenCard
global CurrentID
set the text of field "Field" to CurrentID
answer CurrentID
pass OpenCard
end OpenCard
Did you declare the global variable in your script that SETS this variable (the first time)?jesse wrote:Thanks! That worked great the first time. It carried over the CurrentID from my Datagrid.
But the second time it did not update the CurrentID and still showed the same ID
as the first time.
The CurrentID answer showed "U03" which is correct. But then the second time I clicked on anotherCode: Select all
on OpenCard global CurrentID set the text of field "Field" to CurrentID answer CurrentID pass OpenCard end OpenCard
entry in my Datagrid and it still showed U03 which is incorrect, it did not update the CurrentID variable
on the "Edit Card" card. Am I missing something to do this?
Code: Select all
global gConID
global realPath
global LimitBegin
global LimitEnd
local temp
global CurrentID
on preOpenStack
put empty into gConID
set itemDel to slash
put the effective filename of this stack into realpath
delete last item of realpath --removes .livecode file name
put empty into field counter
end preOpenStack
on doConnect -----------------------------------------------------
put empty into field "counter"
if gConID >0 then
answer info "Already Connected"
exit doConnect
end if
try
put realpath & "/users.sqlite" into pathNdb
//put revOpenDatabase("sqlite", pathNdb,,,,,,) into gConID
put revOpenDatabase("MySQL",clarityproductions.com,"clarityp_lb2011","clarityp_admin","j1220",useSSL) into gConID
catch theError
answer info "Problem Opening Database: " & pathNdb & " " & theError
put 0 into gConID
exit doConnect
end try
put "SQLite DB: " & pathNdb into field status-- display SQLIte flile name with path
answer information return & "Connected to: " & pathNdb & return & " ID is: " & gConID
end doConnect ----------------------------------------------------
on doDisconnect ---------------------------------------------------
put empty into counter
if not Connection() then exit doDisconnect
try
revCloseDatabase gConID
catch theError
answer warning theError
exit doDisconnect
end try
put 0 into gConID
put empty into field status
answer info "Connection Terminated "
end doDisconnect ------------------------------------------------------
on doCreate -----------------------------------------------------------
if not Connection() then exit doCreate
try
put "CREATE TABLE users(userID integer primary key autoincrement, name text)" into tSQL
revExecuteSQL gConID, tSQL
put the result into temp
if the result is not 0 then
answer warning the result
exit doCreate
end if
catch theError
answer warning theError
exit doCreate
end try
answer information "Table 'Users' Created Sussessfully"
end doCreate --------------------------------------------------------
on doDeleteTable ---------------------------------------------------------
if not Connection() then exit doDeleteTable
try
put "DROP TABLE users;" into tSQL
revExecuteSQL gConID, tSQL
put the result into temp
if the result is not 0 then
answer warning the result
exit doDeleteTable
end if
catch theError
answer warning theError
exit doDeleteTable
end try
put empty into field status
answer information "Table 'Users' Deleted Sussessfully"
end doDeleteTable --------------------------------------------------------
on doPopulate ------------------------------------------------------
if not Connection() then exit doPopulate
try
repeat with ii = 1 to 30
put empty into temp
repeat with jj = 1 to 20 -- create 20 random characters
put temp & numtochar(randomNum(97,122) ) into temp
end repeat
put "INSERT INTO users (name) values ('" & temp & "')" into tSQL
revExecuteSQL gConID, tSQL
if the result is not 1 then
answer warning the result
exit doPopulate
end if
put ii into field "counter"
end repeat
catch theError
answer warning theError
exit doPopulate
end try
answer information "Random Data Added to Table 'Users'"
end doPopulate ------------------------------------------------------
on doRead ----------------------------------------------------------
if not Connection() then exit doRead
try
put "SELECT ID,TITLE FROM products LIMIT 100" into tSQL
put revdb_querylist(,,gConID,tSQL) into ptext
put false into firstLineContainsColumnNames
set the dgText of group "myGrid" to ptext
put "100" into LimitBegin
catch theError
answer warning theError
exit doRead
end try
end doRead
on doRead2 ----------------------------------------------------------
if not Connection() then exit doRead2
try
put LimitBegin + 25 into LimitEnd
answer "Limit End: " & LimitEnd & "Limit Begin" & LimitBegin
put ("SELECT ID,TITLE FROM products LIMIT " & LimitBegin &","& LimitEnd) into tSQL
put LimitEnd into LimitBegin
answer "Limit End: " & LimitEnd & "Limit Begin" & LimitBegin
answer tSQL
//put "SELECT ID,TITLE FROM products LIMIT " . LimitSetting into tSQL
put revdb_querylist(,,gConID,tSQL) into ptext
put false into firstLineContainsColumnNames
set the dgText of group "myGrid" to ptext
catch theError
answer warning theError
exit doRead2
end try
end doRead2
on doUpdateRow
put the dgHilitedLines of group "mygrid" into theLine
put the dgDataOfLine[theLine] of group "mygrid" into theDataA
## theDataA is now an array variable.
--answer theDataA["id"] && theDataA["Name"] --for debuging
-- now we need to update the SQLite DB
put theDataA["id"] into xID
put theDataA["Name"] into xName
if not Connection() then exit doUpdateRow
try
put "UPDATE users SET Name='" & xName & "' WHERE userID='" & xID &"'" into tSQL
revExecuteSQL gConID, tSQL
put the result into temp
if the result is not 1 then
answer warning the result
exit doUpdateRow
end if
catch theError
answer warning theError
exit doUpdateRow
end try
answer information "Table 'Users' Updated Sussessfully"
end doUpdateRow
function Connection ----------------------------------------------
if gConID is 0 then
answer info "Press the Connect button first."
return false
else
return true
end if
end Connection ---------------------------------------------------
function randomNum lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomNum
-- For successful queries, the revExecuteSQL command returns
-- the # of rows affected for INSERT, UPDATE and DELETE statements.
-- For all other statements, 0 is returned, so if the result is 0... then everything is good
Code: Select all
on closefieldeditor
--doUpdateRow
--answer information the text of pfieldeditor
--answer information the dgHilitedLines of group "myGrid"
--put the short name of me into theFieldname
--send refreshline to me
-- put the dgHilitedLines of group "mygrid" into theLine
-- put the dgDataOfLine[theLine] of group "mygrid" into theDataA
-- ## theDataA is now an array variable.
-- answer theDataA["id"] && theDataA["Name"]
end closefieldeditor
on editvalue
beep
end editvalue
on mouseDoubleUp pMouseBtnNum
## Let Data Grid process mouseDown and select row that was clicked on
dgMouseDown pMouseBtnNum
## Get value of column clicked on. The column name can be accessed in the
## dgColumn custom property of the column control (the target).
put GetDataOfIndex(the dgHilitedIndexes of me, the dgColumn of the target) into theColumnValue
put theColumnValue into CurrentID
answer CurrentID
//send (CurrentID && CurrentID) to card "Edit Card"
go to card "Edit Card" in a new window //as modal
## Don't pass mouseDown
end mouseDoubleUp
Code: Select all
on preOpenCard
global CurrentID
set the text of field "Field" to CurrentID
answer CurrentID
end preOpenCard
/*on OpenCard -- highlight the "go to this card" button in a set
set the text of field "Field" to CurrentID
//put CurrentID into field "Field"
answer "Hello"
answer CurrentID
answer gConID
pass OpenCard
end OpenCard*/
on closeCard -- record date and time the card was last viewed
-- in a custom property of the card
set the lastAccessDate of the target to the seconds
pass closeCard
end closeCard
Code: Select all
on mouseDoubleUp pMouseBtnNum
## !!!
GLOBAL CurrentID
## !!!
## Let Data Grid process mouseDown and select row that was clicked on
dgMouseDown pMouseBtnNum
## Get value of column clicked on. The column name can be accessed in the
## dgColumn custom property of the column control (the target).
put GetDataOfIndex(the dgHilitedIndexes of me, the dgColumn of the target) into theColumnValue
put theColumnValue into CurrentID
answer CurrentID
## send (CurrentID && CurrentID) to card "Edit Card"
## !!!
## You cannot go to another card of the SAME stack in another window!
go to card "Edit Card"
## in a new window //as modal
## Don't pass mouseDown
end mouseDoubleUp