Solved

String Manipulation and maths

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

777 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