Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 103
» Latest member: LarrySaalmans
» Forum threads: 62
» Forum posts: 411

Full Statistics

Latest Threads
gbNotes (Discussion)
Forum: PowerBASIC for Windows
Last Post: Stuart McLachlan
4 minutes ago
» Replies: 4
» Views: 47
gbThreads
Forum: PowerBASIC for Windows
Last Post: Stuart McLachlan
3 hours ago
» Replies: 13
» Views: 251
The Future
Forum: Suggestions and discussion about PUMP
Last Post: Stuart McLachlan
3 hours ago
» Replies: 3
» Views: 51
gbNotes
Forum: Source Code Library
Last Post: Gary Beene
6 hours ago
» Replies: 0
» Views: 29
gbLocator
Forum: Source Code Library
Last Post: Mike Doty
Yesterday, 07:28 AM
» Replies: 4
» Views: 85
Getting Current UTC
Forum: PowerBASIC for Windows
Last Post: Stuart McLachlan
Yesterday, 06:05 AM
» Replies: 14
» Views: 1,454
Clockwise sort of coordin...
Forum: Programming
Last Post: Torkel M. Jodalen
09-02-2025, 09:14 AM
» Replies: 3
» Views: 141
Pac-Man maze
Forum: Programming
Last Post: Jules Marchildon
09-01-2025, 11:01 PM
» Replies: 9
» Views: 263
High resolution replaceme...
Forum: Source Code Library
Last Post: David Roberts
09-01-2025, 10:33 PM
» Replies: 0
» Views: 67
If you want to get to the...
Forum: Suggestions and discussion about PUMP
Last Post: Albert Richheimer
09-01-2025, 04:53 PM
» Replies: 0
» Views: 112

 
  gbNotes (Discussion)
Posted by: Gary Beene - 6 hours ago - Forum: PowerBASIC for Windows - Replies (4)

I was going to wait about posting gbNotes until I added more features, but I've gotten distracted and probably won't touch it again for a while.  But since I use it daily I thought it ought to be good enough to share.

Link to Source Code Forum

The "database" is just a text file that uses "++++" as a delimiter between entries.

The first line of each entry is just a user name.  Any number of lines can added after that.

On the left is a search term editor, a list of the most search terms and a list of the most recent search matches.  Click on a match to see and edit the content.  Ctrl+D will insert a date line into the editor, below which you can enter new content.

Each day, it does a backup of the CRM.txt file into a "backup" folder.

You can also view/edit/search the entire CRM.txt file

There's not much more to it.  Simple, but good enough to let me track my contacts.

[Image: gbnotes.png]

Print this item

  gbNotes
Posted by: Gary Beene - 6 hours ago - Forum: Source Code Library - No Replies

A while back I asked about CRM app recommendations. Not having found something as simple as I wanted, I wrote my own and have been using it the last couple of months. 

I still have a list of changes I want to make to it, but since I've been using for a while now, I guess it's worth offering up to anyone who wants it.

Discussion:  
Source Code:  https://garybeene.com/files/gbnotes.zip

[Image: gbnotes.png]


Code:
'Compilable Example:
#Compile Exe  "gbnotes.exe"
#Dim All
%Unicode = 1
#Include "Win32API.inc"

$Ver = "1.0"
$Delim = "++++"

#Resource Icon xlogo, "n.ico"
#Resource Icon xsave, "save.ico"
#Resource Icon xnew, "new.ico"
#Resource Icon xdelete, "delete.ico"
#Resource Icon xsearch, "search.ico"
#Resource Icon xall, "all.ico"
#Resource Icon xsaveall, "saveall.ico"
#Resource Icon xplus, "listplus.ico"
#Resource Icon xup, "searchup.ico"
#Resource Icon xdown, "searchdown.ico"
#Resource Icon xexit, "exit.ico"

%MultiLineREStyle_Wrap    = %WS_Child Or %WS_ClipSiblings Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or _
                            %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop Or %ES_SaveSel

Enum Equates Singular
   IDC_ComboBox = 500
   IDC_ListView
   IDC_RichEdit
   IDC_Toolbar
   IDC_StatusBar
   IDT_SaveCFN
   IDT_New
   IDT_Delete
   IDT_Search
   IDT_InsertDelimiter
   IDT_ShowAll
   IDT_AllContacts
   IDT_SaveAll
'   IDT_Sort
   IDT_Exit
   IDT_Mute
   IDT_InsertDate
   IDT_SetFocusRE
   IDT_SearchUP
   IDT_SearchDown
   IDT_NextREDown
   IDT_PrevREUp

   IDC_InputTextBox
   IDC_InputOk
   IDC_InputCancel

End Enum

Global hDlg, hRichEdit, hListView, hComboBox, hList, hDlgI As Dword
Global D() As String, REText$, SearchTerm$, SearchTerms$
Global RESearchTerm As WStringZ * 100
Global SearchDirection, BackupNumber, CFN, iSkip, Maximized, Minimized, Mute As Long

