Troubles with "SendMessage...#EM_LINESCROLL

Just starting out? Need help? Post your questions and find answers here.
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Troubles with "SendMessage...#EM_LINESCROLL

Post by vmars316 »

Troubles with "SendMessage_(GadgetID(Editor_Input), #EM_LINESCROLL"

In my PilgrimsProgress.pb , '1st time thru' works fine , after that , doesnt work well (unpredictable) .
The program has an EditInput(https://vmars.us/ShowMe/Pilgrims-Progre ... umbers.txt)
& EditOutput(search results) ,
& has a SearchBox & SearchButton .
The EditInput lines have sequence numbers on left .

1) ReadInFile into EditInput.
2) Search for Occurances of [search-word-goes-here ] in EditInput .
3) Fill EditOutput with Lines where 'search-word-goes-here' occurs .
4) Click on a line in EditOutput .
5) Show the 'matching line' in EditInput .

Here is the code I am having troubles with .

Code: Select all

;- Case Editor_Output                                    "each Line that Contains your 'Search Argument'  " )                                          
Case Editor_Output 
    If EventGadget() = Editor_Output And EventType() = #PB_EventType_LeftClick  ; Check for left click on the ListView
        ; Get the selected item index
        selectedItem = GetGadgetState(Editor_Output) ; Assuming Editor_Output is the ID of the ListView
        If selectedItem <> -1
            ; Fetch the text of the selected item 
            itemText$ = GetGadgetItemText(Editor_Output, selectedItem)
            ; Find the position of the first space
            spacePosition = FindString(itemText$, " ", 0)
            If spacePosition <> 0
                ; Extract the number before the first space
              number$ = Left(itemText$, spacePosition - 1)
              numberVal = Val(number$) - 1 ; adjust for index starts at 0
              If numberVal > 8 And numberVal < NumberOfLines
               ; numberVal = numberVal + 8  ; move 
                MessageRequester("numbermVal" , Str(numberVal) )
              EndIf
