March 29, 2024, 06:23:16 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Cannot Set Focus in an edit box in a Dialog called from a Window

Started by AdrianFox, January 18, 2014, 11:47:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

Sorry to post another simple question about a simple problem....

I am opening a dialog from my main window to enter a text string in its editbox.  The dialog is called as a Global Sub from the main window with a DOMODAL call.  This all works fine  except I cannot get the focus/caret  into the editbox in the dialog where text is to be entered. In a simple dialog this works fine of course.

I have placed 'SETFOCUS d1, edit_1 ' in the CASE @IDINITDIALOG  part of the dialog handler.  But the focus does not appear there, nor if I make this command from the main window prior to the DoModal call.

I am guessing this might because  the FOCUS remains with the Window.  How can I place the focus into the editbox in the dialog?  If I close the window before moving to the dialog it will disrupt the other things I am trying to do.

???
Adrian Fox

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

Here is all my code:

globals.iwb
PROJECTGLOBAL "ON"

WINDOW Seeds
dialog d1
dialog d2

PROJECTGLOBAL "OFF"


Include file

CONST Seeds_STATIC1 = 0x101
CONST LeftButton = 0x102
CONST RightButton = 0x103
CONST FirstRecordButton = 0x104
CONST LastRecordButton = 0x105
CONST SeedNameEdit = 0x106
CONST SeedTypeEdit = 0x107
CONST Seeds_STATIC2 = 0x108
CONST Seeds_STATIC3 = 0x109
CONST SupplierEdit = 0x10A
CONST YearEdit = 0x10B
CONST Seeds_STATIC4 = 0x10C
CONST Seeds_STATIC5 = 0x10D
CONST RecordNumber = 0x10E
CONST Seeds_STATIC6 = 0x10F
CONST DTPICKSown = 0x110
CONST DTPICKGerm = 0x111
CONST Seeds_STATIC7 = 0x112
CONST Seeds_STATIC8 = 0x113
CONST DateSownEdit = 0x114
CONST DateGermEdit = 0x115
CONST NotesEdit = 0x116
CONST Seeds_STATIC9 = 0x117
CONST NewButton = 0x118
CONST SaveButton = 0x119
CONST UpDateButton = 0x11A
CONST SearchNameButton = 0x11B
CONST SearchRecNoButton = 0x11C
CONST QuitButton = 0x11D
CONST DateHarvest = 0x11E
CONST DTPICKHarvest = 0x11F
CONST Seeds_STATIC10 = 0x120
const static_1=0x121
const edit_2=0x122
const button_3=0x123
const static_2=0x124
const edit_3=0x125
const button_4=0x126

CONST Seeds_menu12 = 0x1001
CONST Seeds_menu16 = 0x1002
CONST Seeds_menu17 = 0x1003
CONST Seeds_menu20 = 0x1004

declare extern startsearchbox()
declare extern numbersearch()
type SeedDataEntry
DEF Seedname[50] as istring
DEF Seedtype[12] as istring
DEF Seedsupply[28] as istring
DEF YearNum[5] as istring  'strangely only 3 characters get saved if you set this for 4
DEF RecNum[4] as istring
DEF DateSown[18] as istring
DEF DateGerm[18] as istring
DEF DateHarv[18] as istring
DEF NoteText[450] as istring
endtype

def seedData as SeedDataEntry

def myfile as bfile 'file for random access
def exportfile as file 'file for export of delimited file

def longdate,RecordNumber$,searchname:string
def NotesLimit,y,count:int
'declare extern startsearchbox()


Main module Seeds.iwb

$MAIN
$INCLUDE "NEWSeedDatabase.inc"
$INCLUDE "globals.iwb"


OpenMainWindow()
ProcessAll()
END


SUB OpenMainWindow()

OPENWINDOW seeds,0,0,806,675,@SIZE|@MINBOX|@MAXBOX|@CAPTION|@SYSMENU,0,"SeedDatabase201",&Seeds_handler