Function PBMain() As Long

   Dialog Default Font "Arial Black", 16,1
   Dialog New Pixels, 0, "gbNotes " + $Ver,,,800,800, %WS_OverlappedWindow To hDlg
   Dialog Set Icon hDlg, "xlogo"

   Control Add ComboBox, hDlg, %IDC_ComboBox,, 10,10,400,200, %CBS_Simple Or %CBS_NoIntegralHeight Or %WS_VScroll Or %WS_TabStop, %WS_Ex_ClientEdge
   Control Handle hDlg, %IDC_ComboBox To hComboBox

   Control Add ListView, hDlg, %IDC_ListView, "",10,40,400,400, %WS_TabStop Or %LVS_Report Or %LVS_ShowSelAlways Or %LVS_SingleSel, %WS_Ex_ClientEdge
   ListView Insert Column hDlg, %IDC_ListView, 1,"All Contacts",400,0
   ListView Insert Column hDlg, %IDC_ListView, 2,"Position",150,0
   Control Handle hDlg, %IDC_ListView To hListView

   LoadLibrary("msftedit.dll")
   Control Add "RichEdit50W", hDlg, %IDC_RichEdit, "", 410,10,400,400, %MultiLineREStyle_Wrap, %WS_Ex_ClientEdge
   Control Handle hDlg, %IDC_RichEdit To hRichEdit
   SendMessage hDlg, %EM_SetEventMask, 0, %ENM_SelChange
   SendMessage hRichEdit, %EM_SetEventMask, 0, %ENM_SelChange Or %ENM_Link
   SendMessage hRichEdit, %EM_AUTOURLDETECT, %True, 0

   Control Add Toolbar, hDlg, %IDC_Toolbar, "", 0,0,0,0,%CCS_NoMoveY
   ImageList New Icon 32,32,32,10 To hList
   ImageList Add Icon hList, "xsearch"  '1
   ImageList Add Icon hList, "xsave"    '2
   ImageList Add Icon hList, "xnew"     '3
   ImageList Add Icon hList, "xdelete"  '4
   ImageList Add Icon hList, "xall"     '5
   ImageList Add Icon hList, "xsaveall" '6
   ImageList Add Icon hList, "xplus"    '7
   ImageList Add Icon hList, "xexit"    '8
   ImageList Add Icon hList, "xup"      '9
   ImageList Add Icon hList, "xdown"    '10

   Toolbar Set ImageList hDlg, %IDC_Toolbar, hList, 0
   Toolbar Add Button hDlg, %IDC_Toolbar, 8, %IDT_Exit, %TbStyle_Button, "Exit"
   Toolbar Add Button hDlg, %IDC_Toolbar, 5, %IDT_AllContacts, %TbStyle_Button, "All"
   Toolbar Add Button hDlg, %IDC_Toolbar, 2, %IDT_SaveCFN, %TbStyle_Button, "Save"
   Toolbar Add Button hDlg, %IDC_Toolbar, 3, %IDT_New, %TbStyle_Button, "New"
   Toolbar Add Button hDlg, %IDC_Toolbar, 4, %IDT_Delete, %TbStyle_Button, "Delete"

   Toolbar Add Separator hDlg, %IDC_Toolbar, 50

   Toolbar Add Button hDlg, %IDC_Toolbar, 5, %IDT_ShowAll, %TbStyle_Button, "Show All"
   Toolbar Add Separator hDlg, %IDC_Toolbar, 10
   Toolbar Add Button hDlg, %IDC_Toolbar, 6, %IDT_SaveAll, %TbStyle_Button, "Save All"
   Toolbar Add Button hDlg, %IDC_Toolbar, 10, %IDT_SearchUp, %TbStyle_Button, "Up"
   Toolbar Add Button hDlg, %IDC_Toolbar, 9, %IDT_SearchDown, %TbStyle_Button, "Down"

   Control Add Statusbar, hDlg, %IDC_StatusBar, "Welcome to gbNotes!", 0,0,0,90

   Dialog Show Modal hDlg Call DlgProc
End Function

CallBack Function DlgProc() As Long
   Local pNMLV As NMListView Ptr, iRow As Long, temp$
   Select Case Cb.Msg
      Case %WM_InitDialog
         If IsFalse IsFolder("backup") Then MkDir "backup"
         Settings_INI "get"
         BuildAcceleratorTable

         LoadCRMFile       'create D() from CRM.txt
         DisplayCRMArray   'put D() into LV

         LoadComboBox
         Control Set Text hDlg, %IDC_ComboBox, SearchTerm$

         If Maximized Then Dialog Show State hDlg, %SW_Maximize  'restore Maximized state if necessary
         If Minimized Then Dialog Show State hDlg, %SW_Minimize       'restore Maximized state if necessary

         Control Set Text hDlg, %IDC_RichEdit, D(CFN)
         ListView Select hDlg, %IDC_ListView, CFN
         ListView_SetItemState hListView, CFN-1, %LVIS_Focused, %LVIS_Focused  '<--- keyboard synchronizing code
         ListView Visible hDlg, %IDC_ListView, CFN

      Case %WM_Size : Resize

      Case %WM_Command
         Select Case Cb.Ctl
