ListBox

BlitzMax Forums/BlitzMax Beginners Area/ListBox

Hi
Could somebody help with this Blitz Max program below, I’m no expert, but I can make this type of program work using Blitz3D. What I wanted to do is enter a number preferable a float
Variable limited to .00 in the next box enter a percentage Variable, then out put the result to the next box. I hope some one can show me how to do this. Code would be helpful but please, please make it simple that even a beginner at Blitz Max like me can understand.


SuperStrict


Local MyWindow:TGadget=CreateWindow(" My Tool Box V1.0", 350,120,400,400) 'the position of the toolbox in the mainwindow
Local ListBox:TGadget=CreateListBox(50,50,290,20,MyWindow) 'the size of the listbox inside the toolbox window

Local Label0:TGadget=CreateLabel("Working out Percentages",135,5,300,20,MyWindow) ' write text to te Main ToolBox window

AddGadgetItem ListBox, " Formular : Value / by 100 x the percent your looking for" ' create a listbox and put text in to it

Global Label1:TGadget=CreateLabel("Enter Value :",50,113,70,25,MyWindow) ' write text to te Main ToolBox window


Local MyInput_1:TGadget=CreateTextField(135,110,85,20,MyWindow) ' a sort of Input




Global Label_2:TGadget=CreateLabel("Enter Percent %:",50,173,85,20,MyWindow) ' write text to te Main ToolBox window


Local MyInput_2:TGadget=CreateTextField(135,170,85,20,MyWindow) ' a sort of Input




Global Label_3:TGadget=CreateLabel("The result is :",50,233,85,20,MyWindow) ' write text to te Main ToolBox window


Local MyInput_3:TGadget=CreateTextField(135,230,85,20,MyWindow) ' a sort of Input




'Global Label1:TGadget=CreateLabel("Enter Value :",50,113,70,25,MyWindow)



Repeat
WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
End
End Select


Forever

Here's a simple version to get you going:
' Listbox help for dalaware

SuperStrict

Local MyWindow:TGadget=CreateWindow(" My Tool Box V1.0", 350,120,400,400) 'the position of the toolbox in the mainwindow
Local ListBox:TGadget=CreateListBox(50,50,290,20,MyWindow) 'the size of the listbox inside the toolbox window 
Local Label0:TGadget=CreateLabel("Working out Percentages",135,5,300,20,MyWindow) ' write text to te Main ToolBox window 
AddGadgetItem ListBox, " Formular : Value / by 100 x the percent your looking for" ' create a listbox and put text in to it 
Global Label1:TGadget=CreateLabel("Enter Value :",50,113,70,25,MyWindow) ' write text to te Main ToolBox window 
Local MyInput_1:TGadget=CreateTextField(135,110,85,20,MyWindow) ' a sort of Input
Global Label_2:TGadget=CreateLabel("Enter Percent %:",50,173,85,20,MyWindow) ' write text to te Main ToolBox window 
Local MyInput_2:TGadget=CreateTextField(135,170,85,20,MyWindow) ' a sort of Input
Global Label_3:TGadget=CreateLabel("The result is :",50,233,85,20,MyWindow) ' write text to te Main ToolBox window 
Local MyInput_3:TGadget=CreateTextField(135,230,85,20,MyWindow) ' a sort of Input

'Global Label1:TGadget=CreateLabel("Enter Value :",50,113,70,25,MyWindow) 


Repeat
	WaitEvent()
	''Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_WINDOWCLOSE
		End
		Case EVENT_GADGETACTION
		Local v:Float=Float(TextFieldText(MyInput_1))
		Local p:Int=Int(TextFieldText(MyInput_2))
		SetGadgetText MyInput_3 , v/100.0*p
	End Select
Forever

You can use SetGadgetFilter for controlling the data being entered into the textfields. I'll try and knock something up to show you how.

Hi, Jim

Thanks for the Help, tell me how do you get your code example in that neat box?

forum codes here

Use codebox /codebox tags wrapped in []
Also, refer to Forum Codes

Here is an example using filters to prevent the user entering unwanted data (such as letters/characters):

' Listbox help for dalaware

SuperStrict


Local MyWindow:TGadget=CreateWindow(" My Tool Box V1.0", 350,120,400,400) 'the position of the toolbox in the mainwindow
Local ListBox:TGadget=CreateListBox(50,50,290,20,MyWindow) 'the size of the listbox inside the toolbox window 
Local Label0:TGadget=CreateLabel("Working out Percentages",135,5,300,20,MyWindow) ' write text to te Main ToolBox window 
AddGadgetItem ListBox, " Formular : Value / by 100 x the percent your looking for" ' create a listbox and put text in to it 
Global Label1:TGadget=CreateLabel("Enter Value :",50,113,70,25,MyWindow) ' write text to te Main ToolBox window 
Local MyInput_1:TGadget=CreateTextField(135,110,85,20,MyWindow) ' a sort of Input
Global Label_2:TGadget=CreateLabel("Enter Percent %:",50,173,85,20,MyWindow) ' write text to te Main ToolBox window 
Local MyInput_2:TGadget=CreateTextField(135,170,85,20,MyWindow) ' a sort of Input
Global Label_3:TGadget=CreateLabel("The result is :",50,233,85,20,MyWindow) ' write text to te Main ToolBox window 
Local MyInput_3:TGadget=CreateTextField(135,230,85,20,MyWindow) ' a sort of Input

'Global Label1:TGadget=CreateLabel("Enter Value :",50,113,70,25,MyWindow) 

' set the textfield filter routines
SetGadgetFilter MyInput_1, MyInput_1_Filter
SetGadgetFilter MyInput_2, MyInput_2_Filter


Repeat
	WaitEvent()
	''Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_WINDOWCLOSE
		End
		Case EVENT_GADGETACTION
		Local v:Float=Float(TextFieldText(MyInput_1))
		Local p:Int=Int(TextFieldText(MyInput_2))
		SetGadgetText MyInput_3 , v/100.0*p
	End Select
Forever

' for MyInput_1 - restrict input to "0123456789."
Function MyInput_1_Filter:Int(event:TEvent, context:Object)
	Select Event.ID
		Case EVENT_KEYCHAR
		' accept fullstop/period
		If event.data=46 Return True
		' accept numbers 0 to 9
		If event.data>=48 And event.data<=57 Return True
	End Select
	Return False
End Function

' for MyInput_2 - restrict input to "0123456789"
Function MyInput_2_Filter:Int(event:TEvent, context:Object)
	Select Event.ID
		Case EVENT_KEYCHAR
		' accept numbers 0 to 9
		If event.data>=48 And event.data<=57 Return True
	End Select
	Return False
End Function