CONTROL Seeds,@STATIC,"Seed Database 2014",240,0,327,44,0,Seeds_STATIC1
CONTROL Seeds,@SYSBUTTON,"<<<<",16,60,60,25,0,LeftButton
CONTROL Seeds,@SYSBUTTON,">>>>",724,60,60,25,0,RightButton
CONTROL Seeds,@SYSBUTTON,"First",81,60,60,25,0,FirstRecordButton
CONTROL Seeds,@SYSBUTTON,"Last",654,60,60,25,0,LastRecordButton
CONTROL Seeds,@EDIT,"",28,114,351,38,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,SeedNameEdit
CONTROL Seeds,@EDIT,"",405,116,316,38,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,SeedTypeEdit
CONTROL Seeds,@STATIC,"Seed Name",156,96,127,17,0,Seeds_STATIC2
CONTROL Seeds,@STATIC,"Seed Type",500,96,127,17,0,Seeds_STATIC3
CONTROL Seeds,@EDIT,"",28,184,347,38,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,SupplierEdit
CONTROL Seeds,@EDIT,"",409,184,75,38,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,YearEdit
CONTROL Seeds,@STATIC,"Supplier",158,163,60,19,0,Seeds_STATIC4
CONTROL Seeds,@STATIC,"Year",423,163,60,18,0,Seeds_STATIC5
CONTROL Seeds,@EDIT,"",646,184,75,36,@CTEDITAUTOH|@CTEDITleft|@TABSTOP,RecordNumber
CONTROL Seeds,@STATIC,"Record Number",588,185,60,34,0,Seeds_STATIC6
DateTimePicker Seeds,"DTPick 1",28,270,118,25,@BORDER|@DTS_LONGDATEFORMAT|@DTS_SHOWNONE,0,DTPICKSown
DateTimePicker Seeds,"DTPick 2",215,270,118,25,@BORDER|@DTS_LONGDATEFORMAT|@DTS_SHOWNONE,0,DTPICKGerm
CONTROL Seeds,@STATIC,"Date Sown",41,248,127,20,0,Seeds_STATIC7
CONTROL Seeds,@STATIC,"Date Germinated",211,248,127,20,0,Seeds_STATIC8
CONTROL Seeds,@EDIT,"",28,296,118,25,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,DateSownEdit
CONTROL Seeds,@EDIT,"",215,296,118,25,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,DateGermEdit
CONTROL Seeds,@EDIT,"",28,355,707,120,@CTEDITMULTI|@TABSTOP,NotesEdit
CONTROL Seeds,@STATIC,"Notes",361,334,60,19,0,Seeds_STATIC9
CONTROL Seeds,@BUTTON,"New",32,547,60,25,0,NewButton
CONTROL Seeds,@BUTTON,"Save",140,547,60,25,0,SaveButton
CONTROL Seeds,@BUTTON,"Update",248,547,60,25,0,UpDateButton
CONTROL Seeds,@BUTTON,"Search Name",356,547,85,25,0,SearchNameButton
CONTROL Seeds,@BUTTON,"Search Record Number",489,547,134,25,0,SearchRecNoButton
CONTROL Seeds,@BUTTON,"Quit",671,547,60,25,0,QuitButton
CONTROL Seeds,@EDIT,"",396,296,118,25,@CTEDITAUTOH|@CTEDITLEFT|@TABSTOP,DateHarvest
DateTimePicker Seeds,"DTPick 3",396,270,118,25,@BORDER|@DTS_LONGDATEFORMAT|@DTS_SHOWNONE,0,DTPICKHarvest
CONTROL Seeds,@STATIC,"Date of 1st Harvest",395,248,152,20,0,Seeds_STATIC10