'            Case %IdCancel : Dialog End hDlg
            Case %IdOk 'Enter Key
               If GetParent(GetFocus) = hComboBox Then
                  sBeep
                  Control Get Text hDlg, %IDC_ComboBox To SearchTerm$
                  Search
                  AddSearchTerm
               End If
            Case %IDC_ComboBox
               Select Case Cb.CtlMsg
                  Case %CBN_SelChange
                     'get post-selection text
                     Control Send hDlg, %IDC_ComboBox, %CB_GetCurSel, 0, 0 To iRow
                     ComboBox Get Text hDlg, %IDC_ComboBox, iRow+1 To SearchTerm$
                     Dialog Set Text hDlg, "SearchTerm = " + SearchTerm$  + "   " + Time$
                     Search
               End Select
            Case %IDT_Exit       : sBeep : Dialog End hDlg
            Case %IDT_SaveCFN    : sBeep : SaveCFN          : ST Trim$(Parse$(D(CFN),$CrLf,1)) + " saved"
            Case %IDT_New        : NewCFN                   : ST "New Contact"
            Case %IDT_Delete     : sBeep : DeleteCFN        : ST ""
            Case %IDT_Search     : sBeep : Control Get Text hDlg, %IDC_ComboBox To SearchTerm$ : Search  'ST
            Case %IDT_InsertDate : sBeep : InsertDate       : ST ""
            Case %IDT_InsertDelimiter : sBeep : InsertDelimiter : ST ""
            Case %IDT_ShowAll    : sBeep : ShowAll          : ST "All CRM.txt Loaded in Editor"
            Case %IDT_SaveAll    : sBeep : SaveAll          : ST "Editor Content saved to crm.txt"
'            Case %IDT_Sort       : sBeep : SortData
            Case %IDT_Mute       : WinBeep(275,150) : Mute Xor=1 : ST "Mute is " + IIf$(Mute,"ON","OFF")
            Case %IDT_SetFocusRE : SetFocus hRichEdit
            Case %IDT_SearchDown     : SearchDirection = 1 : FindRE : ST ""
            Case %IDT_SearchUp       : SearchDirection = 0 : FindRE
            Case %IDT_NextREDown     : sBeep : SearchDirection = 1 :    SearchText RESearchTerm, %FR_Down
            Case %IDT_AllContacts    : DisplayCRMArray

         End Select
      Case %WM_Notify
         Select Case Cb.NmId
            Case %IDC_RichEdit
               Select Case Cb.NmCode
                  Case %EN_Link : OpenLink(Cb.LParam)
               End Select
            Case %IDC_ListView
               Select Case Cb.NmCode
                  Case %LVN_ItemChanged  '%NM_Click
                     pNMLV = Cb.LParam
                     If (@pNMLV.uChanged And %LVIF_STATE) = %LVIF_STATE Then  ' if state has changed
                         If (@pNMLV.unewstate And %LVIS_SELECTED) = %LVIS_SELECTED Then
                            ListView Get Select hDlg, %IDC_ListView To iRow
                            ListView Get Text hDlg, %IDC_Listview, iRow, 2 To temp$
                            CFN = Val(temp$)
                            Control Set Text hDlg, %IDC_RichEdit, D(CFN)
                            sBeep
                         End If
                     End If
               End Select
         End Select
      Case %WM_Destroy
         SaveBackup
         Settings_INI "save"

   End Select
End Function

Sub Resize
   Local x,y,w,h,wc,hc,wt,ht As Long
   Control Get Size hDlg, %IDC_Toolbar To wt,ht
   Dialog Get Client hDlg To w,h

   Control Set Loc hDlg, %IDC_ComboBox, 10,ht+10
   Control Get Size hDlg, %IDC_ComboBox To wc,hc

   Control Set Loc hDlg, %IDC_ListView, 10,ht+hc+20
   Control Set Size hDlg, %IDC_ListView, 400, h-ht-hc-30-40

   Control Set Loc hDlg, %IDC_RichEdit, wc+15,ht+10
   Control Set Size hDlg, %IDC_RichEdit, w-wc-25,h-ht-30-30

End Sub

