Here is the program code: The code raising the error is in the Procedure setupScreen()
Code: Select all
;---------------------------------------------
; Prehistoric Life - Version 2.0
; Author: J. Coones - PBLabs
; March 22, 2017
;--------------------------------------------
;---------------------------------------------------------
; Initialize the database & Image plugins
;---------------------------------------------------------
UseSQLiteDatabase()
UseJPEGImageDecoder()
UseGIFImageDecoder()
;------------------------------------
; Set up constants
;------------------------------------
Enumeration MainWindow
; Windows
#MainWindow
EndEnumeration
Enumeration Databases 100
;Databases
#dbaseID
EndEnumeration
Enumeration FormGadgets 200
; Buttons
#searchBtn
#getRecBtn
#prevBtn
#nextBtn
#exitBtn
EndEnumeration
Enumeration LabelGadgets 300
; Labels
#header
#footer
#labelName
#labelMeaning
#labelPronounce
#labelPeriod
#labelGroup
#labelSize
#labelLived
#labelDiet
#labelFossils
#labelFactfile
#labelPicture
#labelCompare
EndEnumeration
Enumeration TextGadgets 400
;Text Boxes
#name
#meaning
#pronounce
#period
#group
#size
#lived
#diet
#fossils
#factFile
#title
;Edit Box
#search
EndEnumeration
Enumeration Images 500
; Images
#img0
#img1
#img2
#img3
#img4
#img5
#headerImg
#footerimg
#titlebarimg
#searchIcon
EndEnumeration
Enumeration Other 700
; Miscellaneous
#headerFont
#footerFont
#titleFont
#kbdSearch
#RecNo
EndEnumeration
#SS_CENTERIMAGE=512 ;Used to vertically align text in a TextGadget
;#EC_LEFTMARGIN = 1 ;Used similar to cellspacing for left margin in an EditorGadget
;EC_RIGHTMARGIN = 2 ;Used similar to cellspacing for right margin in an EditorGadget
;#EM_SETMARGINS =179 ;Was 211
;-----------------------------------
; Global Variables
;-----------------------------------
Global recno.l = 1
Global startpath.s = ""
Global path.s
Global imagePath1.s
Global imagePath2.s
Global imagePath3.s
Global imagePath4.s
Global imagePath5.s
Global iconPath.s
Global dbselected.s
Global filename1.s
Global filename2.s
Global maxRec.l
Global searchIcon
Global searchString.s
Global winWidth = 1280
Global winHeight = 700
Global headerwidth = 1280
Global headerheight = 50
Global footerwidth = 1280
Global footerheight = 30
Global newWidth
Global newHeight
Global footerY = 670
Global change = 0
Global resW.s
Global resH.s
Global resChange = 0
Global header$ = Chr(13) + " Prehistoric Life"
Global footer$ = " Information on prehistoric life from its beginning up to the appearance of man."
Procedure checkRes()
ExamineDesktops()
resW = Str(DesktopWidth(0))
resH = Str(DesktopHeight(0))
If resW <> Str(1280)
resChange = 1
#DM_BITSPERPEL=$40000
#DM_PELSWIDTH=$80000
#DM_PELSHEIGHT=$100000
res.DEVMODE
res\dmSize=SizeOf(DEVMODE)
res\dmBitsPerPel=32
res\dmPelsWidth=1280
res\dmPelsHeight=720
res\dmDisplayFrequency=60
res\dmFields=#DM_BITSPERPEL|#DM_PELSWIDTH|#DM_PELSHEIGHT
ChangeDisplaySettings_(@res.DEVMODE,0)
EndIf
EndProcedure
;<-------[ Load Font ]------------->
LoadFont(#headerFont, "Arial", 14)
LoadFont(#footerFont, "Arial", 9)
boldFont=LoadFont(#PB_Any, "Arial", 14, #PB_Font_Bold)
LoadFont(#titleFont, "Arial", 10, #PB_Font_Bold)
Procedure getSearchIcon()
path$ = GetPathPart(ProgramFilename())
iconPath = path$ + "images\search-icon.gif"
LoadImage(#img0, iconPath)
;LoadImage(#searchIcon,iconPath)
;imgID = ImageID(#img0)
ButtonImageGadget(#searchIcon, 1145, 193, 20, 20, ImageID(#img0))
EndProcedure
; -----------------[ Display Images ]-----------------
Procedure displayImages()
filename1 = dbselected
filename2 = dbselected
path = GetPathPart(ProgramFilename())
imagePath1 = path + "dino_images\" + filename1 + ".jpg"
imagePath2 = path + "dinosize\" + filename2 + "_size" + ".jpg"
LoadImage(1,imagePath1)
LoadImage(2,imagePath2)
PanelGadget(10, 885, 240, 355, 280)
AddGadgetItem(10, -1, "Dinosaur Picture", 0)
ImageGadget(1, 15, 10, 425, 260, ImageID(1))
AddGadgetItem(10, -1, "Size Comaprison", 0)
ImageGadget(2, 15, 10, 425, 260, ImageID(2))
CloseGadgetList()
SetGadgetState(1, ImageID(1))
SetGadgetState(2, ImageID(2))
EndProcedure
; -----------------[ Search and Display Record ]-----------------
Procedure displayData(searchString.s)
; Routine To see if name contains any spaces
getString.s = LCase(Trim(GetGadgetText(#search))) ;Get the string value in the #Search box.
Length.l = Len(getString) ;Get the length of the name string
chnum = 0 ;variable to hold number of characters in name
For i = 1 To length ;Loop through the name looking for spaces
ch.s = Mid(getString, i, 1)
If ch = " " ;If a space is encountered then...
chnum = i ;assign the character number to chnum
EndIf
Next
;Routine to change the first character of searchString to upper case
rightnum = length - chnum
rightside.s = Right(getString, rightnum)
rightcap.s = UCase(Left(rightside, 1)) ; Change first Character of first word to Upper case
rightnum = rightnum - 1
rightside.s = Right(getString, rightnum)
rightString.s = rightcap + rightside
leftside.s = Left(getstring, chnum)
resultr.s = UCase(Left(leftside, 1)) ; Change first Character second word to Upper case
chnum = chnum - 1
resultl.s = LCase(Right(leftside, chnum))
leftString.s = resultr + resultl
searchString.s = leftString + rightString ;join right string & left string
If DatabaseQuery(#dbaseID,"SELECT * FROM dino WHERE name = '"+ searchString +"'")
While NextDatabaseRow(#dbaseID)
SetGadgetText(#RecNo, GetDatabaseString(#dbaseID, dbColumn)) ;Display record number in RecNo box.
recNum.s = GetDatabaseString(#dbaseID, dbColumn) ;Get the current record number
recno = Val(recNum) ;Set reno to current record number.
If recno = maxRec
DisableGadget(#nextBtn, 1) ;If at the last record then disable the 'Next' button.
Else
DisableGadget(#nextBtn, 0) ;Else enable the 'Next' button.
EndIf
If recno = 1
DisableGadget(#prevBtn, 1) ;If at the first record then disable the 'Prev' button.
Else
DisableGadget(#prevBtn, 0) ;Else enable the 'Prev' button.
EndIf
dbColumn +1 ;Move to the next field in the database.
spacer.s = Space(2)
For populate = #Name To #FactFile ;Fill in the fields with the corresponding data
If populate = #FactFile
spacer = ""
EndIf
SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
If dbcolumn = 1
dbselected = GetDatabaseString(#dbaseID, dbColumn) ;Get the name of the dino to load images.
EndIf
dbColumn + 1 ;Increment the column
Next
displayImages() ;Get and display the associated images.
FinishDatabaseQuery(#dbaseID) ;Disconnect from database but does not close it.
Wend
EndIf
SetGadgetText(#search, "") ;Clear the last search string from search box.
EndProcedure
; -----------------[ Get Database Record & Display it ]-----------------
Procedure getRecord(recno)
If DatabaseQuery(#dbaseID,"SELECT * FROM dino WHERE record = '"+ recno +"'") ;Find the record
While NextDatabaseRow(#dbaseID) ;Start loop to go through fields.
SetGadgetText(#RecNo, GetDatabaseString(#dbaseID, dbColumn)) ;Display record number in RecNo box.
dbColumn + 1 ;Move to the next field in the database.
spacer.s = Space(2)
For populate = #Name To #FactFile ;Fill in the fields with the corresponding data
If populate = #FactFile
spacer = ""
EndIf
SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
SendMessage_(GadgetID(#FactFile), #EM_SCROLL, #SB_TOP, 0) ; Froce scrollbar to top of page.
If dbColumn = 1 ;Check to see if we are in the 'Name' field.
dbselected = GetDatabaseString(#dbaseID, dbColumn) ;Get the dino's name from the name field.
EndIf
dbColumn + 1 ;Move to the next column.
Next
If recno = maxRec ; See if we are at the last record.
DisableGadget(#nextBtn, 1) ;If at the last record then disable the 'Next' button.
Else
DisableGadget(#nextBtn, 0) ;If not at last record then enable the 'Next' button.
EndIf
If recno = 1
DisableGadget(#prevBtn, 1) ;If at the fisrt record then disable the 'Prev' button.
Else
DisableGadget(#prevBtn, 0) ;If not at first record then enable the 'Prev' button.
EndIf
displayImages() ;Get and display the associated images.
FinishDatabaseQuery(#dbaseID) ;Disconnect from database but does not close it.
Wend ; End of loop
EndIf
SetActiveGadget(#Search)
EndProcedure
; -----------------[ Setup Screen]-----------------; Procedure to set up Main GUI
;---------------------------------------------
Procedure setupScreen()
path$ = GetPathPart(ProgramFilename())
imagePath3 = path$ + "images\header.jpg"
LoadImage(#img3,imagePath3)
ImageGadget(#headerimg,0, 28,1280,190,ImageID(#Img3))
DisableGadget(#headerimg,1)
;----------------{ Setup Labels ]----------------
TextGadget(#labelName, 90, 235, 45, 20, "Name : ")
TextGadget(#labelMeaning, 80, 282, 50, 20, "Meaning : ")
TextGadget(#labelPronounce, 50, 335, 85, 20, "Pronounciation : ")
TextGadget(#labelPeriod, 92, 383, 50, 20, "Period : ")
TextGadget(#labelGroup, 68, 433, 70, 20, "Main Group : ")
TextGadget(#labelSize, 103, 484, 30, 20, "Size : ")
TextGadget(#labelLived, 98, 533, 40, 20, "Lived : ")
TextGadget(#labelDiet, 105, 582, 30, 20, "Diet : ")
TextGadget(#labelFossils, 95, 628, 50, 20, "Fossils : ")
TextGadget(#labelFactfile, 585, 657, 55, 20, "Fact File")
For colorGadgets = #labelName To #labelFactFile
SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(226,222,214)) ;May need changing
SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(62, 34, 7))
Next
;---------------{ Setup Data Fields ]-----------------
TextGadget(#name, 145, 232, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#meaning, 145, 280, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#pronounce, 145, 332, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#period, 145, 381, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#group, 145, 430, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#size, 145, 480, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#lived, 145, 530, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#diet, 145, 578, 202, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
TextGadget(#fossils, 145, 628, 200, 20, "", #PB_Text_Border | #SS_CENTERIMAGE)
EditorGadget(#FactFile, 375, 230, 480, 420, #PB_Editor_WordWrap | #PB_Editor_ReadOnly)
boldFont=LoadFont(#PB_Any, "Arial", 10)
SetGadgetFont(#FactFile, FontID(boldFont))
margin = 15
With editArea.RECT
\left = margin
\top = margin
\right = GadgetWidth(#Factfile) - margin
\bottom = GadgetHeight(#Factfile) - margin
EndWith
margin = 10
SendMessage_(GadgetID(#Factfile), #EM_SETRECT, 0, editArea)
;-----------------[ Setup Search Box & Record Number Box ]---------------
StringGadget(#search, 985, 193, 150, 20, "", #SS_CENTERIMAGE) ;Search Box (At top right of screen)
StringGadget(#RecNo, 1036, 540, 70, 20, "", #SS_CENTERIMAGE) ; Get Record Box (above the Prev and Next buttons)
For colorGadgets = #name To #FactFile
SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(212,208,203))
SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(44,23,3))
Next
SetActiveGadget(#Search)
;---{ Setup Buttons ]---
ButtonGadget(#getRecBtn, 1036, 570, 71, 20, "Get Record")
ButtonGadget(#prevBtn, 1000, 605, 60, 20, "Prev")
ButtonGadget(#nextBtn, 1090, 605, 60, 20, "Next")
ButtonGadget(#exitBtn, 1048, 640, 60, 20, "Exit")
imagePath4 = path$ + "images\footer.jpg"
LoadImage(#img4,imagePath4)
ImageGadget(#footerimg, 0, 692, 1280, 30, ImageID(#Img4)) ;Was 650
DisableGadget(#footerimg,1)
imagePath5 = path$ + "images\titlebar.jpg"
LoadImage(#img5,imagePath5)
ImageGadget(#titlebarimg, 0, 0, 1280, 30, ImageID(#Img5))
DisableGadget(#titlebarimg,1)
EndProcedure
;-----------------[ Search Routine ]---------------
Procedure searchRecord()
searchString = GetGadgetText(#search)
; Routine To see if name contains any spaces
getString.s = LCase(Trim(GetGadgetText(#search))) ;Get the string value in the #Search box.
Length.l = Len(getString) ;Get the length of the name string
chnum = 0 ;variable to hold number of characters in name
For i = 1 To length ;Loop through the name looking for spaces
ch.s = Mid(getString, i, 1)
If ch = " " ;If a space is encountered then...
chnum = i ;assign the character number to chnum
EndIf
Next
;Routine to change the first character of searchString to upper case
rightnum = length - chnum
rightside.s = Right(getString, rightnum)
rightcap.s = UCase(Left(rightside, 1)) ; Change first Character of first word to Upper case
rightnum = rightnum - 1
rightside.s = Right(getString, rightnum)
rightString.s = rightcap + rightside
leftside.s = Left(getstring, chnum)
resultr.s = UCase(Left(leftside, 1)) ; Change first Character second word to Upper case
chnum = chnum - 1
resultl.s = LCase(Right(leftside, chnum))
leftString.s = resultr + resultl
searchString.s = leftString + rightString ;join right string & left string
result = DatabaseQuery(#dbaseID, "SELECT * FROM dino WHERE name LIKE '%" + searchString + "%'") ;try to find the search string
While NextDatabaseRow(#dbaseID)
SetGadgetText(#RecNo, GetDatabaseString(#dbaseID, dbColumn)) ;Display record number in RecNo box.
recNum.s = GetDatabaseString(#dbaseID, dbColumn) ;Get the current record number
recno = Val(recNum) ;Set reno to current record number.
If recno = maxRec
DisableGadget(#nextBtn, 1) ;If at the last record then disable the 'Next' button.
Else
DisableGadget(#nextBtn, 0) ;Else enable the 'Next' button.
EndIf
If recno = 1
DisableGadget(#prevBtn, 1) ;If at the first record then disable the 'Prev' button.
Else
DisableGadget(#prevBtn, 0) ;Else enable the 'Prev' button.
EndIf
dbColumn +1 ;Move to the next field in the database.
spacer.s = Space(2)
For populate = #Name To #FactFile ;Fill in the fields with the corresponding data
If populate = #FactFile
spacer = ""
EndIf
SetGadgetText(populate, spacer + GetDatabaseString(#dbaseID, dbColumn))
If dbcolumn = 1
dbselected = GetDatabaseString(#dbaseID, dbColumn) ;Get the name of the dino to load images.
EndIf
dbColumn + 1 ;Increment the column
Next
displayImages() ;Get and display the associated images.
FinishDatabaseQuery(#dbaseID) ;Disconnect from database but does not close it.
Wend
SetGadgetText(#search, "") ;Clear the last search string from search box.
SetActiveGadget(#Search)
EndProcedure
;-------------------[ Open the database & Main Window ]--------------------
If OpenDatabase(#dbaseID, "dinobase.db", "", "") ;Open the database
DatabaseQuery(#dbaseID, "SELECT count(*) FROM dino") ;Get the number of records in database
NextDatabaseRow(#dbaseID) ;Move to the next record.
maxRec = Val(GetDatabaseString(#dbaseID, 0)) ;Give maxRec the number of the last record
;wFlags = #PB_Window_BorderLess | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_Maximize ;Window flags
wFlags = #PB_Window_BorderLess | #PB_Window_Maximize ;Window flags
OpenWindow(#MainWindow, 0, 0, 1280, 678, "Prehistoric Life", wFlags) ;Open GUI Was at 678
SetWindowColor(#MainWindow, RGB(226,222,213))
AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Return, #kbdSearch) ;Trap keyboard input
;checkRes()
setupScreen() ;Setup the main screen.
getSearchIcon() ;Get the icon for the search button.
getRecord(recno) ;Display the first record on startup.
;--------------------------------------
; Wait for window event
;--------------------------------------
Repeat
Select WaitWindowEvent() ;Wait for an event
Case #PB_Event_CloseWindow ;Close window if "X" is clicked.
run = 1 ;Set run flag to 1
Case #PB_Event_MaximizeWindow
; setHeaderFooterSize()
;ResizeGadget(#header, 0, 0, headerWidth, headerHeight)
;ResizeGadget(#footer, 0, footerY, footerWidth, footerHeight)
Case #PB_Event_RestoreWindow
; setHeaderFooterSize()
;ResizeGadget(#header, 0, 0, headerWidth, headerHeight)
;ResizeGadget(#footer, 0, footerY, footerWidth, footerHeight)
Case #PB_Event_Menu
Select EventMenu()
Case #kbdSearch ;Check for keyboard event.
If GetActiveGadget() = #RecNo ;Check if RecNo box is being used.
recno = Val(Trim(GetGadgetText(#RecNo))) ;Get the number user entered into RecNo box.
ElseIf GetActiveGadget() = #search ;See if the search box is being used.
searchRecord()
EndIf
EndSelect
Case #PB_Event_Gadget ;Check for gadget event
Select EventGadget()
Case #searchIcon
; dbselected = GetGadgetText(#search)
displayimages()
; displayData(LCase(Trim(GetGadgetText(#Search))))
searchRecord()
Case #nextBtn ;If the 'Next' button is pressed, get the next record
recno + 1 ;Increase record number by 1.
getRecord(recno)
Case #prevBtn ;If the 'Prev' button is pressed, get the previous record
recno - 1 ;Reduce record number by 1.
getRecord(recno) ;Find the record in database and display it.
Case #getRecBtn
recno = Val(Trim(GetGadgetText(#RecNo))) ;Get number from RecNo box.
getRecord(recno)
Case #exitBtn ;Close window If "Exit" button is pressed.
run = 1 ;Set run flag to 1
EndSelect
EndSelect
Until run = 1 ;If run = 1 close the program.
CloseDatabase(#dbaseID) ;close the database.
;If resChange = 1
;#DM_BITSPERPEL=$40000
;#DM_PELSWIDTH=$80000
;#DM_PELSHEIGHT=$100000
;res.DEVMODE
;res\dmSize=SizeOf(DEVMODE)
;res\dmBitsPerPel=32
;res\dmPelsWidth=Val(resW)
;res\dmPelsHeight=Val(resH)
;res\dmDisplayFrequency=60
;res\dmFields=#DM_BITSPERPEL|#DM_PELSWIDTH|#DM_PELSHEIGHT
;ChangeDisplaySettings_(@res.DEVMODE,0)
;EndIf
EndIf