SETFONT Seeds,"Georgia",10,700,0
SETWINDOWCOLOR Seeds, RGB(56,203,252)
FRONTPEN Seeds, RGB(0,0,0)
SETFONT Seeds,"Arial Black",22,400,0,Seeds_STATIC1
SETCONTROLCOLOR Seeds,Seeds_STATIC1,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"Arial",10,700,0,LeftButton
SETCONTROLCOLOR Seeds,LeftButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"Arial",10,700,0,RightButton
SETCONTROLCOLOR Seeds,RightButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"Georgia",10,700,0,FirstRecordButton
SETCONTROLCOLOR Seeds,FirstRecordButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"Georgia",10,700,0,LastRecordButton
SETCONTROLCOLOR Seeds,LastRecordButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"Georgia",12,700,0,SeedNameEdit
SETCONTROLCOLOR Seeds,SeedNameEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"Georgia",12,700,0,SeedTypeEdit
SETCONTROLCOLOR Seeds,SeedTypeEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC2
SETCONTROLCOLOR Seeds,Seeds_STATIC2,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC3
SETCONTROLCOLOR Seeds,Seeds_STATIC3,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"Georgia",12,700,0,SupplierEdit
SETCONTROLCOLOR Seeds,SupplierEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"Georgia",12,700,0,YearEdit
SETCONTROLCOLOR Seeds,YearEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC4
SETCONTROLCOLOR Seeds,Seeds_STATIC4,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC5
SETCONTROLCOLOR Seeds,Seeds_STATIC5,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"Georgia",12,700,0,RecordNumber
SETCONTROLCOLOR Seeds,RecordNumber,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC6
SETCONTROLCOLOR Seeds,Seeds_STATIC6,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"MS Sans Serif",8,400,0,DTPICKSown
SETCONTROLCOLOR Seeds,DTPICKSown,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",8,400,0,DTPICKGerm
SETCONTROLCOLOR Seeds,DTPICKGerm,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC7
SETCONTROLCOLOR Seeds,Seeds_STATIC7,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC8
SETCONTROLCOLOR Seeds,Seeds_STATIC8,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"Georgia",8,700,0,DateSownEdit
SETCONTROLCOLOR Seeds,DateSownEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"Georgia",8,700,0,DateGermEdit
SETCONTROLCOLOR Seeds,DateGermEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"Georgia",11,700,0,NotesEdit
SETCONTROLCOLOR Seeds,NotesEdit,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC9
SETCONTROLCOLOR Seeds,Seeds_STATIC9,RGB(0,0,0),RGB(56,203,252)
SETFONT Seeds,"MS Sans Serif",8,400,0,NewButton
SETCONTROLCOLOR Seeds,NewButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"MS Sans Serif",8,400,0,SaveButton
SETCONTROLCOLOR Seeds,SaveButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"MS Sans Serif",8,400,0,UpDateButton
SETCONTROLCOLOR Seeds,UpDateButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"MS Sans Serif",8,400,0,SearchNameButton
SETCONTROLCOLOR Seeds,SearchNameButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"MS Sans Serif",8,400,0,SearchRecNoButton
SETCONTROLCOLOR Seeds,SearchRecNoButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"MS Sans Serif",8,400,0,QuitButton
SETCONTROLCOLOR Seeds,QuitButton,RGB(0,0,0),RGB(192,192,192)
SETFONT Seeds,"Georgia",8,700,0,DateHarvest
SETCONTROLCOLOR Seeds,DateHarvest,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",8,400,0,DTPICKHarvest
SETCONTROLCOLOR Seeds,DTPICKHarvest,RGB(0,0,0),RGB(255,255,255)
SETFONT Seeds,"MS Sans Serif",10,700,0,Seeds_STATIC10
SETCONTROLCOLOR Seeds,Seeds_STATIC10,RGB(0,0,0),RGB(56,203,252)
CENTERWINDOW Seeds

startsearchbox()  'absolutely vital to load the dialog ready to use
numbersearch()

BEGINMENU Seeds
MENUTITLE "Menu"
MENUITEM "Garden Diary", 0,Seeds_menu12
MENUITEM "View HTML Seed List", 0,Seeds_menu16
MENUITEM "Export List as CSV (* separator)", 0,Seeds_menu17
MENUITEM "Quit", 0,Seeds_menu20
ENDMENU

ONMENUPICK Seeds,Seeds_menu12,&DoMnu_Seeds_menu12 'garden diary
ONMENUPICK Seeds,Seeds_menu16,&DoMnu_Seeds_menu16  'html seed list
ONMENUPICK Seeds,Seeds_menu17,&DoMnu_Seeds_menu17  'export list
ONMENUPICK Seeds,Seeds_menu20,&DoMnu_Seeds_menu20  'quit program

ONMESSAGE Seeds,@IDCLOSEWINDOW,&OnMainClose

'COORDINATES OF LINE START AND END, NOT SIZE OR WIDTH LIKE OTHER CONTROLS
line Seeds, 0, 48, 800, 48, RGB(0,0,0)  'lines drawn across window in two places
line seeds,0,480,800,480,rgb(0,0,0)