Function OpenLink(ByVal lpLink As Dword) As Long
   Local enlinkPtr As ENLINK Ptr, linkText As String, iReturn As Long
   Control Get Text hDlg, %IDC_RichEdit To REText$
   enlinkPtr  = lpLink
   If @enLinkPtr.Msg = %WM_LButtonUp Then
      LinkText = Mid$(REText$,@enLinkPtr.chrg.cpMin+1 To @enLinkPtr.chrg.cpMax)
      LinkText = Remove$(LinkText, Any $Cr+$Lf+$Spc)
      iReturn  = ShellExecute(hDlg, "Open", (LinkText), $Nul, $Nul, %SW_ShowNormal)
   End If
End Function

Sub LoadComboBox
   Local temp$, i As Long
   Open "searchterms.txt" For Binary As #1 : Get$ #1, Lof(1), SearchTerms$ : Close #1
   SearchTerms$ = Trim$(SearchTerms$, Any $CrLf + $Spc)

   ComboBox Reset hDlg, %IDC_ComboBox
   Control Set Text hDlg, %IDC_ComboBox, SearchTerm$

   For i = 1 To Min(5,ParseCount(searchterms$,$CrLf))
      ComboBox Insert hDlg, %IDC_ComboBox, i, Parse$(SearchTerms$,$CrLf,i)
   Next i
End Sub

Sub LoadCRMFile
   Local tmp$, temp$, i,iCount As Long
   Open "crm.txt" For Binary As #1 : Get$ #1, Lof(1), temp$ : Close #1
   iCount = ParseCount(temp$, $Delim)
   ReDim D(1 To iCount)
   Parse temp$, D(), $Delim
   For i = 1 To iCount
      D(i) = Trim$(D(i), Any $CrLf + $Spc)
      tmp$ = Parse$(D(i),$CrLf,1)
      If Trim$(tmp$) = "" Then ? "Data Issue:" + $CrLf + D(i-1)
   Next i

   ST "Records: " + Format$(iCount,"##,###")
End Sub

Sub DisplayCRMArray
   Local temp$, i As Long
   ListView Reset hDlg, %IDC_ListView
   For i = 1 To UBound(D)
      D(i) = Trim$(D(i))
      ListView Insert Item hDlg, %IDC_ListView, i,0,Parse$(D(i),$CrLf,1)
      ListView Set Text hDlg, %IDC_ListView, i,2,Format$(i)
   Next i
End Sub

Sub Search
   Local temp$, i,iCount As Long

   ListView Reset hDlg, %IDC_ListView
   For i = 1 To UBound(D)
      If InStr(LCase$(D(i)), LCase$(SearchTerm$)) Then
         Incr iCount
         ListView Insert Item hDlg, %IDC_ListView, iCount, 0, Parse$(D(i),$CrLf,1)
         ListView Set Text hDlg, %IDC_ListView, iCount, 2, Format$(i)
      End If
   Next i

   ListView Select hDlg, %IDC_ListView, 1
   ListView_SetItemState hListView, 0, %LVIS_Focused, %LVIS_Focused  '<--- keyboard synchronizing code
   ListView Set Header hDlg, %IDC_ListView, 1, "Matches: " + Format$(iCount) + "   " + $Dq + SearchTerm$ + $Dq
End Sub

Sub Settings_INI(Task$)
   Local x,y,w,h, tempz, INIFileName As WStringZ * %Max_Path, WinPla As WindowPlacement

   'set ini filename
   INIFileName = Exe.Path$ + Exe.Name$ + ".ini"    'get INI file name

   Select Case Task$
      Case "get"
         'get dialog width/height from INI file and use to set Dialog size
         GetPrivateProfileString "All", "Width", "800", w, %Max_Path, INIFileName
         GetPrivateProfileString "All", "Height", "800", h, %Max_Path, INIFileName
         Dialog Set Size hDlg,Val(w), Val(h)   'width/height

         'get dialog top/left from INI file and use to set Dialog location
         Getprivateprofilestring "All", "Left", "0", x, %Max_Path, INIFileName
         Getprivateprofilestring "All", "Top", "0",  y,  %Max_Path, INIFileName
         If IsFile(INIFileName) Then Dialog Set Loc hDlg, Val(x), Val(y)   'left/top but only once INIFileName exists

         'get value for string variables
         GetPrivateProfileString "All", "RESearchTerm", "TWC", RESearchTerm, %Max_Path, INIFileName

         'get value for numeric variables
         Getprivateprofilestring "All", "Minimized", "0", tempz, %Max_Path, INIFileName   : Minimized = Val(tempz)
         Getprivateprofilestring "All", "Maximized", "0", tempz, %Max_Path, INIFileName   : Maximized = Val(tempz)
         Getprivateprofilestring "All", "CFN", "1",       tempz, %Max_Path, INIFileName   : CFN = Val(tempz)
         Getprivateprofilestring "All", "Mute", "0",      tempz, %Max_Path, INIFileName   : Mute = Val(tempz)
         Getprivateprofilestring "All", "BackupNumber", "0",      tempz, %Max_Path, INIFileName   : BackupNumber = Val(tempz)

      Case "save"
         If IsFile(INIFileName) Then Kill INIFileName    'clear the INI file Name to remove residual entries before saving
         WinPla.Length = SizeOf(WinPla)
         GetWindowPlacement hDlg, WinPla
         WritePrivateProfileString "All", "Left", Str$(WinPla.rcNormalPosition.nLeft), INIFileName
         WritePrivateProfileString "All", "Top", Str$(WinPla.rcNormalPosition.nTop), INIFileName
         WritePrivateProfileString "All", "Width", Str$(WinPla.rcNormalPosition.nRight - WinPla.rcNormalPosition.nLeft), INIFileName
         WritePrivateProfileString "All", "Height", Str$(WinPla.rcNormalPosition.nBottom - WinPla.rcNormalPosition.nTop), INIFileName

         'save string variables
         WritePrivateProfileString "All", "RESearchTerm", RESearchTerm, INIFileName

         'save numeric variables
         Minimized = IsIconic(hDlg)
         Maximized = IsZoomed(hDlg)
         WritePrivateProfileString "All", "Minimized", Str$(Minimized), INIFileName
         WritePrivateProfileString "All", "Maximized", Str$(Maximized), INIFileName
         WritePrivateProfileString "All", "CFN", Str$(CFN), INIFileName
         WritePrivateProfileString "All", "Mute", Str$(Mute), INIFileName
         WritePrivateProfileString "All", "BackupNumber", Str$(BackupNumber), INIFileName

   End Select
