Welcome, Guest. Please login or register.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Columbo

Pages: [1] 2 3 ... 11
Database programming / Importing from a text file.
« on: May 09, 2019, 04:21:51 PM »
Here is a challenge!  I have a text file that contains a number of Meal-Master recipes.  What I need to do is read the file, grab the title, category, yield, ingredients and directions and assign them to variables which will then be written to a database.  In other words I want to import all of the recipes in the text file, one at a time, into a database.

Here is the first 2 recipes in the file to show an example of the Meal-Master format:

Code: [Select]

---------- Recipe via Meal-Master (tm) v8.02
 Categories: Meats
      Yield: 6 servings
      6 ea Thick pork chops
      1 x  Salt & red cayenne pepper
  1 1/2 c  Dry white wine
      1 c  Bell pepper, chopped
      1 c  Onions, chopped
      1 ea Clove garlic, chopped
      3 T  Soy sauce
      1 cn Pinapple chunks (15 oz.)
  Salt and red pepper the chops.  Brown them slowly in a skillet.
  Add wine, bell pepper, onion, and garlic,  Cover and simmer for
  25 to 30 minutes.  Remove pork chops, being sure to keep them warm.
  Add the soy sauce and syrup from the pineapple.  Stir and simmer
  until more or less thick.  Add the pineapple chunks and bring to
  a boil.  Serve over pork chops and hot cooked rice.
  From Justin Wilson's "Gourmet and Gourmand Cookbook"
---------- Recipe via Meal-Master (tm) v8.02
 Categories: Meats
      Yield: 8 servings
    1/2 c  Water
    1/4 c  Vinegar
      2 T  Dry mustard
      3 T  Brown sugar
      4 T  Chili sauce
      8 ea Pork chops
  Combine ingredients and mix well.  Pour over seasoned chops
  in glass baking dish, cover and bake at 400 F degrees for
  1-1/2 hours, uncovering last 30 minutes.  Water may be added
  to make gravy.  Delicious with ribs also. 

We know where each recipe begins because it starts with the following header line to indicate that it is the start of a Meal-Master recipe.
Code: [Select]
---------- Recipe via Meal-Master (tm) v8.02

The line with the 5 dashes (-----) indicates the end of that particular recipe.