Oncontrol seeds,SearchRecNoButton,@notifycode,&SearchRecNum
Oncontrol seeds,SearchNameButton,@notifycode,&SearchForName
Oncontrol seeds,UpDateButton,@notifycode,&UpdateFile
Oncontrol seeds,SaveButton,@notifycode,&savefile
Oncontrol seeds,NewButton,@notifycode,&OpenNew
Oncontrol seeds,LastRecordButton,@notifycode,&lastrecord
Oncontrol seeds,FirstRecordButton,@notifycode,&firstrecord
Oncontrol seeds,RightButton,@notifycode,&goup
Oncontrol seeds,LeftButton,@notifycode,&godown
oncontrol seeds,quitbutton,@notifycode,&QuitProgram

CONTROLCMD seeds, NotesEdit, @EDSETLIMITTEXT, 450  'limits text len in notes to 500
ENABLETABS SEEDS, 1
SETFOCUS SEEDS,SeedNameEdit
gosub FirstOpen()
ENDSUB

SUB Seeds_handler
SELECT @MESSAGE
CASE @IDSIZE


case @idcontrol
select @controlid
case DTPICKSOWN
if @notifycode=@dtn_datetimechange
int day=*<NMDATETIMECHANGE>@lparam.st.wDay
int month=*<NMDATETIMECHANGE>@lparam.st.wMonth
int year=*<NMDATETIMECHANGE>@lparam.st.wYear
LongDate=getcontroltext(seeds,dtpicksown)
setcontroltext seeds,datesownedit, longdate
Endif


'CURRENTLY CANNOT HAVE MORE THAN ONE DTPICKERS..SOLVED.  needed to give new variables
'for day, month and year
case DTPICKGerm
if @notifycode=@dtn_datetimechange
int day2=*<NMDATETIMECHANGE>@lparam.st.wDay
int month2=*<NMDATETIMECHANGE>@lparam.st.wMonth
int year2=*<NMDATETIMECHANGE>@lparam.st.wYear
LongDate=getcontroltext(seeds,dtpickGerm)
setcontroltext seeds,dategermedit, longdate
Endif

case DTPICKHarvest
if @notifycode=@dtn_datetimechange
int day3=*<NMDATETIMECHANGE>@lparam.st.wDay
int month3=*<NMDATETIMECHANGE>@lparam.st.wMonth
int year3=*<NMDATETIMECHANGE>@lparam.st.wYear
LongDate=getcontroltext(seeds,dtpickHarvest)
setcontroltext seeds,dateHarvest, longdate
Endif
Endselect


ENDSELECT
RETURN FALSE
ENDSUB

SUB ProcessAll()
WAITUNTIL ISWINDOWCLOSED(Seeds)
ENDSUB

SUB OnMainClose(),INT

CLOSEWINDOW Seeds
RETURN FALSE
ENDSUB

'

SUB DoMnu_Seeds_menu12(),INT  'get garden diary program
'TODO: write handler code
system "gardendiary.exe"
RETURN FALSE
ENDSUB

SUB DoMnu_Seeds_menu16(),INT  'load the html seedlist
'TODO: write handler code
system "seeds2014.html"
RETURN FALSE
ENDSUB

SUB DoMnu_Seeds_menu17(),INT   'this will be the export records as delimited list
'TODO: write handler code
RETURN FALSE
ENDSUB

SUB DoMnu_Seeds_menu20(),INT  'this is quit
'TODO: write handler code
gosub quitprogram()
RETURN FALSE
ENDSUB



sub FirstRecord()

RECORDNUMBER$=""
ENABLECONTROL seeds,SaveButton,0


IF (OPENFILE(myfile,"SeedBase.txt","R") = 0)

GET myfile,1,SeedData  '
'find first record

SETCONTROLTEXT Seeds,SeedNameEdit,Seeddata.Seedname
SetcontrolText Seeds,SeedTypeEdit,Seeddata.SeedType
Setcontroltext Seeds,SupplierEdit,seeddata.SeedSupply
Setcontroltext Seeds,YearEdit,seeddata.YearNum
Setcontroltext Seeds,DateSownEdit,seeddata.DateSown
SETCONtroltext Seeds,DateGermEdit,seeddata.DateGerm
SETcontroltext Seeds,DateHarvest,seeddata.DateHarv
Setcontroltext Seeds,NotesEdit,seeddata.NoteText
Setcontroltext Seeds,RecordNumber,SEEDDATA.RECNUM

