1

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

asked Jul 1, 2015 at 8:06

1 Answer 1

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
answered Jul 1, 2015 at 9:03
3
  • It contains error "Val: argument1 has invalid type" What does it means? Commented 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? Commented 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. Commented Jul 1, 2015 at 20:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.