I am making an inventory program and the numbers entered will be of varying lengths. I need to remove the last two digits on the right of the number, but can't use the Left function since the length of the numbers will change over time.
Printable View
I am making an inventory program and the numbers entered will be of varying lengths. I need to remove the last two digits on the right of the number, but can't use the Left function since the length of the numbers will change over time.
I don't think theres a problem with that:
Code:var=left(var,len(var)-2)
If using vb 5 or 6 then use the Right function.
Jethro, are you sure that's a good idea?
The Right function works fine if you know the exact number of characters you want to extract. If a fraction maybe a string extract based around the point, this allows variable character extraction.
Am using vb5, so don't know if any bad effects in 4 or below, and am waiting to complete work today at this site to load 6. But persumably the Right function works the same in 6 as it does in 5.
Why have you found a problem with it?
It wont solve his problem:
123456 -> 1234
not
3456
If I do this and put in 12345, it returns 1234.
Private Sub Command1_Click()
Dim Var
Var = Text1.Text
Var = Left(Var, Len(Var) - 2)
Text2.Text = Var
End Sub
This will return 123, what I want.
Private Sub Command1_Click()
Dim Var
Var = Val(Text1.Text)
Var = Left(Var, Len(Var) - 2)
Text2.Text = Val(Var)
End Sub
Am I doing the Val() right? I only need whole numbers.
so that's what you want:
Code:Text2.Text=int(text1.text/100)
You stated you wanted to extract the last two digits, are you really saying you want to extract the full amount excluding the fractions
If so the data would be something like
1234.56
In vb6 use the split function in vb5 use instr and mid functions, or kedamans approach.
Thank you, both ways will work for me. Sorry for the confusing wording. I should have gave an example.