CLOSEFILE MYFILE
ENDIF


return false
endsub

sub LastRecord()
ENABLECONTROL seeds,SaveButton,0  'JUST SAVING AGAIN MANAGES TO SAVE THIS AS RECORD 1, NOT SURE WHY
IF OPENFILE(myfile,getstartpath+"SEEDBASE.txt","R") = 0
int num_records = len(myfile)/sizeof(SeedData)
for x=1 to num_records
GET myfile,x,SeedData
next x
'GET MYFILE,X-1,sEEDDATA 'SHOULD GET DATA FROM PENULTIMATE RECORD
CLOSEFILE myfile
endif
RecordNumber$=str$(x-1)
'PLACE NEW RECORD NUMBER IN THE RECORD NUMBER BOX
setcontroltext seeds,RecordNumber,RecordNumber$
SETCONTROLTEXT Seeds,SeedNameEdit,Seeddata.Seedname
SetcontrolText Seeds,SeedTypeEdit,Seeddata.SeedType
Setcontroltext Seeds,SupplierEdit,seeddata.SeedSupply
Setcontroltext Seeds,YearEdit,seeddata.YearNum
Setcontroltext Seeds,DateSownEdit,seeddata.DateSown
SETCONtroltext Seeds,DateGermEdit,seeddata.DateGerm
SETcontroltext Seeds,DateHarvest,seeddata.DateHarv
Setcontroltext Seeds,NotesEdit,seeddata.NoteText
'Setcontroltext Seeds,RecordNumber,SEEDDATA.RECNUM

return false
endsub

sub GoDown()
recordnumber$=(getcontroltext(seeds,RecordNumber)) 'get existing record number
count=val(RecordNumber$)  'works fine now after fixing corrupted records
if count>1
count=count-1 'increase by ONE
endif
If (openfile(myfile,"seedbase.txt","R")=0)  'open the file to READ
  get myfile,count,seeddata  'get all the data for this record number
SETCONTROLTEXT Seeds,SeedNameEdit,Seeddata.Seedname   'show all data on screen
SetcontrolText Seeds,SeedTypeEdit,Seeddata.SeedType
Setcontroltext Seeds,SupplierEdit,seeddata.SeedSupply
Setcontroltext Seeds,YearEdit,seeddata.YearNum
Setcontroltext Seeds,DateSownEdit,seeddata.DateSown
SETCONtroltext Seeds,DateGermEdit,seeddata.DateGerm
SETcontroltext Seeds,DateHarvest,seeddata.DateHarv
Setcontroltext Seeds,NotesEdit,seeddata.NoteText
Setcontroltext Seeds,RecordNumber,SEEDDATA.RECNUM
     endif
enablecontrol seeds,savebutton, 0  'disable save control to force update only
return false
endsub

sub GoUp()

recordnumber$=(getcontroltext(seeds,RecordNumber)) 'get existing record number
count=val(RecordNumber$)  'works fine now after fixing corrupted records
count=count+1 'increase by ONE
If (openfile(myfile,"seedbase.txt","R")=0)  'open the file to READ
  get myfile,count,seeddata  'get all the data for this record number
SETCONTROLTEXT Seeds,SeedNameEdit,Seeddata.Seedname   'show all data on screen
SetcontrolText Seeds,SeedTypeEdit,Seeddata.SeedType
Setcontroltext Seeds,SupplierEdit,seeddata.SeedSupply
Setcontroltext Seeds,YearEdit,seeddata.YearNum
Setcontroltext Seeds,DateSownEdit,seeddata.DateSown
SETCONtroltext Seeds,DateGermEdit,seeddata.DateGerm
SETcontroltext Seeds,DateHarvest,seeddata.DateHarv
Setcontroltext Seeds,NotesEdit,seeddata.NoteText
Setcontroltext Seeds,RecordNumber,SEEDDATA.RECNUM
     endif
enablecontrol seeds,savebutton, 0  'disable save control to force update only
return false
endsub