I am trying to use ReadFile(#srcFile, srcFile)to read the text file a line at a time and While Eof(#srcFile) = 0 to look for the end of the file and fileLIne = Trim(ReadString(#srcFile)) to get the line read however, the problem is that I obviously do not want to save the header line, any blank lines, or the end of file marker, ď-----ď to the database. Also, the bigger problem is that the ingredients and the directions can have any number of lines which would have to be captured and written to the database.

The ingredients are preceded and followed by a blank line which Iím thinking I might be able to use to indicate the start and end of the ingredients.  The same idea for the directions.  Once the title, category, yield, ingredients and directions are assigned to variables and written to a database, it would then do the same thing again for each of the following recipes in the text file.  The database is recipes, the table is recipe and the columns are scat, recipe, ingredients, directions, serves which would be written to  category,  title, yield, ingredients and directions.

I have tried several ways to do this but I am unable to achieve the desired result.  I am able to get the title, category, and yield assigned to variables but I canít seem to come up with a way to get all of the lines in the ingredients and all of the lines in the directions saved to variables so that they can all be saved into the database.

Can someone give me an example of how best to achieve this?


General Discussion / Problem with AddKeyboardShortcut()
« on: May 07, 2019, 03:56:41 PM »
I'm having a problem getting my AddKeyboardShortcut() to work.  I want the user to be able to type a string into the StringGadget which is my #searchBox. This is the code that I used in the window setup:

Code: [Select]
wFlags = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget           ;Window flags
If OpenWindow(#MainWindow, 0, 0, 1280, 700, "", wFlags)     ;Open Main Window
  SetWindowColor(#MainWindow, RGB(255,255,255))
  AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Return, #kbdSearch)     ;Trap keyboard input

This is the StringGadget:

Code: [Select]

 Procedure setupscreenMain()
  ButtonImageGadget(#homeBtn, 250, 161, 99,30, ImageID(#img3))
  ButtonImageGadget(#categoriesBtn, 350, 161, 99,30, ImageID(#img5))
  ButtonImageGadget(#favouritesBtn, 450, 161, 99,30, ImageID(#img7))   
  ButtonImageGadget(#addBtn, 550, 161, 99,30, ImageID(#img9))
  ButtonImageGadget(#addCatBtn, 650, 161, 99,30, ImageID(#img30))
  ButtonImageGadget(#exitBtn, 750, 161, 99,30, ImageID(#img13))
  StringGadget(#searchBox,999, 51, 206, 25,"",#SS_CENTERIMAGE)     ; <---  The search box
  ButtonImageGadget(#searchBtn, 1212, 50, 37,26, ImageID(#searchBtn))
  SetGadgetFont(#searchBox, FontID(#searchFont))

And this is where I capture the event:

Code: [Select]

    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_Menu       
         Select EventMenu()
           Case #kbdSearch                   ;Check for keyboard event.
             If GetActiveGadget() = #searchBox   ;Check if searchBox box is being used.
                    SetGadgetText(#searchBox, "")          ;Clear the last search string from search box.
       Select EventWindow()     
        Case #MainWindow           ;If the event is from the MainWindow
          run = 1                  ;Set run flag to 1
              Case #PB_Event_Gadget
                Select EventGadget()

I used this same code in a previous program and it works fine.  In my current program, when I type a string into the StringGadget and press the enter key the program just quits.  Its like I had clicked the 'X' in the window.  I have placed debugs all the way through the steps and althoughy the searchString is correct, and the database finds the recipes, the Listview is not visible.  If I do a IsWindowVisible_(GadgetID(#LVsearch)) I get a 1 indicating that it is visible.

Any ideas?

General Discussion / Image hidden by other image
« on: May 04, 2019, 07:36:54 PM »
I have an ImageGadget placed on my screen and have disabled it.  I am now trying to place another smaller ImageGadget on top of it but it is always hidden behind the larger ImageGadget no matter where in the code I place the smaller ImageGadget.  How do you make the smaller ImageGadget the top most gadget?


General Discussion / My Recipe program for Syed
« on: May 03, 2019, 12:40:57 PM »
Hi Syed.

I played around with the program a bit today and I tried the CanvasGadget thing but I am really not familiar with that gadget and while I was able to place a CanvasGadget on the screen, I could not get it working properly.

Using the ImageGadget, I managed to be able to place the TextGadget on it and display the recipe of the day.  When you left click the TextGadget it invokes the getrecipe() procedure perfectly.  The problem now is that my category listview no longer populates.  If the ImageGadget and the TextGadget are not placed on the screen then the listviews all work properly.  I did a debug to check the database query in the populateCategoryList() and the result is 0 so it is not getting the listView items.  If I comment out the call to recipeoftheday() then the ListViews populate properly.  I have no idea as to what the connection is between the recipe database and the recipeoftheday() procedure.

Anyway, I have attached the .zip file with the program and all resources if you wish to look at it.


Database programming / Colorize text in a TextGadget
« on: July 20, 2017, 12:37:54 PM »
I am working on a program that pulls data from a SQLite database.  The program pulls source code from the database and places it into one of the TextGadgets in the program.  Is there a way to colorize the code that goes into this TextgGadget?


General Discussion / TABBING EditorGadgets
« on: April 16, 2017, 01:11:42 PM »
Hi Syed,

I have just tried to implement your code for TABBING EditorGadgets into my recent program but I am having a problem with it.  I copied example code and the only changes that I made to it is that, in your loops you are using For gadgetLoop = 1 To 3 since your example has 3 gadgets.  My program has 8 gadgets and I am using For gadgetLoop = #Function To #Seealso.  I also added the currentGadget to my Global variable list.

The problem I am having is that, while PB does not flag any errors, when my dataWindow comes up,  the labels are all there but there are no EditorGadgets visible.

Here is the relevant code I am using:

Code: [Select]

; TAB EditorGadgets
Procedure EditorProc(hWnd, uMsg, wParam, lParam)
  Shared sysProc, currentGadget
  If uMsg = #WM_CHAR And wParam = #VK_TAB
    currentGadget + 1
    If currentGadget > #Seealso
      currentGadget = #Function
    uMsg = 0
  ProcedureReturn CallWindowProc_(sysProc, hWnd, uMsg, wParam, lParam)

This is where I open the dataWindow

Code: [Select]

; Open dataWindow
  wFlags = #PB_Window_BorderLess | #PB_Window_ScreenCentered
 OpenWindow(#dataWindow, 0, 0, 1270, 700, "", wFlags)                   ;Open data Window
 SetWindowColor(#dataWindow, RGB(221,221,221))
 For x = #Function To #Seealso
   BindGadgetEvent(x, @textChange(), #PB_EventType_Change)
 Next x
 EditorProc(hWnd, uMsg, wParam, lParam)

And here is where I set up the dataScreen

Code: [Select]

; Setup Screen dataWindow
Procedure setupScreenDataWindow() 
  TextGadget(#headerData, 0, 0, 1270, 50, header, #SS_CENTERIMAGE)                ;Set up the DataWindow header
  SetGadgetFont(#headerData, FontID(#headerFont))                                 ;Set the DataWindow header font to Arial
  TextGadget(#footerData, 0, 650, 1270, 30, footer, #SS_CENTERIMAGE)              ;Set up the DataWindow footer
  SetGadgetFont(#footerData, FontID(#footerFont))                                 ;Set the DataWindow footer font to Arial
 For colorGadgets = #headerData To #footerData
    SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(0,84,166))             ;Set DataWindow header background color to Blue
    SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(235,235,235))         ;Set DataWindow header font color to light Grey 
     ButtonImageGadget(#nosubmitBtn, 750, 535, 74, 90, ImageID(#img4))   
     ButtonImageGadget(#submitBtn, 750, 535, 74, 90, ImageID(#img3))
     ButtonImageGadget(#changetableBtn, 925, 535, 74, 90, ImageID(#img5))
     ButtonImageGadget(#exitBtn, 1090, 535, 74, 90, ImageID(#img1))
     HideGadget(#submitBtn, #True)
  TextGadget(#labelFunction, 50,102,60,20, "Statement   : ")
  TextGadget(#labelSyntax, 50,142,60,20, "Syntax        : ")
  TextGadget(#labelDescription, 50,185,60,20, "Description : ")
  TextGadget(#labelParameters, 50,270,60,20, "Parameters : ")
  TextGadget(#labelReturnValue, 50,395,60,20, "Returns      : ")
  TextGadget(#labelRemarks, 50,490,60,20, "Remarks     : ")
  TextGadget(#labelExample, 635, 102, 55, 20, "Example   : ")
  TextGadget(#labelSeealso, 50,597,60,20, "See Also     : ")
  For colorGadgets = #labelFunction To #labelSeealso
    SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(221,221,221))          ;Set label background color to Blue
    SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(0,0,0))               ;Set label font color to light Grey 
  StringGadget(#Function, 120,100,480,20, "", #ES_MULTILINE | #ES_WANTRETURN) 
  StringGadget(#Syntax, 120,140,480,20, "", #ES_MULTILINE | #ES_WANTRETURN)
  StringGadget(#Description, 120,180,480,60, "", #ES_MULTILINE | #ES_WANTRETURN)
  EditorGadget(#Parameters, 120,265,480,100, #PB_Editor_WordWrap)    ;change to read only after data entry completed
  EditorGadget(#ReturnValue, 120,390,480,70, #PB_Editor_WordWrap)
  EditorGadget(#Remarks, 120,485,480,80, #PB_Editor_WordWrap)
  EditorGadget(#example, 700, 100, 540, 405, #PB_Editor_WordWrap)
  EditorGadget(#Seealso, 120,590,480,40, #PB_Editor_WordWrap)
  For colorGadgets = #Function To #Seealso
    SetGadgetColor(colorGadgets, #PB_Gadget_BackColor, RGB(245,245,245))          ;Set fields background color to white
    SetGadgetColor(colorGadgets, #PB_Gadget_FrontColor, RGB(0,0,0))               ;Set Gadgets font color to light Grey   
  For usefont = #Function To #Seealso
    SetGadgetFont(usefont, FontID(#editorFont))
  margin = 5
  SendMessage_(GadgetID(#Function), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#Function), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#Syntax), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#Syntax), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#Description), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#Description), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#Parameters), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#Parameters), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#ReturnValue), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#ReturnValue), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#Remarks), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#Remarks), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#example), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#example), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  SendMessage_(GadgetID(#Seealso), #EM_SETMARGINS, #EC_LEFTMARGIN, margin|0 << 16)
  SendMessage_(GadgetID(#Seealso), #EM_SETMARGINS, #EC_RIGHTMARGIN, 0|margin << 16)
  currentGadget = #Function
  For gadgetLoop = #Function To #Seealso
    sysProc = SetWindowLongPtr_(GadgetID(gadgetLoop),#GWL_WNDPROC, @EditorProc())
  Next gadgetLoop

Any suggestions?



Here is version 2 of my Prehistoric Life Database program.  The screen is slightly larger than version 1 and instead of using  two separate image gadgets for the picture and the size comparison I used a panel gadget.  Saves space and looks a little more neat.

The database is attached as a .zip file.

General Discussion / How to have header & footer fit window?
« on: April 02, 2017, 10:48:35 AM »
In my program I have a header and a footer, which I created by using a TextGadget, and setting the backgound color to grey and setting the text to be displayed. I did the same for the footer. The header height is 50px and the footer height is 30px. The window size is set to 1200px wide and 625px high which, purposely, does not fill the screen. If I click the Maximize button on the window the window maximizes but the header and footer size does not expand the width to fit the maximized window.   How would I resolve this issue?

General Discussion / Using a PanelGadget to display images
« on: March 11, 2017, 12:41:48 PM »
I have created a PanelGadget with 2 panels. Rather than displaying some kind of text in each panel I want to display an image. I am not talking about putting an icon in the panel tab, I want to display a 300x150 .jpg image in each panel. What would be the easiest way to do that?


Database programming / Not writing to database table
« on: March 05, 2017, 11:04:00 PM »
I have a table in my database called projects and I am trying to write to that table but for some reason it is not doing so.
I am using code that I have used in some of my other programs and it works in those programs but not here.
The fields in the table are "category", "title", "instructions" and "code"

Here is the code that I am using to write to the table.

Code: [Select]

 Procedure AddToDatabase()
   cat = GetGadgetText(#recCategory)
   title = GetGadgetText(#recTitle)
   instructions = GetGadgetText(#recInstructions)
   code = GetGadgetText(#recCode)

   cmd$ = "INSERT INTO projects VALUES('"+ cat +"', '"+ title +"', '"+ instructions +"', '"+ code +"' );"
   result = DatabaseUpdate(#dbaseID, cmd$)

If I debug the variables cat, title, instructions and code, they are all ok.  The only thing that is different from other programs where I have used this code is that the "instructions" and "code" fields are MEMO fields but it seems to me that it should still be able to insert the data into them.

Any thoughts?

General Discussion / Select All
« on: March 04, 2017, 12:01:30 PM »
I have a field in my program that contains a fairly large amount of code. What I would like is to have a text that says "Select All" and when someone clicks on the text it selects all of the code in that field so that it can be copied. 

Actually, it would probably be better if it not only selected the code but copied it to the clipboard as well.  Is this possible and if so,... Does anybody have a piece of example code?


General Discussion / Hold contents of a Memo field
« on: March 01, 2017, 04:21:40 PM »
In my current project I need to display the contents of a couple of Memo fields in a DB.  I remember, in a previous project, I used an EditorGadget() to display the content.  The EditorGadget() was good in that it had scroll bars so it took up less space in the window but the problem with the EditorGadget() is that you have to define the number of characters that it will hold and, in this current project, the number of characters can range from very few, 30 or 40, to very many, (thousands). If Purebasic allocates memory for this, it seems like a waste to create an EditorGadget() for 6 or 7 thousand characters when it might only need 30 or 40 characters from a database table.

Any thoughts on this issue?

General Discussion / Lost for a while
« on: March 01, 2017, 03:50:05 PM »
I have not been on the site for some time due to health issues for my wife.  While these issues remain, they are hopefully under control, so I am finally getting started back into Purebasic again and I should be on the site from here on in. Sorry for being MIA.


Database programming / How to check if Database is open
« on: April 15, 2016, 11:00:43 AM »
Is there a way to check if a database is already open before using it?


General Discussion / Just an update on my Video POS program.
« on: February 15, 2016, 12:38:17 PM »
Just an update on my Video POS program.  Its coming along quite well so far.  I have the staff module and the customer membership module pretty much complete and now I have to start on the Inventory and rental tracking modules.  Still a lot of work left to do but it has been fun and a great learning experience as well.


Pages: [1] 2 3 ... 11