Hello,
I just bought PureBasic and built a very first try-out program to get acquainted a bit with PB.
Now I stumble upon a problem I really don't understand.
In the program I've got the next 2 lines in Procedure Converteer() :
	input.s = GetGadgetText(#txtInput)
	ouput.f = ValF(input)
I've used Debug and can see that output will always contain zero, while input is 1 (or any other value! I even changed the first line to
                input.s = "1"
and the same occurs.
When I create a small standalone program with only the 2 lines (using a literal string for the first line) all works fine!
Here follows the source of  Common.pb
;------------------------------------------------------------------------------------
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
;- Window Constants
;
Enumeration
  #Window1
EndEnumeration
;- Gadget Constants
;
Enumeration
  #lblInput
  #txtInput
  #lblOutput
  #comFrom
  #lblConv
  #comTo
  #btnExit
EndEnumeration
Procedure Open_Window1()
  If OpenWindow(#Window1, 216, 0, 496, 291, "Conversie",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window1))
      TextGadget(#lblInput, 20, 50, 180, 20, "Type hier de te converteren waarde:")
      StringGadget(#txtInput, 220, 50, 90, 20, "")
      TextGadget(#lblOutput, 20, 210, 290, 20, "")
      ComboBoxGadget(#comFrom, 80, 110, 200, 80)
      TextGadget(#lblConv, 20, 90, 500, 20, "Converteer   van                                                                naar")
      ComboBoxGadget(#comTo, 290, 110, 190, 80)
      ButtonGadget(#btnExit, 20, 250, 70, 30, "E&xit")
      
    EndIf
  EndIf
EndProcedure
;------------------------------------------------------------------------------------
And the source of Conversie.pb
;------------------------------------------------------------------------------------
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
IncludeFile "Common.pb"
Declare Initialiseer()
Declare Converteer()
Procedure Initialiseer()
	Enumeration
 		#millimeter
 		#centimeter
 		#decimeter
 		#meter
 		#hectometer
 		#kilometer
	EndEnumeration
	Open_Window1()
	AddGadgetItem(#comFrom, -1,"millimeter")
	AddGadgetItem(#comFrom, -1,"centimeter")
	AddGadgetItem(#comFrom, -1,"decimeter")
	AddGadgetItem(#comFrom, -1,"meter")
	AddGadgetItem(#comFrom, -1,"hectometer")
	AddGadgetItem(#comFrom, -1,"kilometer")
	SetGadgetState(#comFrom,3)
	AddGadgetItem(#comTo, -1,"millimeter")
	AddGadgetItem(#comTo, -1,"centimeter")
	AddGadgetItem(#comTo, -1,"decimeter")
	AddGadgetItem(#comTo, -1,"meter")
	AddGadgetItem(#comTo, -1,"hectometer")
	AddGadgetItem(#comTo, -1,"kilometer")
	SetGadgetState(#comTo,3)
	SetGadgetText(#txtInput,"1")
	Converteer()
EndProcedure
Procedure Converteer()
	input.s = GetGadgetText(#txtInput)
Debug input
	ouput.f = ValF(input)
Debug output
	Select GetGadgetState(#comFrom)
		Case #millimeter
			output = output / 1000
		Case #centimeter
			output = output / 100
		Case #decimeter
			output = output / 10
		Case #hectometer
			output = output * 100
		Case #kilometer
			output = output * 1000
		Default
			; must be a Meter
	EndSelect
	Select GetGadgetState(#comTo)
		Case #millimeter
			output = output * 1000
		Case #centimeter
			output = output * 100
		Case #decimeter
			output = output * 10
		Case #hectometer
			output = output / 100
		Case #kilometer
			output = output / 1000
		Default
			; must be a Meter
	EndSelect
	txtout.s = input + " " + GetGadgetItemText(#comFrom,GetGadgetState(#comfrom),0)
	txtout = txtout + " = " + StrF(output)
	txtout = txtout + " " + GetGadgetItemText(#comto,GetGadgetState(#comto),0)
	;SetGadgetText(#lblOutput,txtout)
EndProcedure
Initialiseer()
Repeat
  Event = WaitWindowEvent()
  Select EventWindow() ; Needed when multiple Windows exist
    Case 0 ; main window
    	If Event = #PB_Event_Gadget
        Select EventGadget()
  				Case #btnExit
  					End
  				Case #txtInput
  					Converteer()
  				Case #comFrom
  					Converteer()
  				Case #comTo
  					Converteer()
          Default
            ; Ignore other Gadgets
        EndSelect
      EndIf
    Default
    	; ignore other Windows
  EndSelect
Until Event = #PB_Event_CloseWindow
End
;------------------------------------------------------------------------------------
			
			
									
									
						ValF seems not to work properly
You have a typo! Look at the two variable names in these lines - do you see the difference?
Regards,
Eric
			
			
									
									
						Code: Select all
ouput.f = ValF(input)
Debug outputEric
- 
				NuclearFusion
- User 
- Posts: 35
- Joined: Wed Nov 22, 2006 2:00 pm
Just some beginner tips:
You can make the compiler give an error on cases like this if you put "EnableExplicit" first in your file. Then you must declare all variables with "Define Variable" before you can use them.
When you post code at the forums it is easier to read and copy if you enclose it code tags:
Click the quote button above my post to see how I did that.
			
			
									
									
						You can make the compiler give an error on cases like this if you put "EnableExplicit" first in your file. Then you must declare all variables with "Define Variable" before you can use them.
When you post code at the forums it is easier to read and copy if you enclose it code tags:
Code: Select all
EnableExplicit
Define Output.f
Define String.s
String = InputRequester("Hi", "Type in any number:", "1.6")
Output = ValF(String)
Debug Output
- 
				NuclearFusion
- User 
- Posts: 35
- Joined: Wed Nov 22, 2006 2:00 pm