;                MessageRequester("Event Detected", "Left click on ListView detected on item #" + Str(selectedItem) + " - Number: " + number$ + " (" + itemText$ + ")")
                SendMessage_(GadgetID(Editor_Input), #EM_LINESCROLL, 0, numberVal)
                SetGadgetState(Editor_Input,numberVal)       
             EndIf
        EndIf
And here is the full code :

Code: Select all

; PilgrimsProgress.pb
EnableExplicit 
Global StringGadget , Editor_Input , HelpButton , Editor_Output ,
       line$ , Search_String , RepeatCount = 0 , Editor_Input_ItemText$ ,
       CaptureArgText$ , Quit = 0 , SearchButton , DifferentFileButton ,
       Editor_Input_ItemsCount = 0 , CollectLineLen = 0 , FoundPOS = 0 ,
       itemText$ , selectedItem , event = 0 , spacePosition , number$  

;
Declare ReadInFile()
Declare ClearOutputFile()
Declare CollectLine()
Declare InitWindow()
; Create the main window
Procedure InitWindow()
OpenWindow(0, 0, 0, 1050, 820, "Pilgrim_Progress 2.0", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Search_String = StringGadget(#PB_Any, 10, 20, 300, 30, "the") ; Parameters: GadgetID, X, Y, Width, Height
SearchButton = ButtonGadget(#PB_Any, 320, 20, 100, 30, "Search")
DifferentFileButton = ButtonGadget(#PB_Any, 460, 20, 200, 30, "Open Different File")
HelpButton = ButtonGadget(#PB_Any, 900, 20, 80, 30, "Help")
Editor_Input = EditorGadget(#PB_Any, 10, 100, 1030, 350) 
  GadgetToolTip(Editor_Input , "Editor Input File") 
Editor_Output = ListViewGadget(#PB_Any, 10, 500, 1030, 300) ; #PB_ListViewGadget_ClickSelect) 
  GadgetToolTip(Editor_Output , "Click on a Line to Find/Show the Line in Context Above.") 
;
EndProcedure ; InitWindow()

; Read 'Pilgrims.txt' and insert content into EditorGadget(0)
Procedure ReadInFile()
Global   NumberOfLines = 0 , numberVal = 0
If OpenFile(1,"Pilgrims-Progress-Small-Numbers.txt")
    While Eof(1) = 0
      line$ = ReadString(1)
        If line$ <> ""
            ; Append the line read from the file to the EditorGadget(0)
          AddGadgetItem(Editor_Input,-1,line$)  ; " 
          NumberOfLines= NumberOfLines + 1
          EndIf
    Wend
    CloseFile(1)
EndIf
EndProcedure ; ReadInFile
;
;
Procedure ClearOutputFile()
  ClearGadgetItems(Editor_Output)
EndProcedure  ; ClearOutputFile;             ;
:
Procedure CollectLine()
Editor_Input_ItemsCount = CountGadgetItems(Editor_Input)
If Editor_Input_ItemsCount < 1 
    Goto Editor_Input_Missing
  EndIf

  ClearOutputFile()
  CollectLineLen = Len(GetGadgetText(Search_String))
  If CollectLineLen > 0 ; Check if there is a Capture Arg
    CaptureArgText$ = GetGadgetText(Search_String)
    
    Editor_Input_ItemsCount = CountGadgetItems(Editor_Input)
    
    RepeatCount = 0
    Repeat     
    Editor_Input_ItemText$ = GetGadgetItemText(Editor_Input, RepeatCount)
    FoundPOS = FindString(Editor_Input_ItemText$, CaptureArgText$, 1, #PB_String_NoCase) ; if line contains
    If FoundPOS > 0                                                                      ; if did find it
      AddGadgetItem(Editor_Output , -1 , Editor_Input_ItemText$)
    Else
    EndIf    
    RepeatCount = RepeatCount + 1
  Until RepeatCount = Editor_Input_ItemsCount 
  Else 
    MessageRequester("Procedure CollectLine()" , "'Collect Line Search Arg' Must contain a value")
  EndIf ; Check if there is a Delete Arg
  
Editor_Input_Missing:
  If Editor_Input_ItemsCount < 1 
    MessageRequester("Editor_Input_Missing" , "Editor_Input_Missing , 'OPEN FILE'" +Chr(10)+Chr(34)+ 
    "Or Paste Text into 'INPUT Editor'" )
  EndIf

EndProcedure ; CollectLine()
;
InitWindow()
ReadInFile()
;- Event_Loop 
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
;      MessageRequester("Case #PB_Event_Gadget" , "Case #PB_Event_Gadget")
      Select EventGadget()
        Case SearchButton 
           Debug "SearchButton"
           CollectLine()
         Case HelpButton
           MessageRequester("Help Info" , "This Programs Opens with 'PilgrimsProgress.txt' File." + #CRLF$+ 
                                          "Here you can enter a 'Search Word Argument' to Find"       + #CRLF$+ 
;- Case Editor_Output                                    "each Line that Contains your 'Search Argument'  " )                                          
Case Editor_Output 
    If EventGadget() = Editor_Output And EventType() = #PB_EventType_LeftClick  ; Check for left click on the ListView
        ; Get the selected item index
        selectedItem = GetGadgetState(Editor_Output) ; Assuming Editor_Output is the ID of the ListView
        If selectedItem <> -1
            ; Fetch the text of the selected item 
            itemText$ = GetGadgetItemText(Editor_Output, selectedItem)
            ; Find the position of the first space
            spacePosition = FindString(itemText$, " ", 0)
            If spacePosition <> 0
                ; Extract the number before the first space
              number$ = Left(itemText$, spacePosition - 1)
              numberVal = Val(number$) - 1 ; adjust for index starts at 0
              If numberVal > 8 And numberVal < NumberOfLines
               ; numberVal = numberVal + 8  ; move 
                MessageRequester("numbermVal" , Str(numberVal) )
              EndIf
;                MessageRequester("Event Detected", "Left click on ListView detected on item #" + Str(selectedItem) + " - Number: " + number$ + " (" + itemText$ + ")")
                SendMessage_(GadgetID(Editor_Input), #EM_LINESCROLL, 0, numberVal)
                SetGadgetState(Editor_Input,numberVal)       
             EndIf
        EndIf
    EndIf           
      EndSelect
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect

  If Quit = 1
    End
  EndIf

ForEver 
'1st time thru' works fine , after that , doesnt work well (unpredictable) .
Is there a 'RESET code for SENDMESSAGE' or something ?
Thanks for your Help...
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Troubles with "SendMessage...#EM_LINESCROLL

Post by infratec »

I think there are relative values expected and not absolut ones.

Code: Select all

Debug "NumberVal: " + Str(numberVal)
                SendMessage_(GadgetID(Editor_Input), #EM_LINESCROLL, 0, numberVal - LastLine)
                LastLine = numberVal
If you use a function, you should know how it works :wink:

https://learn.microsoft.com/en-us/windo ... linescroll
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Troubles with "SendMessage...#EM_LINESCROLL

Post by vmars316 »

Aha..
"The number of lines to scroll vertically."
Thanks infratec
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
Post Reply