I use TextBox, prompt string can't input number,
Enter the Numbers on the window enter
Variable=TextBox1. Text
How should I change the program, meet the needs of me now?
CodePudding user response:
Textbox can't enter the Numbers?Take a closer look at the control property Settings, or see if code control,
CodePudding user response:
Variable=Val (TextBox1. Text)Or:
The type conversion function
Each function can be forced to convert an expression to a specific data type,
Syntax
CBool (expression)
CByte (expression)
CCur (expression)
CDate (expression)
CDbl (expression)
CDec (expression)
CInt (expression)
CLng (expression)
CSng (expression)
CStr (expression)
CVar (expression)
CStr (expression)
Necessary expression parameter can be any string expression or numerical expression,
The return type
Function name decided to return type, as shown in the following:
Function return type expression parameters
CBool Boolean any valid string or numeric expressions,
CByte Byte 0 to 255,
CCur Currency - 922337203685477580-7, 8 to 922337203685477580
CDate Date any valid Date expressions,
CDbl Double negative e-324 e308 from 1.79769313486232 to 4.94065645841247; Positive e-324 from 4.94065645841247 to 1.79769313486232 e308,
CDec zero change than a Decimal value, that is, no small digital values, for the
+/- 79228162514264337593543950335, to 28 decimal value range is
+/- 7.9228162514264337593543950335; The smallest possible nonzero value is 0.0000000000000000000000000001,
CInt Integer - 32768 to 32767, the decimal part rounded,
CLng Long - 2147483648 to 2147483647, the decimal part rounded,
E38 CSng Single negative for 3.402823 to 1.401298 e-45; Positive number 1.401298 e-45 to 3.402823 e38,
CStr String returned to CStr according to expression parameters,
CVar Variant for numerical, range is the same as the Double; If not for numerical, the scope and the same String,
Description
If passed to the function of expression than converting the scope of the target data type will be an error occurs,
Usually, can use when encoding, data type conversion function to display the results of some operations should be expressed as a specific data type, instead of the default data type, for example, when a single, double or integer arithmetic, using CCur to enforce monetary operations,
Data type conversion function should be used instead of Val, in order to make the international version of the data conversion can transfer from one data type to another, for example, when using Ccur, different decimal separator, micrometer separator and a variety of currency options, on the basis of system of our country Settings will be properly identified,
When the decimal part is just 0.5, Cint and CLng function will convert it to the closest value, for example, conversion of 0,1.5 conversion to 2, 0.5 Cint and CLng function is different from Fix and Int function, Fix and the fractional part will be truncated Int function rather than rounded, and Fix and Int function always return the same value with the incoming data types,
IsDate function, can judge whether the date can be converted to a date or time, Cdate text can be used to identify the date and time of text, and fall into the date of the acceptable range value, when converting a digital date, is to convert the integer part of date, converting the decimal part from the middle of the night time,
CDate according to the system of our country set up to determine the date format, if you provide the format for date set, unrecognized correct judgment will not be year, month, day order, in addition, the long date format, if the string contains a week, can not be identified,
CVDate function also provides for early Visual Basic version compatibility, CVDate function of grammar and CDate function are the same, however, is CVDate returns a Variant, it is the Date subtypes, rather than the actual Date type, because there are real Date type, so the CVDate also no longer need, convert an expression as the Date, and then assigned to a Variant, also can achieve the same effect, can also use this technique to other real data type conversion for equivalent Variant subtypes,
Note CDec function cannot return to separate data types, and always returns a Variant, its value has been converted to a Decimal subtypes,