Using dynamic list of database names

jamesmc

Member
I can build a list of the names of databases that are connected when my program is run.

The thing I would then like to do is perform actions on the database that is selected from the list by the user, ie. for each {database name}._file etc.

Does anyone have any suggestions on how to perform actions against a selected database. This code needs to be as generic as possible. I am using Progress v8.3.

Thanks,

James
 

Chris Kelleher

Administrator
Staff member
Hi James-

This is fairly easy to do using a database alias. For example:

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
/* choosedb.p */
/* let user choose their database... */
CREATE ALIAS mydb FOR DATABASE sports.
RUN choosefile.p.


/* choosefile.p */
FOR EACH mydb._file:
/* do whatever */
END.
[/code]

HTH.

-Chris


------------------
Chris Schreiber
ProgressTalk.com Manager
chris@fast4gl.com

[This message has been edited by progresstalk (edited 31 January 2000).]
 

Chris Kelleher

Administrator
Staff member
Chris,

Sorry to trouble you again but I am still having a little bit of trouble with the problem that I posted. Basically, when the program runs I want the user to select a database from the list of connected ones, and I then want to be able to display a list of the files within that database. This needs to be as generic as possible so I can run it on any Progress system. I have attached a sample piece of code for you to look at and tell me what you think. I know that the code doesn't work but you basically get the idea of what I want to do.

Thanks for your time,
James.

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
def button b-1 label "Tell me More".

def var w-i as int.
def var w-dbname as cha format "x(6)".
def var w-db as cha format "x(20)" label "Database"
view-as combo-box
inner-lines 4 size 25 by 1 NO-UNDO.

form skip(1)
w-db at 10
skip(1)
b-1 at 14
skip(1)
with frame f1 centered
width 40 no-labels.


REPEAT w-i = 1 TO NUM-DBS:
w-db:add-last(LDBNAME(w-i)).
w-dbname = (ldbname(w-i) + "1").
CREATE ALIAS value(w-dbname) FOR DATABASE value(w-db:screen-value).
END.

/* From the value that the user selects in
the dropdown list display all of the files
in that database */
on choose of b-1 do:
for each value((w-db:screen-value + "1"))._file
where (w-db:screen-value + "1")._file._file-name
< "_" NO-LOCK:
display (w-db:screen-value + "1")._file._file-name
with 1 column.
end.
end.

enable all with frame f1.

wait-for choose of b-1.

[/code]

[This message has been edited by progresstalk (edited 02 February 2000).]
 

Chris Kelleher

Administrator
Staff member
James-

No trouble at all. I attached two sample programs to this email to
show you how this can work. Basically, you need to selected the
database and create the alias in the main program, then run a
sub-program to display the tables.

HTH.

-Chris

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
def button b-1 label "Tell me More".

def var w-i as int.
def var w-dbname as cha format "x(6)".
def var w-db as cha format "x(20)" label "Database"
view-as combo-box
inner-lines 4 size 25 by 1 NO-UNDO.


form skip(1)
w-db at 10
skip(1)
b-1 at 14
skip(1)
with frame f1 centered width 40 no-labels.


REPEAT w-i = 1 TO NUM-DBS:
w-db:add-last(LDBNAME(w-i)).
END.

/* From the value that the user selects in
the dropdown list display all of the files
in that database */

on choose of b-1 do:
CREATE ALIAS "selecteddb"
FOR DATABASE value(w-db:screen-value).
RUN displayfile.p.
end.

enable all with frame f1.

wait-for choose of b-1.
[/code]

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
for each selecteddb._file where
selecteddb._file._file-name < "_" NO-LOCK:
display selecteddb._file._file-name
with 1 column.
end.
[/code]




------------------
Chris Schreiber
ProgressTalk.com Manager
chris@fast4gl.com
 
Top