Page 1 of 1

Code from PureArea

Posted: Sat Oct 11, 2025 4:31 pm
by RNBW
I tried to run the following code for "NumbersInStringGadget.pb" from PureArea (Translated to English, but the same happens in German). It comes up with the error "Line 29: number_Click is not a valid operator'.

Code: Select all

; German forum: Translated to English
; Author: OzBernd (updated for PB4.00 by blbltheworm)
; Date: 20. December 2002
; OS: Windows
; Demo: No


; Number String Gadget 
; Feel free to use it anywhere, anytime 
; Pay attention to decimal and thousandth characters 
;------------------------------------------------ 

Form1_hWnd= OpenWindow(0,100,200,200,200,"TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
;If Form1_hWnd=0 Or CreateGadgetList(Form1_hWnd)=0 : End : EndIf 
If Form1_hWnd=0  : End : EndIf

#number = 1 
#label = 2 
string_hWnd= StringGadget(#number,10,50,100,20,"") 
label_hWnd = TextGadget(#label, 10,30,100,20,"Enter limit") 
GadgetToolTip(#number,"Please enter your desired credit limit") 
SetActiveGadget(#number) 

Repeat 
  EventID=WaitWindowEvent() 
  Select EventID 
    Case #PB_Event_Gadget 
      Select EventGadget() 
        Case #number :FakeEndSelect: Gosub number_Click 
        
    EndSelect 
  EndSelect 
  esc=GetAsyncKeyState_(#VK_ESCAPE) 
  ret=GetAsyncKeyState_(#VK_RETURN) 
Until EventID=#PB_Event_CloseWindow Or esc=-32767 Or ret=-32767 


;Swap format according to German convention
text$ = ReplaceString(text$, ",", ".",1,1) 
          
Debug text$ 




      
End    
          
; Process input, exclude NoNumbers and place cursor at the end 
number_Click: 

text$ = GetGadgetText(#number) 
If Len(text$)> 0 
   input.b = Asc(RTrim(Right(text$,1))) 
   If input >=44 And input <=57 And input <> 47      ; numbers 0 to 9, -., 
      Return 
   Else 
     SetGadgetText(#number,Left(text$,Len(text$)-1))          ;delete last character
     SendMessage_(string_hWnd,#EM_SETSEL, Len(text$),-1)  ;Place cursor at the end 
   EndIf 
EndIf 

Return 
End 

; IDE Options = PureBasic v4.00 (Windows - x86)
; Folding = -
; EnableXP
I don't understand.

Re: Code from PureArea

Posted: Sat Oct 11, 2025 4:48 pm
by normeus
replace this line:

Code: Select all

Case #number :FakeEndSelect: Gosub number_Click 

with this:

Code: Select all

        Case #number
          Gosub number_Click
I did not check the whole program. looks like It was created for PB 4.00. With older programs, you have to check for language changes.
There are probably other examples doing the same thng in this forum, that use newer versions of PB

Norm

Re: Code from PureArea

Posted: Sat Oct 11, 2025 5:25 pm
by RNBW
Thank you for your very prompt reply.
I've been away from programming for a little while and I'm trying to catch up again. Your suggestion got rid of the error.
Thank you.

Re: Code from PureArea

Posted: Sun Oct 12, 2025 7:14 am
by jacdelad
Umm...this should be rewritten to use a procedure instead of gosub.

Re: Code from PureArea

Posted: Sun Oct 12, 2025 8:39 am
by mk-soft
Some codes on the PureArea are also getting old and need to be revised a lot.
Many already have alternative codes here in the forum.

Re: Code from PureArea

Posted: Sun Oct 12, 2025 8:48 am
by AZJIO
Why don't you use the new sources? You can go back to the old ones when you can't find anything in the new ones.
viewtopic.php?p=492472#p492472
viewtopic.php?p=590228#p590228

Re: Code from PureArea

Posted: Sun Oct 12, 2025 11:41 am
by RNBW
jacdelad wrote: Sun Oct 12, 2025 7:14 am Umm...this should be rewritten to use a procedure instead of gosub.
I think you are correct. I'll give it a go.

The idea and its code could be useful to incorporate in a program if you need alternative output of numbers where countries don't use a comma as a decimal point and use a full stop as the decimal point.

Re: Code from PureArea

Posted: Sun Oct 12, 2025 11:44 am
by RNBW
AZJIO wrote: Sun Oct 12, 2025 8:48 am Why don't you use the new sources? You can go back to the old ones when you can't find anything in the new ones.
viewtopic.php?p=492472#p492472
viewtopic.php?p=590228#p590228
Thank you for the links, they are very useful.

Re: Code from PureArea

Posted: Sun Oct 12, 2025 2:27 pm
by AZJIO
RNBW wrote: Sun Oct 12, 2025 11:44 am Thank you for the links, they are very useful.
There's a newer one here
viewtopic.php?t=62741
viewtopic.php?t=80656