End Sub

Sub SaveCFN
   Local temp$
   Control Get Text hDlg, %IDC_RichEdit To temp$

   If InStr(temp$, $Delim) Then ? "Cannot Save!" : Exit Sub

   D(CFN) = temp$
   Open "crm.txt" For Output As #1 : Print #1, Join$(D(), $CrLf + $Delim + $CrLf); : Close #1
   ListView Set Text hDlg, %IDC_ListView, CFN, 1, Parse$(D(CFN),$CrLf,1)
   SetFocus hRichEdit
End Sub

Sub ShowAll
   Control Set Text hDlg, %IDC_RichEdit, Join$(D(),$CrLf + $Delim + $CrLf)
   SendMessage hRichEdit, %EM_SetSel, 0, 0
   SetFocus hRichEdit
End Sub

Sub SaveAll
   Local temp$
   If MsgBox("Update All CRM Data?", %MB_YesNo Or %MB_IconQuestion Or %MB_TaskModal, "Update CRM") = %IdYes Then
      Control Get Text hDlg, %IDC_RichEdit To temp$
      temp$ = Trim$(temp$, Any $CrLf + " +")
      Open "crm.txt" For Output As #1
      Print #1, temp$;
      Close #1

      LoadCRMFile       'create D() from CRM.txt
      DisplayCRMArray   'put D() into LV

   End If
End Sub

Sub sBeep
   If Mute Then Exit Sub
   WinBeep(275,150)
End Sub

Sub BuildAcceleratorTable
   Local ac() As ACCELAPI, hAccelerator As Dword, c As Long  ' for keyboard accelator table values
   Dim ac(10)
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_Delete : ac(c).cmd = %IDT_Delete          : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_D : ac(c).cmd = %IDT_InsertDate        : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_E : ac(c).cmd = %IDT_ShowAll           : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_F : ac(c).cmd = %IDT_SearchDown        : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_I : ac(c).cmd = %IDT_InsertDelimiter   : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_R : ac(c).cmd = %IDT_SetFocusRE        : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_M : ac(c).cmd = %IDT_Mute              : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_N : ac(c).cmd = %IDT_NextREDown        : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key   = %VK_S : ac(c).cmd = %IDT_SaveCFN           : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL Or %FSHIFT : ac(c).key = %VK_F : ac(c).cmd = %IDT_SearchUp : Incr c
   ac(c).fvirt = %FVIRTKEY Or %FCONTROL Or %FSHIFT : ac(c).key = %VK_S : ac(c).cmd = %IDT_SaveAll  : Incr c
   Accel Attach hDlg, AC() To hAccelerator
End Sub

Sub InsertDelimiter
   Clipboard Reset
   Clipboard Set Text $CrLf + $Delim + $CrLf + $CrLf
   SendMessage hRichEdit, %WM_Paste, 0, 0
End Sub

Sub InsertDate
   Clipboard Reset
   Clipboard Set Text $CrLf + "Discussion: " + Date$ + "  " + Time$ + "  ---------" + $CrLf + $CrLf
   SendMessage hRichEdit, %WM_Paste, 0, 0
End Sub

'Sub SortData
'   Array Sort D(1)
'   Open "crm.txt" For Output As #1 : Print #1, Join$(D(), $CrLf + $Delim + $CrLf); : Close #1
'   LoadCRMFile       'create D() from CRM.txt
'   DisplayCRMArray   'put D() into LV
'End Sub

