-3

i am getting error in 1st line

Dim result = (CInt(Split(Overtime.Text, ":")(0)) * 60 + CInt(Split(Overtime.Text, ":")(1)))
OvertimeAmount.Text = (result * Val(OvertimeRate.Text)) / 60
5
  • 4
    Did you debug the code ? Whats the Overtime.Text value in the Quickwatch ?
    – lstern
    May 20, 2013 at 17:56
  • What kind of error are you getting?
    – Jules
    May 20, 2013 at 18:15
  • 1
    Why do you do the split twice? Think about expanding the code to multiple steps and check each step at a time. You are doing too much at the same time without understanding what is going on. May 20, 2013 at 19:56
  • @Istern Overtime.text contains total overtime of employee between two selected date
    – Raj Sharma
    May 20, 2013 at 22:38
  • @JulesMazur “Conversion from string ”" to type 'Integer' is not valid
    – Raj Sharma
    May 20, 2013 at 23:21

3 Answers 3

3
Dim i As Integer
Integer.TryParse(value, i)
Console.WriteLine("Integer:", i)
1
  • its not working, still getting the same error in 1st line in my above given code
    – Raj Sharma
    May 20, 2013 at 22:41
0

To convert a string containing a numeric value to an actual numerical type (eg int) you need to use

Integer.Parse(someString)
1
  • i am still getting the same error..nothing is working for me..please help
    – Raj Sharma
    May 20, 2013 at 22:39
0

perhaps something like this will work:

Dim Result as Integer = TimeSpan.Parse(Overtime.Text).TotalMinutes
OvertimeAmount.Text = ((result * Val(OvertimeRate.Text)) / 60).ToString

This assumes you are validating the text in Overtime. If not you can use the TryParse method.

    Dim ts As New TimeSpan
    Dim ValidText As Boolean = TimeSpan.TryParse(Overtime.Text, ts)
    If ValidText Then
        Dim Result as Integer = ts.TotalMinutes
    End If

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.