Page 1 of 1

Error message Bad Parameter, number expected

Posted: Sun Nov 08, 2009 11:25 pm
by Hot Pockets
Below is 1 of 16 examples I've downloaded that don't work(Very discouraging. Ive got a splash screen and a menu working and I need examples of programs that the menu calls !

;EXAMPLE 1

;Making a window application in PureBasic is easy, just need to understand
;a few easy concepts

;CONSTANTS:

;Constants are used to make readable a code
;Constants are preceded with # and are used to store numeric values so the code will
;be easier to read.
;In this example we create 2 constants to store the ID number that we will
;use for identify the gadgets or controls that we are going to use with our
;application.

#MyStringGadget = 1
#MyButton = 2

;The first step for creating a window in PureBasic is callig the
;OpenWindow() command and sending all the parameters required.
;In this case we give the number 0 as the identifier for our window
;we give the coordinates 100,150 for the left and top position
;of the window
;then give 450 as the Innerwitdh and 200 as innerheight

;The #PB_Window_SystemMenu flag is one of many available (check the help file
;to see the other flags available)
;and then we put the text that will have the window.
***********************************************************
If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,Title$,12) < This Line is selected,but I can't find what"s wrong.
************************************************************
;Now we will put the gadgets in the window
CreateGadgetList(WindowID())
StringGadget(#MyStringGadget,50,50,350,20,"")
ButtonGadget(#MyButton,200,100,50,25,"Test")

;and now we will go to a loop to receive any user input
;in this case we will receive when a user pushes a button

Repeat
EventID=WaitWindowEvent();we get the windowevent

Select EventID;we check which window event are we receiving

Case #PB_EventGadget;in case its the event from our gadgets
Select EventGadgetID()
Case #MyButton ; the user click the button
MessageRequester("button clicked","hello world",0)
SetGadgetText(#MyStringGadget,"clicked!!");Then we put a text into the string gadget
EndSelect

EndSelect

Until EventID=#PB_EventCloseWindow;loop until the user decide to close the window
EndIf
End

Why do I get messageLine so & so Bad Parameter Type,expects number ?
Pkease help, I think if I can get just get 1 of these examples to work my Prayers will be answered!!

Re: Error message Bad Parameter, number expected

Posted: Sun Nov 08, 2009 11:42 pm
by Arctic Fox
It's just some old syntax for previous versions of PB (before 4.00)

Updated code

Code: Select all

;EXAMPLE 1

;Making a window application in PureBasic is easy, just need to understand
;a few easy concepts

;CONSTANTS:

;Constants are used to make readable a code
;Constants are preceded with # and are used to store numeric values so the code will
;be easier to read.
;In this example we create 2 constants to store the ID number that we will
;use for identify the gadgets or controls that we are going to use with our
;application.

#MyStringGadget = 1
#MyButton = 2

;The first step for creating a window in PureBasic is callig the
;OpenWindow() command and sending all the parameters required.
;In this case we give the number 0 as the identifier for our window
;we give the coordinates 100,150 for the left and top position
;of the window
;then give 450 as the Innerwitdh and 200 as innerheight

;The #PB_Window_SystemMenu flag is one of many available (check the help file
;to see the other flags available)
;and then we put the text that will have the window.
; ***********************************************************
If OpenWindow(0,100,150,450,200,Title$,#PB_Window_SystemMenu,12); < This Line is selected,but I can't find what"s wrong.
; ************************************************************
;Now we will put the gadgets in the window
StringGadget(#MyStringGadget,50,50,350,20,"")
ButtonGadget(#MyButton,200,100,50,25,"Test")

;and now we will go to a loop to receive any user input
;in this case we will receive when a user pushes a button

Repeat
EventID=WaitWindowEvent();we get the windowevent

Select EventID;we check which window event are we receiving

Case #PB_Event_Gadget;in case its the event from our gadgets
Select EventGadget()
Case #MyButton ; the user click the button
MessageRequester("button clicked","hello world",0)
SetGadgetText(#MyStringGadget,"clicked!!");Then we put a text into the string gadget
EndSelect
EndSelect

Until EventID=#PB_Event_CloseWindow;loop until the user decide to close the window
EndIf
End

Re: Error message Bad Parameter, number expected

Posted: Sun Nov 08, 2009 11:45 pm
by infratec
Hi,

simply go on the command which produce the fault (with the cursor) and press F1.
In the upcoming help you can read something like that:

Ergebnis = OpenWindow(#Window, x, y, InnereBreite, InnereHoehe, Titel$ [, Flags [, ParentWindowID]])

So you can see, that your parameters are wrong sorted.
(even when my help is from the german help-file)

Best regards,

Bernd

Oh, to late, only second :(
:mrgreen: :mrgreen: :mrgreen:

Re: Error message Bad Parameter, number expected

Posted: Mon Nov 09, 2009 4:31 am
by SFSxOI

Code: Select all

OpenWindow(0,100,150,450,200,Title$, #PB_Window_SystemMenu,12)

Re: Error message Bad Parameter, number expected

Posted: Mon Nov 09, 2009 5:47 am
by Hot Pockets
Mr SFSs01
Sorry the number 12 was put in to replace the "" that was there originally. The message said that a number was expected so I replaced "" with 12. That did NOT solve the problem. I downloaded these from Purearea and none of the 8 examples work &
they all get the same message.Why?

Re: Error message Bad Parameter, number expected

Posted: Mon Nov 09, 2009 6:04 am
by citystate
replace

Code: Select all

If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,Title$,12)
with

Code: Select all

If OpenWindow(0, 100, 150, 450, 200, Title$ , #PB_Window_SystemMenu)
the code you are using is for an old version of PB, the parameter order of the OpenWindow function has changed - the window title string and the flag have swapped places; so where PB is expecting to find a string, it is finding a number, and vice-versa

when in doubt, have a look at the manual, it's really helpful in cases like this