Sub AddSearchTerm
   Local i As Long

   'If SearchTerm alread in use, do nothing
   For i = 1 To Min(5,ParseCount(SearchTerms$,$CrLf))
      If LCase$(Parse$(SearchTerms$,$CrLf,i)) = LCase$(SearchTerm$) Then Exit Sub
   Next i

   'If new search term, add it top of the list of SearchTerms$
   SearchTerms$ = SearchTerm$ + $CrLf + SearchTerms$
   SearchTerms$ = Trim$(SearchTerms$, Any $CrLf + $Spc)
   Open "searchterms.txt" For Output As #1 : Print #1, SearchTerms$; : Close #1

   LoadComboBox
End Sub

Sub SaveBackup
   Local temp$
   temp$ = Time$
   Replace  ":" With "." In temp$
   Incr BackupNumber
   Open "backup\crm_" + Format$(BackupNumber) + "_" + Date$ + "_" + temp$ + ".txt" For Output As #1
   Print #1, Join$(D(), $CrLf + $Delim + $CrLf); : Close #1
End Sub

Sub FindRE
   GetRESearchTerm
   SearchText RESearchTerm, %FR_Down
End Sub

Function SearchText(ByVal sTextToSearchFor As WString, SearchDirection As Long) As Long
Local  FindTextText         As FINDTEXTEX
Local  NextMatch, SelStart, SelEnd As Long

SendMessage(hRichEdit, %EM_GETSEL, VarPtr(SelStart), VarPtr(SelEnd))
FindTextText.lpStrText = StrPtr(sTextToSearchFor)

If SearchDirection = 1 Then
   FindTextText.chrg.cpMin = SelEnd + 1 'Search from current position
   FindTextText.chrg.cpMax = -1         '- till the end
Else '%FR_UP
   FindTextText.chrg.cpMin = SelStart   'Search from current position
   FindTextText.chrg.cpMax = 0          '- up to the start
End If

NextMatch = SendMessage(hRichEdit, %EM_FINDTEXTEX, SearchDirection, VarPtr(FindTextText)) 'Return next match or -1 for no more

If NextMatch = -1 Then WinBeep(250,300) :Exit Function
SendMessage(hRichEdit, %EM_SETSEL, FindTextText.chrgText.cpMin, FindTextText.chrgText.cpMax)

End Function

Sub GetRESearchTerm
   Dialog New Pixels, 0, "Search RE",,,200,80, %WS_SysMenu To hDlgI
   Dialog Set Icon hDlgI, "xsearch"
   Control Add TextBox, hDlgI, %IDC_InputTextBox,RESearchTerm, 20,10,160,30
   Control Add Button, hDlgI, %IDC_InputOk, "Ok", 20,50,50,25
   Control Add Button, hDlgI, %IDC_InputCancel, "Cancel", 90,50,90,25
   RESearchTerm = ""
   Dialog Show Modal hdlgI Call hDlgIProc
End Sub

CallBack Function hDlgIProc() As Long
   Select Case Cb.Msg
      Case %WM_Command
         Select Case Cb.Ctl
            Case %IdOk    , %IDC_InputOk     : Control Get Text hDlgI, %IDC_InputTextBox To RESearchTerm : Dialog End hDlgI
            Case %IdCancel, %IDC_InputCancel : Dialog End hDlgI
         End Select
   End Select
End Function

Sub NewCFN
   ReDim Preserve D(1 To UBound(D)+1)
   D(UBound(D)) = "New Entry"
   CFN = UBound(D)

   ListView Insert Item hDlg, %IDC_ListView, CFN, 0, "New Entry " + $CrLf + "Date: " + Date$
   ListView Set Text hDlg, %IDC_ListView, CFN, 2, Format$(CFN)

   ListView Select hDlg, %IDC_ListView, CFN
   ListView_SetItemState hListView, CFN-1, %LVIS_Focused, %LVIS_Focused  '<--- keyboard synchronizing code
   ListView Visible hDlg, %IDC_ListView, CFN

   Control Set Text hDlg, %IDC_RichEdit, D(CFN)
   SetFocus hRichEdit
End Sub

Sub DeleteCFN

   If GetFocus = hListView Then
      'list of all item
      If UBound(D) = 1 Then D(1) = "New Entry" : Exit Sub
      ListView Delete Item hDlg, %IDC_ListView, CFN

      Array Delete D(CFN)
      ReDim Preserve D(UBound(D)-1)
      If CFN > UBound(D) Then CFN = CFN - 1

      Open "crm.txt" For Output As #1 : Print #1, Join$(D(), $CrLf + $Delim + $CrLf); : Close #1

      LoadCRMFile       'create D() from CRM.txt
      DisplayCRMArray   'put D() into LV

   Else
      ? "Delete Allowed Only on Main List"
   End If

End Sub

