Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

String Manipulation and maths

Posted on 2006-11-16
5
Medium Priority
?
297 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 1000 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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
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:
This video teaches viewers about errors in exception handling.
Suggested Courses

715 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