I have created a dialog menu in MapBasic which user can enter value in text field. I am a newbie in MapBasic Programming. My question is how to select data from database using text field value?
select * from voronoi where Ha>= inputnumber
That inputnumber is text field. Please I need your help
1 Answer 1
Let me expand on my previous answer to show how to get the value from the EDITTEXT control. First create your dialog box using a dialog statement like below.
Dim inputText as String
Dialog
Control STATICTEXT
ID 1
Title "Enter a valid number:"
Control EDITTEXT
ID 2
Into inputText
Control OKBUTTON
ID 3
Now you need to check whether the OK button was pressed and if so, then you can do your selection using the value stored in inputText
. You will need to convert the value to a number using the Val()
function. Be careful, the Val()
function will return 0 if the value in inputText
is not a valid number so you may want to check this first.
If CommandInfo(CMD_INFO_DLG_OK) then
Select * from Voronoi where Ha >= Val(inputText)
End if
-
It contains error "Val: argument1 has invalid type" What does it means?Junita– Junita2015年07月01日 09:17:33 +00:00Commented Jul 1, 2015 at 9:17
-
It means that
inputnumber
is not a valid type for the Val() function. I'm not sure without seeing a bit more of the code why that is - can you post the part of the code where inputnumber is assigned?T_Bacon– T_Bacon2015年07月01日 09:24:19 +00:00Commented Jul 1, 2015 at 9:24 -
MapBasic has some neat function for formatting numbers (FormatNUmber$()) and deformating numbers DeformatNumber$(). They might come in handy here, too. The first will add grouping digits and decimal digits set in the Region Settings to the value and return a string with these. The second will assume the string has grouping digits and decimal digits and convert these back. You still need to use the Val() function to cast it to a numeric value.Peter Horsbøll Møller– Peter Horsbøll Møller2015年07月01日 20:37:36 +00:00Commented Jul 1, 2015 at 20:37