• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

String Manipulation and maths

I have a result passed to me as a result of an sql query it is a string.

the string for example would be 03 02:45:00

This represents the duration of a trip.

I need to be able to perform some maths on this string in seperate sections......

I need the first two digits in the string to be *24 then *6 and return a value i then the next 2 digit to be *6 and added to the first value, finally i need the next two digits to be /10 then added to the total, the last two digits are to be ignored.

eg.,..03 02:45:00 would be ((03*24)*6)+(02*6)+(45/10) giving me and end result of 448

Could anyone help me with some pointers for Visual Basic code to do this?
2 Solutions
I'm not really sure I follow what you're trying to accomplish, but this seems to arrive at the same value.

Dim intData As Integer
Dim strData as String
strData = "03 02:45:00"
intData = (CInt(Left(strdata, 2)) * 24 * 6) + (CInt(Mid(strdata, 4, 2)) * 6) + (CInt(Mid(strdata, 7, 2)) / 10)
Msgbox intData

hi this will do this

Dim str As String
str = "03 02:45:00"

Dim strarr() As String
Dim strarr2() As String

'' first split on space
strarr = Split(str, " ")
'' then split on :
strarr2 = Split(strarr(1), ":")

Dim result As Integer

result = ((CInt(strarr(0)) * 24) * 6) + (CInt(strarr2(0)) * 6) + (CInt(strarr2(1)) / 10)

Debug.Print result
dr_duddAuthor Commented:
Worked it out myself :-P

Dim days As String
Dim daysint As Integer
Dim hours As String
Dim hoursint As Integer
Dim minutes As String
Dim minutesint As Integer
Dim length As Integer

days = .GetString(2)
daysint = days.Substring(0, 2)
daysint = (daysint * 24) * 6
hours = .GetString(2)
hoursint = hours.Substring(3, 2)
hoursint = (hoursint * 6)
minutes = .GetString(2)
minutesint = minutes.Substring(6, 2)
minutesint = (minutesint / 10)
length = daysint + hoursint + minutesint

Could a moderator please close the question.
It helps if you identify in a non-coding-language-specific topic which language you're using.
By declaring that youw were using visual basic, it was assumed, that you meant vb6.

"Could a moderator please close the question."

Moderators don't continually monitor threads, you need to post such a request in http:/Community_Support/
Just click split points and divide them between the comments that were actual answers, CS has lots to do
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now