Sub ST(temp$)
   Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, temp$
End Sub



Attached Files Thumbnail(s)
   
Print this item

  The Future
Posted by: George Bleck - 9 hours ago - Forum: Suggestions and discussion about PUMP - Replies (3)

I'd like to start by thanking Albert for hosting our community's new home. This platform has been crucial in bringing our group together and facilitating knowledge-sharing, which would be difficult to achieve without it.

That being said, I think we're still vulnerable to disruptions if something happens to Albert or the current setup. To address this, I propose that we establish a committee to oversee the creation of a more permanent and stable home for our community. This would involve securing reliable hosting, maintenance, and data management, including the ability to export our databases if needed.

To ensure the committee represents our diverse international community, I suggest we aim for broad representation of at least 3-5 members. I know we could nominate some individuals who have demonstrated long-term commitment, but it's essential that potential committee members volunteer and are voted in to confirm their willingness and community acceptance to take on this responsibility.

I'm personally willing to contribute financially to partially support a hosted platform managed by an elected committee, even if I'm not part of the committee myself. I could (and should) not do it alone though, so I expect other donations to help meet the appropriate level of support we would look to achieve.

Establishing bylaws, rules, and other governing documents would be an important next step, which I believe the committee should handle once it's formed.

Thoughts on this proposal?

Print this item

Photo gbLocator
Posted by: Gary Beene - Yesterday, 06:28 AM - Forum: Source Code Library - Replies (4)

Howdy!

I've continued working on gbLocator, which provides a user interface to Everything for blind and low vision users.  I'm up to v4.2.

Web Site: https://newvisionconcepts.com/gblocator/gblocator.htm
Installation File:   https://garybeene.com/files/gblocator_setup.exe
Source Code File:   https://garybeene.com/files/gblocator.zip

You'll recall that I spoke with David (Everything author) and he encouraged me to post something on his forum. I've just done that and hope to get some feedback from folks on his forum.

Here are gbLocator images - one with the toolbar showing (low vision users) and one with the toolbar hidden (blind users).

   

... does this forum allow inline images or just thumbnails that are links to the full size image?

Print this item

  gbThreads
Posted by: Gary Beene - Yesterday, 02:01 AM - Forum: PowerBASIC for Windows - Replies (13)

With the guidance from the other thread on accessing the forum, I was able to update my gbThreads files through today.

These links contain just the file bigthread.htm. Use it to replace the one you already have.

https://garybeene.com/files/bigthread.zip   140MB

https://garybeene.com/files/bigthread.7z   90MB

I had to manually walk through the forums to get a list of threads that have changed since the last update so please let me know if I missed anything!

Print this item

  High resolution replacement for Sleep
Posted by: David Roberts - 09-01-2025, 10:33 PM - Forum: Source Code Library - No Replies

SleepX()

SleepX() is a high resolution replacement for Sleep.

The principle used has an analogy with HiFi were a class B amplifier is used to get us within a neighbourhood of a desired voltage and then uses a class A amplifier to fine tune. The cost of this approach is much less than using only a class A amplifier, which are expensive.

The class B amplifier analogy uses Sleep and the class A amplifier analogy uses the Performance Counter, which has a resolution of 100ns with Windows 10 and later.

The following code has the SleepX() code and a usage example.

This is a typical output.

Code:
Quarter of a millisecond: .2503 ms

2 seconds: 2.0000003 s

Silly: 1234.0003 ms

1  1.0001 ms
2  2.0001 ms
3  3.0002 ms
4  4.0001 ms
5  5.0002 ms
6  6.0002 ms
7  7.0002 ms
8  8.0001 ms
9  9.0001 ms
10  10 ms
11  11.0002 ms
12  12.0002 ms
13  13.0001 ms
14  14.0001 ms
15  15.0001 ms
16  16.0002 ms
17  17.0002 ms
18  18.0002 ms
19  19.0002 ms
20  20.0001 ms
21  21.0003 ms
22  22.0002 ms
23  23.0001 ms
24  24.0001 ms
25  25 ms
26  26.0002 ms
27  27.0002 ms
28  28.0002 ms
29  29.0002 ms
30  30.0002 ms

The first example looks at a delay of a quarter of a millisecond. I doubt that anyone will have a use for that. The second example looks at a delay of two seconds. The third example looks at a 'silly' delay of 1234ms, The following looks at delays from 1ms to 30ms in steps of 1ms.

All the results have a sub micro accuracy inline with the Performance Counter on Windows 10 and later.

SleepX() has two parts: The first part is used for delays <= to 3ms and only polls the Performance Counter. This is expensive but is a short-lived expense and should not impact on the system performance. The second part uses the construct 'Sleep ( n-3 )' to get us within a neighbourhood of the target delay, and then we poll the Performance Counter to fine tune. 'Sleep ( n-3 )' needs a resolution of 1ms and why we use SetHiRes.