sub OpenNew()
YearNum=date$("yyyy")
setcontroltext seeds,YearEdit,YearNum

IF OPENFILE(myfile,getstartpath+"SeedBase.txt","R") = 0
int num_records = len(myfile)/sizeof(SeedData) 'length of file divided by size in bytes of reserved mem
for x=1 to num_records
GET myfile,x,SeedData  'note x will be the number of last record
next x
CLOSEFILE myfile
endif

RecordNumber$=str$(x)
count=x

SETCONTROLTEXT Seeds,SeedNameEdit,"" 
SetcontrolText Seeds,SeedTypeEdit,""
Setcontroltext Seeds,SupplierEdit,""
Setcontroltext Seeds,DateSownEdit,""
SETCONtroltext Seeds,DateGermEdit,""
SETcontroltext Seeds,DateHarvest,""
Setcontroltext Seeds,NotesEdit,"" 

Setcontroltext Seeds,RecordNumber,RecordNumber$ 'currently in absence of file gives v high no.
ENABLECONTROL seeds,SaveButton,1



return false
endsub

sub SaveFile  'this routine now works after difficult reacting with dialog box
'
if getcontroltext(seeds,seednameedit)<>""
SEEDDATA.Seedname=getcontroltext(seeds,seednameedit)
SEEDDATA.Seedtype=getcontroltext(seeds,seedtypeedit)
SEEDDATA.SeedSupply=getcontroltext(seeds,SupplierEdit)
SEEDDATA.YearNum=getcontroltext(seeds,YearEdit)
SEEDDATA.RecNum=Getcontroltext(seeds,RecordNumber)
SEEDDATA.DateSown=GetControlText(seeds,DateSownEdit)
SEEDDATA.DateGerm=GetControlText(seeds,DateGermEdit)
SEEDDATA.DateHarv=GetControlText(seeds,DateHarvest)
SEEDDATA.Notetext=GetControlText(seeds,NotesEdit)

count=val(Seeddata.RecNum)  'this is always 1.  Something to do with variable used. USING
'recordnumber$ instead of RecNum seems to sort it out.
RecordNumber$=seeddata.RecNum
setcontroltext seeds,RecordNumber,RecordNumber$
IF(OPENFILE(myfile,getstartpath+"SEEDBASE.txt","a") = 0)

PUT myfile,count,seeddata 'put the data into the file at date position and contents of type diary
closefile myfile
endif

recordnumber$=str$(count)  'need to change variable in this way
setcontroltext seeds,RecordNumber,RecordNumber$ 
ENABLECONTROL seeds,SaveButton,0 'disable save control to prevent new saves
endif
return false
endsub

sub SearchForName()
domodal d1  '
'NOTE you MUST use DOMODAL not ShowDialog if you want the window to wait until you close the dialog
SETFOCUS D1,EDIT_2 'WON'T WORK EITHER
searchname=getcontroltext(seeds,seednameEdit)


IF OPENFILE(myfile,getstartpath+"Seedbase.txt","R") = 0
int num_records = len(myfile)/sizeof(Seeddata) 'length of file divided by size in bytes of reserved mem
for x=1 to num_records
GET myfile,x,Seeddata  'note x will be the number of last record
if instr(ucase$(Seeddata.SeedName),ucase$(searchname))

breakfor 'breakout of for next loop if condition met
endif
next x

CLOSEFILE myfile
ENDIF
'RecordNumber$=str$(x) don't need this as just put the search on screen
SETCONTROLTEXT Seeds,SeedNameEdit,seeddata.Seedname   'show all data on screen
SetcontrolText Seeds,SeedTypeEdit,seeddata.SeedType
Setcontroltext Seeds,SupplierEdit,seeddata.SeedSupply
Setcontroltext Seeds,YearEdit,seeddata.YearNum
Setcontroltext Seeds,DateSownEdit,seeddata.DateSown
SETCONtroltext Seeds,DateGermEdit,seeddata.DateGerm
SETcontroltext Seeds,DateHarvest,seeddata.DateHarv
Setcontroltext Seeds,NotesEdit,seeddata.NoteText
Setcontroltext Seeds,RecordNumber,SEEDDATA.RECNUM

ENABLECONTROL Seeds,SaveButton,0


