Solved

String Manipulation and maths

Posted on 2006-11-16
5
280 Views
Last Modified: 2013-12-29
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?
0
Comment
Question by:dr_dudd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 250 total points
ID: 17954950
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
0
 
LVL 2

Accepted Solution

by:
amiableansari earned 250 total points
ID: 17954996

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
0
 
LVL 2

Author Comment

by:dr_dudd
ID: 17955002
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.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17955173
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/
0
 
LVL 24

Expert Comment

by:SunBow
ID: 17959199
Just click split points and divide them between the comments that were actual answers, CS has lots to do
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question