Re: tbl.rules_get() problem
Here is a code for a script to provide the user the ability to 1) find out the field data type of a field in the database and then 2) have the ability to change it. The second part is not in this script, just the first. I was going to give this to the code archives once complete.
The system throws an error when there is not a field rule data type set. The code Stan presented (red, line 80) to circumvent this does not work. Is there a way to error trap this within the code for the xdialog?
Thanks
Here is a code for a script to provide the user the ability to 1) find out the field data type of a field in the database and then 2) have the ability to change it. The second part is not in this script, just the first. I was going to give this to the code archives once complete.
The system throws an error when there is not a field rule data type set. The code Stan presented (red, line 80) to circumvent this does not work. Is there a way to error trap this within the code for the xdialog?
Thanks
Code:
' get list of the current tables dim vTM as C="" vTM = a5.table_enum() dim vFM as C="" 'Create list of field rules DIM vL1 as C vL1= <<%a% user_entered calculated auto_increment %a% '======== generate the xDialogs =================== dim start_type as C dim end_type as C dim tablename as C dim fieldname as C = "Field Name" dim shared vdy as C RETRY: DIM vW as C vW = word_subtract(vL1,"USER_ENTERED",crlf()) Gchoices = vL1 vStart = word( Gchoices, 1, crlf() ) endchoices = vW dlg_text = <<%dlg% {position=1.5,2.5} {background=#155,175,165} {xmargin=2,2} {font=Arial,9,b} {frame=1,1: Table and Field} {font=Arial,9,n} {region} [.25tablename^+vTM!tc_*] {sp} | [.25fieldname^+vFM!fc_*] {endregion}; {lf}; {region} Current Data Type: | [.25vDY] {endregion}; {lf}; {region} {font=Arial,9,b} {frame=1,0:Current Field Type} {font=Arial,9,n} [.30,4start_type^#Gchoices!newd_*]; {endregion} {region}{comment this region is just to space things out a bit} {comment this adds even more space - maybe too much} {endregion} {region} {font=Arial,9,b}{frame=1,1:Change To Field Type }{font=Arial,9,n} [.30,4end_type^#endchoices]; {endregion} {condition=.t.} {lf}; {line=1,0} {lf}; <10OK> <10Cancel> %dlg% dim vresults as C vresult=ui_dlg_box("Item Choices", dlg_text, <<%code% ' this is for a trapping a change in the tablefield box IF left( a_dlg_button, 3 ) = "tc_" IF a_dlg_button = "tc_change" vFM = sortsubstr(w_upper(lower(table.external_field_name_get(tablename,"N"))),crlf(),"a") END IF a_dlg_button = "" ' this is for a trapping a change in the fieldname box to get the current data type ELSE IF left(a_dlg_button, 3) = "fc_" IF a_dlg_button = "fc_change" tbl = table.open(tablename) fr = tbl.rules_get() [COLOR="Red"]if prop_valid(eval("fr."+fieldname),"data_type") vdy = eval("fr."+fieldname+".data_type") else vdy = "No field rules indicating data type." end if[/COLOR] vdy = eval("fr."+fieldname+".data_type") msgbox(vdy) tbl.close() END IF a_dlg_button = "" ' this is for a trapping a change in the current datatype ELSE IF left( a_dlg_button, 5 ) = "newd_" IF a_dlg_button = "newd_change" endchoices = word_subtract(vL1,start_type,crlf()) END IF a_dlg_button = "" END IF %code%) if end_type = "" then p_msg_box("ALERT","The end type was not chosen correctly. Try again? .","<Yes><Cancel>","") select case vReply = "Yes" GOTO RETRY case vReply = "Cancel" vProceed = "no" end end select else if start_type = "" then p_msg_box("ALERT","The start type was not chosen correctly. Try again? .","<Yes><Cancel>","") select case vReply = "Yes" GOTO RETRY case vReply = "Cancel" vProceed = "no" end end select end if start_type = chrtran(start_type,"_"," ") end_type = chrtran(end_type,"_"," ")
Comment