Subject |
Re: attachment for mv_mail programm |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Sat, 18 Nov 2023 09:07:08 +0200 |
Newsgroups |
dbase.getting-started |
Attachment(s) |
bijlage_test.wfm |
On 2023/11/17 00:40, Dirk C wrote:
> hello,
>
> looking for a way to get a variable from 1 function to an other
>
>
> i am working with a function to get a file :: function bijlageB
>
> got by this function
>
> function knop_bijlage_onClick()
> class::bijlageB()
> return
> *****
> need to get the variable into bijlageA ( for testing to send the
> attcahment i use opslaanA an B)
>
> with function zendemail
You can use the RETURN command at the end of a function to make data,
which can be a single value of any type or an array, from a function
available elsewhere. Simply assign the executed function to a variable
or object property.
function knop_bijlage_onClick()
test_array = class::bijlageA() //the () executes the function
//and places a copy of the array groep in test_array
class::bijlageB(test_array) //the array in () is passed to
//bijlageB and the () executes the function using the array
return
function bijlageB
groep = new array()
groep.add('item 1')
groep.add('item 2')
groep.add('item 3')
return groep
function bijlageA(aArray)
for n = 1 to aArray.size
form.email.setattachment(aArray[n])
next
return
Using getfile() works well where one needs to select just one file. If
you need to select more than one file to attach to an email this is
going to be a nuisance. You are better off using getdir() to save a
directory name in an entryfield and then use dir() to place a list of
the files in that directory in a listbox on your form. By holding down
the ctrl key multiple files can be selected. You access the selected
files by using the listbox's selected() method.
for n = 1 to form.listbox1.selected().size
?form.listbox1.selected()[n]
next
At first sight this looks most peculiar but it does work. :-)
A little example form is attached. To allow multiple selections to be
made, the listbox's multiple property is set true. You will need to
edit the entryfield1 value property to set an appropriate default
directory. You will also need to edit the filetype skeleton in the
get_file_list function. I have it set to '\*.*' for testing but you may
want to make it more limited.
When a listbox opens the first entry is always selected and shown
highlighted. Where multiple selections are allowed a selection can be
cancelled by left-clicking on the entry with the ctrl key held down.
The example form uses code ("stolen" from Marc van den Berghen MANY
years ago :-) ) to deselect the first entry in the listbox so that the
user starts with a clean sheet. This is only possible where the
listbox's multiple property is set true. The user can, of course still
select the first entry if required.
Mervyn.
| clear
** END HEADER -- do not remove this line
//
// Generated on 2023-11-17
//
parameter bModal
local f
f = new bijlage_testForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class bijlage_testForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
metric = 6 // Pixels
height = 413.0
left = 190.0
top = 33.0
width = 713.0
text = ""
endwith
this.KNOP_BIJLAGE = new PUSHBUTTON(this)
with (this.KNOP_BIJLAGE)
onClick = class::KNOP_BIJLAGE_ONCLICK
height = 57.0
left = 374.0
top = 177.0
width = 131.0
text = "Run function bijlageB() to select files."
endwith
this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
height = 57.0
left = 374.0
top = 261.0
width = 131.0
text = "Run function bijlageA() to display selected files"
endwith
this.EDITOR1 = new EDITOR(this)
with (this.EDITOR1)
height = 126.0
left = 320.0
top = 34.0
width = 321.0
value = ""
endwith
this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
height = 22.0
left = 35.0
top = 36.0
width = 213.0
value = "D:\examples"
endwith
this.PUSHBUTTON2 = new PUSHBUTTON(this)
with (this.PUSHBUTTON2)
onClick = class::PUSHBUTTON2_ONCLICK
height = 24.0
left = 50.0
top = 68.0
width = 107.0
text = "Change directory"
endwith
this.LISTBOX1 = new LISTBOX(this)
with (this.LISTBOX1)
onRightMouseUp = class::LISTBOX1_ONRIGHTMOUSEUP
height = 232.0
left = 35.0
top = 162.0
width = 218.0
id = 106
colorHighLight = "HighLightText/HighLight"
multiple = true
vScrollBar = 1 // On
endwith
this.TEXTLABEL1 = new TEXTLABEL(this)
with (this.TEXTLABEL1)
height = 22.0
left = 35.0
top = 105.0
width = 267.0
text = "Use Ctrl-key to select/deselect multiple files"
endwith
this.TEXTLABEL2 = new TEXTLABEL(this)
with (this.TEXTLABEL2)
height = 22.0
left = 35.0
top = 132.0
width = 226.0
text = "Right-click to clear selection "
endwith
this.PUSHBUTTON3 = new PUSHBUTTON(this)
with (this.PUSHBUTTON3)
onClick = class::PUSHBUTTON3_ONCLICK
height = 57.0
left = 374.0
top = 341.0
width = 131.0
text = "Print listbox1.selected()"
endwith
function KNOP_BIJLAGE_onClick()
//save the array returned by bijlageB in
form.editor1.value = ''
form.bijlage_array = class::bijlageB()
return
function LISTBOX1_onRightMouseUp(flags, col, row)
class::renew_listbox_list()
this.cursel = 1
class::deselectEntry()
return
function PUSHBUTTON1_onClick()
if type('form.bijlage_array') ='A'
class::bijlageA(form.bijlage_array)
else
msgbox("bijlageB hasn't been executed")
endif
return
function bijlageB
aGroep = new array()
aGroep = form.listbox1.selected()
return aGroep
function PUSHBUTTON2_onClick()
form.entryfield1.value = getdir()
class::renew_listbox_list()
form.listbox1.cursel = 1
class::deselectEntry()
return
function renew_listbox_list
form.listbox1.selected() = null
form.listbox1.datasource = null
aList = class::get_file_list()
form.aList_first = aList[1]
form.listbox1.datasource = 'ARRAY aList'
class::deselectentry()
return
function PUSHBUTTON3_onClick()
if form.listbox1.selected().size = 0
msgbox('Nothing selected')
endif
for n = 1 to form.listbox1.selected().size
? form.listbox1.selected()[n]
next
return
function bijlageA(aArray)
//Replace with code to set email attachments
if aArray.size = 0
msgbox('Nothing selected')
endif
form.editor1.value = ''
for n = 1 to aArray.size
form.editor1.value += aArray[n]
form.editor1.value += chr(13)+chr(10)
next
return
function get_file_list
//Creates the array aList containing a list of
//filenames held in the directory shown in entryfield1
local aFiles,nFiles,cSkeleton
private aList
#define ARRAY_DIR_NAME 1
aFiles = new Array() // Array will be resized as needed
aList = new array() //One dimension array for listbox
cFileType = '\*.*' //Change as appropriate
cSkeleton = form.entryfield1.value+cFileType
nFiles = aFiles.dir(cSkeleton)
for nFile = 1 to nFiles
aList.add(aFiles[nFile,ARRAY_DIR_NAME])
next
return aList
function setcontrolkey(onoff,nstate)
local keybuffer,state,vk_control
vk_control = 0x11 //virtual key code for control key
keybuffer = Space(256)
GetKeyboardState(keybuffer)
state=keybuffer.getbyte(vk_control)
If onoff # 0
nstate=bitor(128,state)
endif
keybuffer.setbyte(vk_control,nstate)
SetKeyboardState(keybuffer)
return state
function deselectEntry
wm_lbuttondown = 0x0201
wm_lbuttonup = 0x0202
class::setcontrolkey(1,0)
sendmessage(form.listbox1.hwnd,wm_lbuttondown,9,0x100010)
sendmessage(form.listbox1.hwnd,wm_lbuttonup,9,0x100010)
class::setcontrolkey(0,1)
return
function form_onOpen()
if type("SendMessage") # "FP"
extern clong SendMessage(chandle,cuint,clong,clong) user32 ;
from "SendMessageA"
endif
if type("GetKeyboardState") # "FP"
extern CVOID GetKeyboardState(CPTR) User32
endif
if type("SetKeyboardState") # "FP"
extern CVOID SetKeyboardState(CPTR) User32
endif
//get list of files in diretory shown in entryfield1
aList = class::get_file_list()
form.listbox1.datasource = 'ARRAY aList'
class::deselectEntry()
return
endclass
|
|