Solved

String Manipulation and maths

Posted on 2006-11-16
5
243 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modify a small python script 19 94
print map entry 34 53
reverse digits of a number using for loop 5 36
"Black Box" Testing of Control System Software 2 17
This article will show, step by step, how to integrate R code into a R Sweave document
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now