Hi,
This program was originally started by three young kids as a school project.
Next year they will do a lot of project work at school, and they wanted to make their own lightweight tool for collecting and storing information as text files for later editing and printing.
But when they ran into big coding problems, they felt that they were wasting time, and started all over with another approach. Instead of the original combination of ComboBox/ListBox to organise and list their projects and files, they now decided to use menues and traditional folder and file browsers to find and open their files.
The problems they had with their first attempt were solved by LarryMc. But at that time they had put so much effort into their second attempt, that their teacher decided they should stick to the new code.
But in my opinion, their first idea was much better approach for keeping an overview of their files. So I decided to add some code to their first attempt, to make the program work as intended.
I have populated the datacollection with copies of a few examples from the old IBasic Std Code Archive. The program is far from finished, but works good enough for demonstrating the original idea.
Any suggestions for added functionality and changes will be much appreciated.
The attached archive contains an EXE-version plus the contents described above.
Have fun!
Egil.
Also see: http://www.ionicwind.com/forums/index.php?topic=5998.0 (http://www.ionicwind.com/forums/index.php?topic=5998.0)
'
'-------------------------------------------------------------------------------------
' CB_MockUp.cba
'-------------------------------------------------------------------------------------
AutoDefine "Off"
'--------------------------------------------------
' Defines for catching ENTER key in edit controls:
'--------------------------------------------------
SETID "ENMKEYEVENTS",0x10000
SETID "ENMSGFILTER",0x700
TYPE MSGFILTER
def hwndFrom:INT
def idFrom:INT
def code:INT
def msg:INT
def wparam:INT
def lparam:INT
ENDTYPE
DEF mf:MSGFILTER
DEF mem:MEMORY
'*********************************
DECLARE "kernel32.dll",Sleep(dwMilliseconds:INT)
DECLARE AddProject(wnd:window, projectname:string, ID:int)
DECLARE ListProjects(wnd:window,ID:int)
DECLARE AddItem(wnd:window,path:string,itemname:string)
DECLARE ListItems(wnd:window,projectname:string,ID:int)
DECLARE SaveItem(wnd:window,fname:string,ID:int)
DECLARE LoadItem(wnd:window,fname:string,ID:int)
DECLARE RemoveCR()
def LB_RESETCONTENT:int
CONST LB_RESETCONTENT = 0x184
DEF answer:INT
def wstyle:int
wstyle = @SIZE|@MINBOX|@MAXBOX
def win:window
def cleft,ctop,cwidth,cheight:int :'Clientarea
def run,pcount,ret,lpos:int
def itempath,selecteditem,newitem,olditem,selectedproject,newproject,oldproject:string
def buffer[32766]:ISTRING
selecteditem = ""
' Menu defines
'-----------------------------
def t1,t2,t3,t4,t5:string
t1 = "I,Save Item,0,100"
t2 = "I,Print Item,1,101"
t3 = "I,Delete Item,0,102"
t4 = "I,Delete Project,1,103"
t5 = "I,Exit Program,0,199"
'-----------------------------
Window win,-640,0,680,480,wstyle,0," CB MockUp",MainLoop
GETCLIENTSIZE win,cleft,ctop,cwidth,cheight
SETWINDOWCOLOR win,RGB(121,150,222)
drawmode win,@TRANSPARENT
'-------------------------------------------------------------------------------------
' SETTING UP
'-------------------------------------------------------------------------------------
RECT win,11,11,518,56, RGB(32,32,32),RGB(240,216,126)
RECT win,10,10,518,56, RGB(96,96,96),RGB(240,216,126)
CONTROL win,"M,Select,16,35,160,202,@CTCOMBODROPDOWN|@VSCROLL,11" :' ComboBox Control
SETCONTROLTEXT win,11,"Select:"
CONTROL win,"L,,3,73,160,cheight-(10+67),@CTLISTNOTIFY,12" :' ListBox Control
CONTROL win,"E,,166,72,cwidth-169,cheight-(10+65),@CTEDITMULTI|@CTEDITRETURN|@VSCROLL,13" :' Edit Control
RECT win,190,35,158,23,0,RGB(102,102,102) :' Make fake EDIT Control appearance
RECT win,191,36,158,23,0,RGB(255,255,255) :' Make fake EDIT Control appearance
CONTROL win,"RE,proj,193,38,150,18,@CTEDITLEFT,14"
CONTROLCMD win,14,@RTSETEVENTMASK,@ENMKEYEVENTS
RECT win,362,35,158,23,0,RGB(102,102,102) :' Make fake EDIT Control appearance
RECT win,363,36,158,23,0,RGB(255,255,255) :' Make fake EDIT Control appearance
CONTROL win,"RE,item,365,38,150,18,@CTEDITLEFT,15"
CONTROLCMD win,15,@RTSETEVENTMASK,@ENMKEYEVENTS
SETFONT win,"Ariel",12,700
FRONTPEN win,RGB(121,150,222)
move win,50,16
print win,"PROJECT"
move win,225,16
print win,"NEW ITEM"
move win,380,16
print win,"NEW PROJECT"
CONTROL win,"B,,540,15,47,47,@CTLBTNBITMAP,16"
SETCONTROLTEXT win,16,GETSTARTPATH + "tools.bmp"
CONTROL win,"B,,600,15,47,47,@CTLBTNBITMAP,17"
SETCONTROLTEXT win,17,GETSTARTPATH + "info.bmp"
CREATEDIR(GETSTARTPATH + "PROJECTS") :' Creates Projectfolder if not found
ListProjects(win,11)
run = 1
WAITUNTIL run = 0
CLOSEWINDOW win
END
'
SUB MainLoop()
'-------------------------------------------------------------------------------------
' Main Loop
'-------------------------------------------------------------------------------------
'
DEF key:int
SELECT @CLASS
CASE @IDSIZE :' Has Window size has been changed?
GETCLIENTSIZE win,cleft,ctop,cwidth,cheight :' Retreive new window size
if CONTROLEXISTS(win,12) then SETSIZE win,3,73,160,cheight-(10+67),12 :' Resize ListBox Control
if CONTROLEXISTS(win,13) then SETSIZE win,166,72,cwidth-169,cheight-(10+65),13 :' Resize Edit Control
CASE @IDCONTROL
SELECT @CONTROLID
case 11
if @NOTIFYCODE = @CBNSELCHANGE
selectedproject = GETSTRING (win, 11,GETSELECTED (win,11))
if selectedproject <> oldproject
SendMessage(win,LB_RESETCONTENT,0,0,12)
oldproject = selectedproject
ListItems(win,selectedproject,12)
buffer = ""
setcontroltext win,13,buffer
endif
endif
case 12 :' load selected file
if @NOTIFYCODE = @LBNSELCHANGE
itempath = GETSTARTPATH + "PROJECTS\" + selectedproject + "\"
selecteditem = itempath + GETSTRING(win,12,GETSELECTED(win,12))
LoadItem(win,selecteditem ,13)
endif
'case 13 :' check for changes in EditControl
case 14 :' New Item is Entered
IF @NOTIFYCODE = @ENMSGFILTER
'read in the MSGFILTER structure
mem = @QUAL
READMEM mem,1,mf
'at this point the keyboard event
'is in mf.msg and the keyboard code is in mf.wparam
'the event can be things like @IDCHAR
IF mf.msg = @IDCHAR
key = mf.wparam
IF (key = 13) :' ENTER KEY PRESSED
selectedproject = GETCONTROLTEXT(win,11)
newitem = GETCONTROLTEXT(win,14)
if newitem <> ""
itempath = GETSTARTPATH + "PROJECTS\" + selectedproject + "\"
AddItem(win,itempath,newitem)
ADDSTRING win,12,newitem + ".txt"
SETCONTROLTEXT(win,14,"")
newitem = ""
SETFOCUS win,14 :' Send focus back to the window
endif
ENDIF
ENDIF
ENDIF
case 15 :' New project is entered
IF @NOTIFYCODE = @ENMSGFILTER
'read in the MSGFILTER structure
mem = @QUAL
READMEM mem,1,mf
'at this point the keyboard event
'is in mf.msg and the keyboard code is in mf.wparam
'the event can be things like @IDCHAR
IF mf.msg = @IDCHAR
key = mf.wparam
IF (key = 13) :' ENTER KEY PRESSED
newproject = GETCONTROLTEXT(win,15)
if newproject<>"" then AddProject(win,newproject,11)
SETCONTROLTEXT(win,15,"")
pcount = GETSTRINGCOUNT(win,11)
SETSELECTED win,11,pcount-1
'SETFOCUS win :' Send focus back to the window
oldproject = newproject
newproject = ""
endif
ENDIF
ENDIF
ENDIF
case 16
CONTEXTMENU win,500,65,t1,t2,t3,t4,t5
case 17
system GETSTARTPATH + "info.txt"
ENDSELECT
CASE @IDMENUPICK
SELECT @MENUNUM
case 100
SaveItem(win,selecteditem,13)
' case 101
case 102
lpos = GETSELECTED (win,12)
DELETEFILE(selecteditem)
DELETESTRING win, 12, lpos
' case 103
' case 104
case 199
run = 0
ENDSELECT
CASE @IDCREATE
CENTERWINDOW win
CASE @IDCLOSEWINDOW
FREEMEM mem
run = 0
ENDSELECT
RETURN
'-------------------------------------------------------------------------------------
'
SUB ListProjects(wnd:window,ID:int)
'-------------------------------------------------------------------------------------
' Find existing project folders and add them to ComboBox list
'-------------------------------------------------------------------------------------
DEF dir:INT
DEF fname:STRING
def fdir:string
fdir = "PROJECTS\"
dir = FINDOPEN(GETSTARTPATH + fdir + "*.*")
IF(dir)
DO
fname = FINDNEXT(dir)
if (fname <> ".") & (fname <> "..") &(fname <> "")
if CONTROLEXISTS(wnd,ID) then ADDSTRING wnd,ID,fname
endif
UNTIL fname = ""
FINDCLOSE dir
ENDIF
WAIT 1 :' Whithout this line, program sometimes crashes
RETURN
'
SUB AddProject(wnd:window, projectname:string, ID:int)
'-------------------------------------------------------------------------------------
' Create new project
'-------------------------------------------------------------------------------------
DEF err:int
err = CREATEDIR(GETSTARTPATH + "PROJECTS\" + projectname)
if (err=1) & CONTROLEXISTS(wnd,ID)
ADDSTRING wnd,ID,projectname
else
if err = 0 then MessageBox(wnd,"Project already exists!", "",0x30)
endif
WAIT 1 :' Whithout this line, program sometimes crashes
RETURN
'
SUB AddItem(wnd:window,path:string,itemname:string)
'-------------------------------------------------------------------------------------
' Creates new, empty, Item File for editing later
'-------------------------------------------------------------------------------------
DEF myfile:FILE
'DEF err:int
DEF myfilename:string
myfilename = path + itemname + ".txt"
IF(OPENFILE(myfile,myfilename,"W") = 0)
WRITE myfile,"EMPTY "
CLOSEFILE myfile
ELSE
MessageBox(wnd, "Could not create file","WARNING!",0x30)
ENDIF
RETURN
'
SUB ListItems(wnd:window,projectname:string,ID:int)
'-------------------------------------------------------------------------------------
' List items in selected project in ListBox Control
'-------------------------------------------------------------------------------------
DEF dir:INT
DEF fname:STRING
def fdir:string
fdir = "PROJECTS\" + projectname + "\"
dir = FINDOPEN(GETSTARTPATH + fdir + "*.*")
IF(dir)
DO
fname = FINDNEXT(dir)
if (fname <> ".") & (fname <> "..") &(fname <> "")
if CONTROLEXISTS(wnd,ID) then ADDSTRING wnd,ID,fname
endif
UNTIL fname = ""
FINDCLOSE dir
ENDIF
WAIT 1 :' Whithout this line, program sometimes crashes
RETURN
'
SUB LoadItem(wnd:window,fname:string,ID:int)
'-------------------------------------------------------------------------------------
' Load selected Item into Edit Control
'-------------------------------------------------------------------------------------
DEF filh:FILE
def ln:string
if(len(fname) > 0)
buffer = ""
if( openfile(filh,fname,"R") = 0)
do
if(read(filh,ln) = 0)
if(len(ln) <> 0)
buffer = buffer + ln + chr$(13) + chr$(10)
endif
endif
until eof(filh)
closefile filh
setcontroltext wnd,ID,buffer
endif
endif
RETURN
'
SUB SaveItem(wnd:window,fname:string,ID:int)
'-------------------------------------------------------------------------------------
' List items in selected project in ListBox Control
'-------------------------------------------------------------------------------------
DEF filh:FILE
def buffer2[32766]:ISTRING
if(openfile(filh,fname,"W") = 0)
buffer2 = getcontroltext(wnd,ID)
REM EDIT controls insert extra carriage returns at in every line
REM so remove them before saving
RemoveCR
write filh,buffer2
closefile filh
endif
endif
RETURN
'
SUB RemoveCR()
'-------------------------------------------------------------------------------------
' Remove carriage returns
'-------------------------------------------------------------------------------------
def pos:INT
def buffer2[32766]:ISTRING
pos = INSTR(buffer,CHR$(13))
while(pos)
if(mid$(buffer,pos,1) = CHR$(13))
buffer2 = left$(buffer,pos-1)
buffer2 = buffer2 + mid$(buffer,pos+1)
buffer = buffer2
endif
pos = INSTR(pos+1,buffer,chr$(13))
endwhile
RETURN
The boys now have finished their school coding project, and I have translated all norwegian texts and menues to english. The result really impress me. They are only 11 years old. Full source code, a working EXE file, User Guide and Project notes are all included in the zip archive.
Let's hope these guys stick to CB also in the future!
Have fun!
Egil.
Tell those young men I said "nice job".
That's great work!
Suggestions:
On selecting an existing project, you could copy each item text file to a backup copy i.e.
Item1.txt to Item1.bac
Item2.txt to Item2.bac
On exit, you could get them to read each matching txt and bac file, i.e. Item1.txt and Item1.bac into two ISTRINGS.
You could then compare the two strings to see if there is a difference - if there is (on exit) save and delete the bac files.
Also, you could add in a timer - here you could also do the above, and also check that each txt file has a corresponding bac file - if not, it's an addition - so you could save it automatically, and then create a new bac file for the new txt file.
Just a couple of ideas, it would introduce them to strings longer than 255 characters, how to compare strings and reading simple files.
Just thoughts - anyway great job! :)
Great ideas for them to expanded upon it over the summer Andy.
Thanks guys!
I will pass all your comments to them on tuesday when they have returned from a school trip to Trondheim. Think they'll be proud.
This was the third time I have been helping out with the coding course at the local school. It has been very rewarding.
I have been giving them a lot of examples of what I have been working on myself, and explained why I did it in that specific way. Only a short glance on their source code reveals that they've adapted to my way of coding. 8) ;D
It's almost scary to see how fast these kids adapt to new information. And when explaining examples I know I would have had problems to understand myself at their age. I have been wondering where they get their enthusiasm from...
In addition, they have all kinds of ideas for what they want to do next, and how to do it. Some ideas so neat that I'm tempted to have a go myself.
We already have discussed how the program can be improved. And they are thinking very much the same way as Andy. But instead of a timer, they talked about controlling program behaviour with "flags".
I have told them that whatever they do, they have to make their source code in such a way that they will understand what they have done if they read the same code again in a couple of months. And they could have put more comments into it. But still I think they have done a good job.
Regards,
Egil
EDIT:
@Andy:
If my memory serves me right, the RE Controls already have a built in routine for checking if the contents have been changed or edited. Maybe they can use that method?
Just my two cents worth. On a change, I would set a flag. On exit you could have, "Would you like to save your changes?". With a backup file (or multiple backup files) they could revert to an earlier version.
Later,
Clint
Egil,
I think it's a good idea to let people learn how to do things the hard (long way round) first before replying on a built in function.
You learn so much more that way and learn to appreciate what these functions are actually doing for you.
:)
Quote from: ckoehn on June 01, 2017, 05:09:40 AM
Just my two cents worth. On a change, I would set a flag. On exit you could have, "Would you like to save your changes?". With a backup file (or multiple backup files) they could revert to an earlier version.
Later,
Clint
Great idea Clint!
thanks
Egil
Quote from: Andy on June 01, 2017, 06:44:09 AM
Egil,
I think it's a good idea to let people learn how to do things the hard (long way round) first before replying on a built in function.
You learn so much more that way and learn to appreciate what these functions are actually doing for you.
:)
Maybe you are right. I'll try to make them use that method first, and if they want to experiment, they can try the built-in function, just to see the difference.
Egil
In Norway we use potatoes for most every hot meal. Therefore we have a saying "It is like a patato, we can use it for mosteverything".
I think these young boys just made such a potato. I modified their code (whithout clelaning up things not needed), and "stole" one of the icons built into cbasix.exe to make a new bmp-file.
The result is a simple snippet manager for CB. Just try, and see what happens when the CB button is pressed....
Egil
P.S.
I did not make an exe file for this, as you will need CB anyway.
8)