Hi all,
In the new version this code
variablename = me.txtboxname.value
or
variablename = Val(me.txtboxname.values)
don`t wrk it.
Is there a another option to read values (numbers) in vb express or i can`t use it in vb express
cheers,
spike
Hi all,
In the new version this code
variablename = me.txtboxname.value
or
variablename = Val(me.txtboxname.values)
don`t wrk it.
Is there a another option to read values (numbers) in vb express or i can`t use it in vb express
cheers,
spike
value from txtBox
nomad98736
Yes, you have to declare a variable "test" of type Decimal before you can call TryParse...
Best regards,
Johan Stenberg
soumyac
Remove the "out" from your TryParse call:
Dim success As Boolean = Decimal.TryParse(txtFcprober.Text, out test)
Should be:
Dim success As Boolean = Decimal.TryParse(txtFcprober.Text, test)
Best regards,
Johan Stenberg
PeteCarterGreenan
hi,
no, it will be string what is the type that you use for variablename . if its integer you can use Dim variableName as integer = integer.parse(txtbox.text); if its any numeric type use the type.parse(string)
hope this helps
KanishK
for all your decimal variables you can use
fcprober = decimal.parse(Me.txtFcprober.Text)
if the textbox.text contain anything other than decimal number like letters for example it will give you exception
other wise you can use tryparse it return a boolean represent the sucessfullness of the conversion for example
dim fcpropber as decimal
dim success as boolean = decimal.tryparse(txtFCprober.text,out test)
Edit
previous line was wrong it suppose to be like this
dim success as boolean = decimal.tryparse(txtFCprober.text,fcprober)
end edit
if the conversion was made successfully it will set Fcprober equal to the value if not it will set it equal 0.0 and success will false
if not success = true then
messagebox.show("plz enter numeric value in this feild")
txtFCprober.focous()
end if
hope this helps
Dean Hiller2
So hier are my codes:
Dim
username As String Dim filtertyp As String Dim lotnumber As String Dim fcprober As Decimal Dim cdev_soll As VariantType Dim cdevtol_soll As VariantType Dim cdev_soll_diff_mhz As Decimal Dim cdevtol_soll_diff As Decimal Dim lowerlimit_soll As Decimal Dim fcsoll As Decimal Dim upperlimit_soll As Decimalusername =
Me.txtName.Textlotnumber =
Me.txtLotnumber.Textfiltertyp =
Me.txtFiltertyp.Textfcprober =
Me.txtFcprober.Textcdev_soll =
Me.txtCDevsoll.Textcdevtol_soll =
Me.txtCDevtolsoll.Textcdev_soll_diff_mhz =
Me.txtCDevdiffsoll.Textcdevtol_soll_diff =
Me.txtCDevtoldiffsoll.Textlowerlimit_soll =
Me.txtLowerlimitsoll.Textfcsoll =
Me.txtOptimafcsoll.Textupperlimit_soll =
Me.txtUpperlimitsoll.Textand i become this error massage:
Invalid conversion of the character sequence in type decimal
can some1 help me to solve this problem pls
cheers,
spike
PoKemonInstructor
thx johan, sorry it was in C# and i forgot to remove "out test" it will not work like that , it suppose to be
Dim success As Boolean = Decimal.TryParse(txtFcprober.Text, fcprober)
hope this helps
JoelBarish
as first thx all for great helping :D
so i alredy declared a variable "test" as decimal and succes as boolean. When i start the programm and if i nothing enter in txtFcprober-Textbox i become this error message:
The input character sequence has the wrong format.
in the line:
fcprober = Decimal.Parse(Me.txtFcprober.Text)
Here is the part of codes:
Dim
username As String Dim filtertyp As String Dim lotnumber As String Dim fcprober As Decimal Dim cdev_soll As Decimal Dim cdevtol_soll As Decimal Dim cdev_soll_diff_mhz As Decimal Dim cdevtol_soll_diff As Decimal Dim lowerlimit_soll As Decimal Dim fcsoll As Decimal Dim upperlimit_soll As Decimal Dim test As Decimalusername =
Me.txtName.Textlotnumber =
Me.txtLotnumber.Textfiltertyp =
Me.txtFiltertyp.Textfcprober =
Decimal.Parse(Me.txtFcprober.Text)cdev_soll =
Decimal.Parse(Me.txtCDevsoll.Text)cdevtol_soll =
Decimal.Parse(Me.txtCDevtolsoll.Text)cdev_soll_diff_mhz = cdev_soll * fcprober / 1000000
cdevtol_soll_diff = cdevtol_soll * fcprober / 1000000
fcsoll = fcprober + cdev_soll_diff_mhz
upperlimit_soll = fcprober + cdev_soll_diff_mhz + cdevtol_soll_diff
lowerlimit_soll = fcsoll - cdevtol_soll_diff
Me.txtCDevdiffsoll.Text = cdev_soll_diff_mhz Me.txtCDevtoldiffsoll.Text = cdevtol_soll_diff Me.txtOptimafcsoll.Text = fcsoll Me.txtLowerlimitsoll.Text = lowerlimit_soll Me.txtUpperlimitsoll.Text = upperlimit_soll
Dim success As Boolean = Decimal.TryParse(txtFcprober.Text, test) If Not success = False ThenMessageBox.Show(
"Please enter a numeric value in this field!")txtFcprober.Focus()
End IfMaybe couse i use first time a new version of VB but i think the old version was symple to use :D
Adam West
thx for fast reply.
buit i will to take numbers as values. in older version if i type variablename = txtboxname.text wasn’t same like variablename = me.txtboxname.value .
with variablename = txtboxname.text will be as number if i type number in box
Seth Cohen
I already removed but i become errorr:
The name "test" was not defined.
shall i have to declare a variable with name "test" or...
thx,
spike
Joel McCormick
i changed it but i become still error (if is nothing in this field) :(
"The input character sequence has the wrong format."
in line:
fcprober = Decimal.Parse(Me.txtFcprober.Text)
ShubertAtEastridge
There are two flavours of the Parse function; the Parse that returns the value is successful, but throws an exception if it fails, and the TryParse, where you have to provide the variable that you want the function to "fill in" with the parsed value, and that returns true if the function succeeds, and false if the function fails.
So, when would you choose one over the other I would use the Parse function if I "trusted" the data that I was about to convert (I really didn't expect the parse to fail) and use the TryParse if I thought that it was likely that the string that I was about to convert was of the wrong format.
This measn that at any point where I get data directly from the user (such as is the case here) I would use TryParse (you can't trust users
)
If you use the Parse function, you probably want to put it in a Try/Catch block and add appropriate error handling if the conversion fails.
Best regards,
Johan Stenberg
Michiel1978
As first thank you shakalama and to you johan for helping
With tryParse i solved the problem (just for info if some1 have a same trouble)
Just the last question
:
If i will to make for every textbox, where user entering information, a if-function like:
Dim
success As Boolean = Decimal.TryParse(txtFcprober.Text, fcprober) If Not success = True ThenMessageBox.Show(
"Please enter a numeric value in this field!")txtFcprober.Focus()
End Ifshall i have to just giving the codes one behind the other before END SUB or it be there a better place
Exitboy
As first thx for helping :D
It works better but i have just problem with this part of code
I wrote it exactly but it didnt work:
Dim
success As Boolean = Decimal.TryParse(txtFcprober.Text, out test) If Not success = True ThenMessageBox.Show(
"Please enter numeric value in this field!")txtFCprober.focus()
End If
nguyenkiem
variablename = txtboxname.Text
lmao