'Sleep ( n-3 )' does not use any CPU load. The CPU load only kicks in when we enter the 'class A' mode, so is an absolute value and should not impact on the system performance.

Why was 'n <= 3'.  It is reasonable to expect a 1ms resolution to give a delay of between n ms and n+1 ms. In practice, we can exceed n+1 ms and about one third of delays do just that. It is very rare, but values approaching n+1.5 ms have been seen. To mitigate that issue, 'n <= 3' was chosen.

That is it: A very simple idea to give a high resolution replacement for Sleep with a negligible CPU load.

It is worth noting that
Code:
SetHiRes
<Code to time>
RevokeHiRes
is acceptable, but it should not be used within a loop; for example a graphics application with 60, or so, fps. That will upset the system clock. It is better to use SetHiRes at the beginning of an application and RevokeHiRes when the higher resolution is no longer needed. If you forget to use RevokeHiRes SetHiRes will be cancelled when the process terminates. Microsoft neglects to mention that.

Code:
#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"

' SOURCE CODE:

Macro QPC = QueryPerformanceCounter qTimeNow

Macro SetHiRes
  MacroTemp Time
  Dim Time As TIMECAPS
  TimeGetDevCaps( Time, SizeOf(Time) )
  TimeBeginPeriod(Time.wPeriodMin)
  'Sleep 16 ' Pre Windows 10 - high resolution does not 'byte' until next clock tick.
End Macro

Macro RevokeHiRes
  MacroTemp Time
  Dim Time As TIMECAPS
  TimeGetDevCaps( Time, SizeOf(Time) )
  TimeEndPeriod(Time.wPeriodMin)
End Macro

Global qFreq As Quad

Sub SleepX( ByVal n As Double )
  Local qTarget, qTimeNow As Quad
  QPC
  qTarget = qTimeNow + n*qFreq*0.001
  If n <= 3 then
    Do : QPC : Loop Until qTimeNow >= qTarget ' Class A amplifier analogy
  Else
    ' Class B amplifier analogy followed by Classs A amplifier analogy
    Sleep ( n-3 ) : Do : QPC : Loop Until qTimeNow >= qTarget
  End If
End Sub

' ====================

' EXAMPLE USAGE:

Function Pbmain () As Long
Local i as Long
Local qStart, qStop As Quad

  QueryPerformanceFrequency qFreq

  SetHiRes

  QueryPerformanceCounter qStart
    SleepX(0.25)
  QueryPerformanceCounter qStop
  Print "Quarter of a millisecond:";(qStop - qStart)*1000/qFreq;"ms"
  Print

  QueryPerformanceCounter qStart
    SleepX(2000)
  QueryPerformanceCounter qStop
  Print "2 seconds:";(qStop - qStart)/qFreq;"s"
  Print

  QueryPerformanceCounter qStart
    SleepX(1234)
  QueryPerformanceCounter qStop
  Print "Silly:";(qStop - qStart)*1000/qFreq;"ms"
  Print

  For i = 1 to 30
    QueryPerformanceCounter qStart
      SleepX(i)
    QueryPerformanceCounter qStop
    Print i;" ";(qStop - qStart)*1000/qFreq;"ms"
  Next

  RevokeHiRes

  WaitKey$

End Function

Print this item

  If you want to get to the PB Forum, do this
Posted by: Albert Richheimer - 09-01-2025, 04:53 PM - Forum: Suggestions and discussion about PUMP - No Replies

I have moved Carlo's thread into the members area, in Issues About The PowerBASIC Forum

Should be a better solution, so that the new PB owners won't be aware that we still have access to forum.powerbasic.com.

Print this item

  Clockwise sort of coordinates
Posted by: Torkel M. Jodalen - 08-30-2025, 09:33 AM - Forum: Programming - Replies (3)

Anyone who cares to post the final iteration of the "clockwise sort of coordinates" source code, which was recently discussed in the PB forums? I waited too long to store a local copy.

Thanks.

Print this item

  Pac-Man maze
Posted by: Jules Marchildon - 08-30-2025, 03:28 AM - Forum: Programming - Replies (9)

I'm starting to work on a pac-man maze.  I have a long road ahead of me with this challenge.   I'm going with a technique I read up on using tiles that are setup as a grid that allows you to draw the maze dynamically.  Each tile is stored in a 2D array.  The maze is setup 28 across and 31 tiles down.  The array elements are structures that allow you to include properties or attributes about the tile and can be used for game flow logic and drawing updates.   I'm curious to know if anyone else in PB land has done any work in this area?  TIA. 

A picture of what I have so far... (obviously more work to be done )
   

Print this item

  Hardware via USB
Posted by: Tillmann Viefhaus - 07-05-2025, 06:52 AM - Forum: Special Interest Groups - Replies (2)

How could I detect and handle for example a webcam with Power Basic?
I have no experience with this topic.

Print this item