return false
endsub

sub SearchRecNum()
domodal d2

searchname=getcontroltext(seeds,RecordNumber)


IF OPENFILE(myfile,getstartpath+"Seedbase.txt","R") = 0
int num_records = len(myfile)/sizeof(Seeddata) 'length of file divided by size in bytes of reserved mem
for x=1 to num_records
GET myfile,x,Seeddata  'note x will be the number of last record
if instr(Seeddata.RecNum,searchname)

breakfor 'breakout of for next loop if condition met
endif
next x

CLOSEFILE myfile
ENDIF
'RecordNumber$=str$(x) don't need this as just put the search on screen
SETCONTROLTEXT Seeds,SeedNameEdit,seeddata.Seedname   'show all data on screen
SetcontrolText Seeds,SeedTypeEdit,seeddata.SeedType
Setcontroltext Seeds,SupplierEdit,seeddata.SeedSupply
Setcontroltext Seeds,YearEdit,seeddata.YearNum
Setcontroltext Seeds,DateSownEdit,seeddata.DateSown
SETCONtroltext Seeds,DateGermEdit,seeddata.DateGerm
SETcontroltext Seeds,DateHarvest,seeddata.DateHarv
Setcontroltext Seeds,NotesEdit,seeddata.NoteText
Setcontroltext Seeds,RecordNumber,SEEDDATA.RECNUM

ENABLECONTROL Seeds,SaveButton,0
  'endif

return false
endsub

sub UpDateFile()
SEEDDATA.Seedname=getcontroltext(seeds,seednameedit)
SEEDDATA.Seedtype=getcontroltext(seeds,seedtypeedit)
SEEDDATA.SeedSupply=getcontroltext(seeds,SupplierEdit)
SEEDDATA.YearNum=getcontroltext(seeds,YearEdit)
SEEDDATA.RecNum=Getcontroltext(seeds,RecordNumber)
SEEDDATA.DateSown=GetControlText(seeds,DateSownEdit)
SEEDDATA.DateGerm=GetControlText(seeds,DateGermEdit)
SEEDDATA.DateHarv=GetControlText(seeds,DateHarvest)
SEEDDATA.Notetext=GetControlText(seeds,NotesEdit)

count=val(seeddata.RecNum)


IF(OPENFILE(myfile,getstartpath+"SEEDBASE.txt","a") = 0)

PUT myfile,count,seeddata 'put the data into the file at date position and contents of type diary
closefile myfile
endif
return false
endsub

sub quitprogram
if messagebox (seeds,"Do you really want to quit?","Quit the program?",@MB_ICONEXCLAMATION|@mb_yesnocancel)=@idyes
closewindow seeds
endif
return false
endsub

sub FirstOpen()  'sub to open file and get first record
'THIS NOW WORKS FINE AND PICKS UP LAST RECORD NUMBER READY FOR NEW ENTRY

IF OPENFILE(myfile,getstartpath+"SEEDBASE.txt","R") = 0
int num_records = len(myfile)/sizeof(SeedData)
for x=1 to num_records
GET myfile,x,SeedData
next x
CLOSEFILE myfile
endif
RecordNumber$=str$(x)
'PLACE NEW RECORD NUMBER IN THE RECORD NUMBER BOX
setcontroltext seeds,RecordNumber,RecordNumber$


return false
endsub


One of the dialogs where I can't get the focus into the editbox (Searchname.iwb)

$include "globals.iwb"
$include "NewSeedDatabase.inc"




global SUB startsearchbox()



CREATEDIALOG d1,0,0,300,100,@CAPTION|@SYSMENU,0,"Search for Seed Name",&d1_handler
CONTROL d1,@STATIC,"Enter Seed Name",47,12,204,23,0x5000010B,STATIC_1
CONTROL d1,@EDIT,"",46,36,182,21,@CTEDITLEFT|@CTEDITAUTOH,EDIT_2
CONTROL d1,@BUTTON,"OK",185,72,70,20,0x50000000,BUTTON_3

ENDSUB

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
SETFONT d1,"Arial Black",12,400,0,STATIC_1
centerwindow d1
SETFOCUS D1,EDIT_2 'WILL NOT WORK!
ONMESSAGE d1,@IDCLOSEWINDOW,&closethisdialog
oncontrol d1,Button_3,@notifycode,&Getsearchtext

