In converting an A5 v1 app to v4, I discovered that something I knew how to do in v1 was something I have been unable to figure out how to do in v4, namely view the contents of a table (say on a diskette) that is not in the v4 database using the table's default form. And, optionally, view it with it's default browse, all without even temporarily adding the table to the v4 database.
It turns out that a lot of trial and error with v1 code got me very close to what I want (but not quite in that a version of the code for Button 2 for the default browse only gets me the browse attached to and last used for the table, not the default browse). In any case, it seems to me that using butchered v1 code is not a good practice for future versions of A5 in which it may not work at all. Also, the code for button 1 won't work if the path has spaces in it, such as "C:Program FilesA5v4".
Anyone know how to accomplish what I want using v4 code?
Ideally, I would also like to be able to specify which attached form or browse to use when I know what they are named. But using the defaults would suffice (especially when others do not exist or I do not know their names)
The code below is taken from 2 buttons on form in an A5 v4 database (the code was originally in a v1 application). A sample database should be attached to this message.
�********BUTTON 1, mainly sets the variable DbfName to be the path and table name
�**of table not in the current A5 database:
DIM Global DbfName AS C
DIM HDHistoryDir AS C
HDHistoryDir=A_DB_current_path+"history"
Old_dir=dir_get()
dir_put(HDHistoryDir)
'**The above puts the file open in a specific path. When it doesn't exist
�**you just go to My Computer
DbfName=UI_GET_FILE("Open A Different History File","database(*.dbf)","","X")
IF DbfName=""
parent.resynch()
end
end if
dir_put(Old_dir)
' **Display the changes on the form (just need to refresh the variable object, but...).
parent.RESYNCH()
�**********END OF BUTTON 1 CODE********
�********BUTTON 2, opens the default form layout for the table selected with button 1.
' **Make sure the file exists. FILE_EXISTS() is true for *.dbf
IF FILE_EXISTS( DbfName ) = .F. .OR. "*" $ DbfName
' Complain if the file L_NAME is bad.
UI_MSG_BOX( "You need to select a file first.", "Unable to open: " + DbfName )
ELSE
' Open the default form layout.
CARD_SPAWN("FORM_VIEWER","SPAWNDB="+DbfName+"Default Form")
'**The above was derived thru trial & error from the following v1 code, which does not
�**work in v4, except possibly one time, after which the code gets automatically
�**truncated to something that won't work.
'CARD_SPAWN("FORM_VIEWER", "SPAWNDB=~" + DbfName + "~ SPAWNNEW=0 SPAWNCHILD=1 USE=~~")
END IF
END
�************END OF CODE FOR BUTTON 2*********
Interestingly, if you leave out the +"Default Form" in:
CARD_SPAWN("FORM_VIEWER","SPAWNDB="+DbfName+"Default Form")
what you get is the last used non-default form attached to the table (if there is one), not the default form. And when there is a named browse, similar code will always get you the last used named browse and never the default.
Ray Lyons
It turns out that a lot of trial and error with v1 code got me very close to what I want (but not quite in that a version of the code for Button 2 for the default browse only gets me the browse attached to and last used for the table, not the default browse). In any case, it seems to me that using butchered v1 code is not a good practice for future versions of A5 in which it may not work at all. Also, the code for button 1 won't work if the path has spaces in it, such as "C:Program FilesA5v4".
Anyone know how to accomplish what I want using v4 code?
Ideally, I would also like to be able to specify which attached form or browse to use when I know what they are named. But using the defaults would suffice (especially when others do not exist or I do not know their names)
The code below is taken from 2 buttons on form in an A5 v4 database (the code was originally in a v1 application). A sample database should be attached to this message.
�********BUTTON 1, mainly sets the variable DbfName to be the path and table name
�**of table not in the current A5 database:
DIM Global DbfName AS C
DIM HDHistoryDir AS C
HDHistoryDir=A_DB_current_path+"history"
Old_dir=dir_get()
dir_put(HDHistoryDir)
'**The above puts the file open in a specific path. When it doesn't exist
�**you just go to My Computer
DbfName=UI_GET_FILE("Open A Different History File","database(*.dbf)","","X")
IF DbfName=""
parent.resynch()
end
end if
dir_put(Old_dir)
' **Display the changes on the form (just need to refresh the variable object, but...).
parent.RESYNCH()
�**********END OF BUTTON 1 CODE********
�********BUTTON 2, opens the default form layout for the table selected with button 1.
' **Make sure the file exists. FILE_EXISTS() is true for *.dbf
IF FILE_EXISTS( DbfName ) = .F. .OR. "*" $ DbfName
' Complain if the file L_NAME is bad.
UI_MSG_BOX( "You need to select a file first.", "Unable to open: " + DbfName )
ELSE
' Open the default form layout.
CARD_SPAWN("FORM_VIEWER","SPAWNDB="+DbfName+"Default Form")
'**The above was derived thru trial & error from the following v1 code, which does not
�**work in v4, except possibly one time, after which the code gets automatically
�**truncated to something that won't work.
'CARD_SPAWN("FORM_VIEWER", "SPAWNDB=~" + DbfName + "~ SPAWNNEW=0 SPAWNCHILD=1 USE=~~")
END IF
END
�************END OF CODE FOR BUTTON 2*********
Interestingly, if you leave out the +"Default Form" in:
CARD_SPAWN("FORM_VIEWER","SPAWNDB="+DbfName+"Default Form")
what you get is the last used non-default form attached to the table (if there is one), not the default form. And when there is a named browse, similar code will always get you the last used named browse and never the default.
Ray Lyons
Comment