Simple question

Blitz3D Forums/Blitz3D Beginners Area/Simple question

Apollonius(Posted 2003) [#1]
look at this:
txt_Gamma = CreateTextField( 150,8,100,20,ChildPanel)
...
Gamma_Num = TextFieldText$(txt_Gamma)
...
its really simple but shouldnt this work it says invalid gadget handler, and its a global variable :|

Need the complete code?


eBusiness(Posted 2003) [#2]
I don't use plus, but isn't it mandatory to state the upper left corner first try:

txt_Gamma = CreateTextField( 100,8,150,20,ChildPanel)

Edit:
Ehh, hmm, no. The command probably doesn't work the way I thought at first, dunno what's wrong about it.


soja(Posted 2003) [#3]
Which one is the invalid gadget handle? txt_Gamma or ChildPanel? If you're using them in a function where they were created elsewhere, then they both need to be global. Make sure you're not misspelling anything.


Apollonius(Posted 2003) [#4]
source:
AppTitle "Coalition Legions Game Commander"

	Global   fileopen  = False
	Global   Gamma_Num = 0
	Global   txt_Gamma
	Const    MAXLINES  = 127
	
	; Create Main Window
	w% = 300;GadgetWidth(Desktop()) - 100
	h% = 300;GadgetHeight(Desktop()) - 100
	x% = (ClientWidth(Desktop()) - w) / 2
	y% = (ClientHeight(Desktop()) - h) / 2
	wndMain = CreateWindow("               Coalition Legions Game Commander", x, y, w, h,0,17)
	

	
	ChildPanel = CreatePanel(2,20,280,220,wndMain,0)
	MainSlid   = CreateSlider(275+1,10,15,228,wndMain,2)
	SaveBut    = CreateButton("Save",5,250,60,20,wndMain)
	ExitBut    = CreateButton("Exit",70,250,60,20,wndMain)
	
	lab_Gamma  = CreateLabel("Gamma :",15,14,60,15,ChildPanel)
	txt_Gamma  = CreateTextField( 150,8,100,20,ChildPanel)
	CreatePanel(5,30,255,4,ChildPanel,1)
	;CreatePanel(135,5,4,255,ChildPanel,1)
	
		CreateLabox("Edit",2,7,270,230,30,1,wndMain)
	
	Dim dat$(MAXLINES)
	
	ReadCFG   = ReadFile ("dfv.cfg")
	linecount=0
	If  ReadCFG = 0 Then
		Notify "Unable to access the file needed!"
		End
	Else
		fileopen=True	
	End If
	;-------------------------
	; READ
	While Not Eof(ReadCFG)
		linecount=linecount+1
		dat$(linecount)=ReadLine(ReadCFG)
		If linecount=MAXLINES Exit 
	Wend
	CloseFile ReadCFG
	txt_Gamma = Gamma_Num
	;------------------------
	CreateTimer(60)
quit=False
Repeat
	
	WaitEvent()
	; Close Window
	If EventID()=$803
            If EventSource()=wndMain
				quit=True
            End If
	EndIf
	; Always Ontop
	If EventID()=$4001            ; 60 TIMER LOOP
		ActivateWindow wndMain
	EndIf
	;
	If EventID()=$401
		If EventSource()=SaveBut ; CLICK SAVE BUTTON
			If fileopen=True
				
				Gamma_Num = TextFieldText$(txt_Gamma)
				dat$(15) = "gamma = " + Gamma_Num
				
				ReadCFG=WriteFile("dfv.cfg")
				For i=1 To linecount
				WriteLine ReadCFG,dat$(i)
				Next
				CloseFile ReadCFG
					Notify "Save Successful!"
			EndIf
		EndIf
		If EventSource()=ExitBut ; CLICK EXIT BUTTON
			quit=True
		EndIf
	EndIf

Until quit

; LABOX CREATION CODE
Function CreateLabox(b_text$,b_x,b_y,b_width,b_height,lab_width,lab_style,b_parent)

	CreatePanel( b_x, b_y, b_width+3, 4, b_parent, 1)                                     ; Top
	
	CreatePanel( b_x, b_y+2, 4, b_height, b_parent, 1)                                    ; Left
	
	CreatePanel( b_x, b_y + b_height, b_width+4, 4, b_parent, 1)                          ; Bottom
	
	CreatePanel( b_x + b_width, b_y, 4, b_height+3, b_parent, 1)               			  ; Right
	
	CreateLabel( b_text$, b_x+10, b_y-6, lab_width, 16, b_parent, lab_style)              ; Text

End Function


Gamma_Num = TextFieldText$(txt_Gamma)
Above txt_Gamma is an invalid Gadget.. simpler.. invalid textfield...


soja(Posted 2003) [#5]
Look at what you're doing:
txt_Gamma = CreateTextField( 150,8,100,20,ChildPanel)
This is OK, but then later, you do this:
txt_Gamma = Gamma_Num
...which sets txt_gamma to 0, so it's not referring to a textfield anymore. That's why when you do this later:
Gamma_Num = TextFieldText$(txt_Gamma)
...you get that error. txt_Gamma is 0.


Apollonius(Posted 2003) [#6]
oh stupid me forgot to remove it :|

See I was right it was simple ;)


rdodson41(Posted 2003) [#7]
I don't know if this is just weird or something but you said "Gamma_Num = TextFieldText$(txt_Gamma)". Shouldn't Gamma_Num be a string? TextFieldText$() returns a string, but Gamma_Num is an integer variable. Gamma_Num is then zero or something, but it is definitly not a string! Is there something I am missing here?

-Rich05


soja(Posted 2003) [#8]
The Blitz compiler can do implicit typecasting. In this case, it converts the string of number digits to an integer, automatically.