CASE @IDSIZE
CASE @IDCONTROL
SELECT @CONTROLID

ENDSELECT
ENDSELECT

RETURN FALSE
ENDSUB

sub getsearchtext
searchname=getcontroltext(d1,Edit_2)
if searchname=""
messagebox seeds,"You must type something into the search box","What do you want to search for?"
endif
setcontroltext seeds,seednameedit,searchname
gosub closethisdialog

return 0
endsub

sub closethisdialog
CLOSEDIALOG d1,@IDOK
return 0
endsub


The other dialog, seachnumber.iwb

$include "globals.iwb"
$include "NewSeedDatabase.inc"




global SUB numbersearch()




CREATEDIALOG d2,0,0,300,100,@CAPTION|@SYSMENU,0,"Search for Record Number",&d2_handler
CONTROL d2,@STATIC,"Enter Record Number",47,12,204,23,0x5000010B,STATIC_2
CONTROL d2,@EDIT,"",46,36,182,21,0x50800000,EDIT_3
CONTROL d2,@BUTTON,"OK",185,72,70,20,0x50000000,BUTTON_4

ENDSUB

SUB d2_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
SETFONT d2,"Arial Black",12,400,0,STATIC_2
centerwindow d2
ONMESSAGE d2,@IDCLOSEWINDOW,&closenumberdialog
oncontrol d2,Button_4,@notifycode,&Getnumbertext
SETFOCUS D2,EDIT_3
CASE @IDSIZE
CASE @IDCONTROL
SELECT @CONTROLID

ENDSELECT
ENDSELECT

RETURN FALSE
ENDSUB

sub getnumbertext
searchname=getcontroltext(d2,Edit_3)
if searchname=""
messagebox seeds,"You must type something into the record box","Which number do you want to search for?"
endif
setcontroltext seeds,RecordNumber,searchname
gosub closenumberdialog

return 0
endsub

sub closenumberdialog
CLOSEDIALOG d2,@IDOK
return 0
endsub
Adrian Fox

LarryMc

First FYI, next time just zip up the files and post them as an attachment.
That will save you and I both time by not having to copy/paste all the code.

The good news is easy solution.
The main problem you had was that even though you used DOMODAL your dialogs weren't modal.

The whole purpose of DOMODAL is to keep a user from being able to hide the dialog and cover it up with your main window

You created your two dialogs like this
CREATEDIALOG d1,0,0,300,100,@CAPTION|@SYSMENU,0,"Search for Seed Name",&d1_handler
CREATEDIALOG d2,0,0,300,100,@CAPTION|@SYSMENU,0,"Search for Record Number",&d2_handler

notice the 0 after |@SYSMENU; that means the dialogs were created without defining a parent window
If you define them that way(which is okay) and you want them to be modal when you call them then
you have to use this
domodal d1, seeds instead of like you used:domodal d1

In order to use this:domodal d1 like you did then you'd have to create your dialogs like this to be modalCREATEDIALOG d1,0,0,300,100,@CAPTION|@SYSMENU,seeds,"Search for Seed Name",&d1_handler
CREATEDIALOG d2,0,0,300,100,@CAPTION|@SYSMENU,seeds,"Search for Record Number",&d2_handler


As for the focus issue.
It seems like I've run into this focus issue before with modal dialogs.
All you have to do is add the @tabstop flag to the control you want to have initial focus and then make sure that control is the first one created with the @tapstop flag after the dialog is created.

Fix those things and you'll be in business
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

Many thanks Larry.  Yes that certainly gets everything working as I intended.  I hadn't appreciated that the @tabstop flag would influence the setting of focus in that way, but that alone made a difference. 

I have also changed my domodal commands in the way suggested to ensure the dialogs are truly modal, but that is an area I need to read a bit more about.

I spent some time looking more generally on the Internet about problems with setting focus in dialogs from the parent Window which had just got me thinking this was going to be a very complex solution, and then your reply came through! 

I will make sure I make a zip file of all my code next time rather than copy and pasting it. 

Thanks again for your time.  As my program has only a few finishing touches to go, I hope I won't need to bother you again too soon!   ;)
Adrian Fox