basic help again :)

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by willinyork.

Hi! I've been playing around with the example files, and have figured what I need as far as getting something on the screen. I may be missing the completely obvious... but I can't seem to find something to enter numbers with? I mean, something like the "StringGadget" command, but can accept numbers. Basically, I want a box for the user to type a number in, a button for the user to click on (which will perform a simple calculation using the number), then another box which will display the final number after calculation. Any advice will be greatly appreciated :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Use StringGadgets to input the numbers, then VAL to convert the string to a number. Here is an example...

Code: Select all

InitGadget(4)
#num1 = 1
#num2 = 2
#addbutton = 3
#total = 4

If OpenWindow(0,0,0, 185, 172, #PB_Window_SystemMenu,"Add 2 Numbers")
  If CreateGadgetList(WindowID())   
    StringGadget(#num1,30,10,110,21,"") 
    StringGadget(#num2,30,40,110,21,"")
    ButtonGadget(#addbutton,46,80,80,21,"Add")
    StringGadget(#total,30,110,110,21,"")   
  EndIf 
EndIf   

Repeat 
  EventID.l = WaitWindowEvent()
  If EventID = #PB_EventGadget
   
     Select EventGadgetID()
       Case #addbutton
       a.l=Val(GetGadgetText(#num1))
       b.l=Val(GetGadgetText(#num2))
       SetGadgetText(#total,Str(a+b))   
     EndSelect
     
   EndIf
Until EventID = #PB_EventCloseWindow
End  
Of course this example will only add Long numbers.

Edited by - paul on 02 December 2001 16:25:25
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kanati.
Use StringGadgets to input the numbers, then VAL to convert the string to a number. Here is an example...
Think he's referring to a masked edit box that only accepts numeric data. Which PB doesn't have as far as I can see. You could probably create your own with keypress events, but that's kind of a kludge.

Kanati
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

When PureBasic can't do what you want, use the API, it's also a PB feature:

Code: Select all

#ES_NUMBER = $2000 ; Constant not present in PB 2.70
InitGadget(4)
#num1 = 1
#num2 = 2
#addbutton = 3
#total = 4
If OpenWindow(0,0,0, 185, 172, #PB_Window_SystemMenu,"Add 2 Numbers")
  If CreateGadgetList(WindowID())
    number = StringGadget(#num1,30,10,110,21,"")
    SetWindowLong_(number, #GWL_STYLE, GetWindowLong_(number, #GWL_STYLE)|#ES_NUMBER)
    number = StringGadget(#num2,30,40,110,21,"")
    SetWindowLong_(number, #GWL_STYLE, GetWindowLong_(number, #GWL_STYLE)|#ES_NUMBER)
    ButtonGadget(#addbutton,46,80,80,21,"Add")
    number = StringGadget(#total,30,110,110,21,"")
    SetWindowLong_(number, #GWL_STYLE, GetWindowLong_(number, #GWL_STYLE)|#WS_DISABLED)
  EndIf 
EndIf   
Repeat 
  EventID.l = WaitWindowEvent()
  If EventID = #PB_EventGadget
   
     Select EventGadgetID()
       Case #addbutton
       a.l=Val(GetGadgetText(#num1))
       b.l=Val(GetGadgetText(#num2))
       SetGadgetText(#total,Str(a+b))   
     EndSelect
     
   EndIf
Until EventID = #PB_EventCloseWindow
End
Bye,

Juan Calderón Alonso
Registered user
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kanati.
When PureBasic can't do what you want, use the API, it's also a PB feature:

Juan Calderón Alonso
Registered user
Well there you go... More of those undocumented but still there windows constants I wasn't aware of. :) Now if someone could just tell me what the heck a '|=' means in a bit of PB code I've run across........

Kanati
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

Hey Wavemaker,
Doesn't your RichEdit library allow for entering numbers only?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

As far as I know, the ES_NUMBER style doesn't apply to Rich Edit controls, I've tried it with no success, so in that case probably keydown testing could be necessary.

Bye,

Juan Calderón Alonso
Registered user
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
When PureBasic can't do what you want, use the API, it's also a PB feature
That's assuming that you don't intend to use your PureBasic source on
the Amiga and/or Linux platforms, because they obviously don't have the
API commands and must use the built-in PureBasic commands only. But for
a Windows-only app, then yes, the API is the way to go. :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

You're absolutely right, PB. I was wrongly assuming that only Windows users were to read these posts, since they don't seem to be very active in their forums. I am an Amiga user, too, and I'd like to port my libraries to Amiga, its Asm is not new to me, but I don't have a PPC, so... BTW, I don't think there's nothing new after Amos and BlitzBasic in Amiga, is it? I don't understand why the Amiga forum in this site is so inactive, I would have been very glad in my Amiga years to have a compiler like this.

Bye,

Juan Calderón Alonso
Registered user
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

if you have amiga libraries why you dont post them somewhere ?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

I didn't say I had PureBasic Amiga libraries. I don't even have an Amiga now (UAE is a poor substitute). And, AFAIK, PureBasic for Amiga works only in PPC Amigas, which I have never used.

Bye,

Juan Calderón Alonso
Registered user
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

my mistake then however Purebasic runs ATM only on 68k
ppc suport never completed (dropped??)
and BTW amigaOS API has an integer gadget(numeric)
via gadtool.library (PB also support this via internal libs
but PB lack's other command we waiting for :()
Post Reply