Letting the user enter a float value.

BlitzMax Forums/BlitzMax Beginners Area/Letting the user enter a float value.

Try it this way:

Strict
Graphics 640,480
Global Str$=""
Global Point:Byte = False
Global Result:Float = 0




While Not KeyDown(KEY_ESCAPE)
Cls
	Local Ch:Int = GetChar()
	If CH > 47 And ch < 58 Then 
		Str:+Chr(CH)
	EndIf
	If CH = Asc(".") Then
		If Point = False Then
			Str:+Chr(CH)
			Point = True
		EndIf
	EndIf
	If CH = KEY_ENTER Then
		Result = 100.0*Float(Str)
		Str = ""
		Point = False
	EndIf
		
	SetColor 255,255,255
	DrawText(Str+"_",12,12)
	DrawText(Result,12,32)
Flip
Wend


You have to save GetChar once before and the operate only with the saved result, because Getchar deletes the last entered key after execution.