number from a string

  • Thread starter Jean-Paul De Winter
  • Start date
J

Jean-Paul De Winter

Hi,
How to get the number 800 out of the string 8:00
or 850 out of 8:30....
Thanks
 
S

Stuart McCall

Jean-Paul De Winter said:
Hi,
How to get the number 800 out of the string 8:00
or 850 out of 8:30....
Thanks

I'm going to assume 850 was a typo. The easiest way is to use the Replace
function to remove the colons:

Result = Replace("8:30", ":", "")
Debug.Print Result --> "830"
 
J

Jean-Paul

No it's not a typo...
The result of your code is a new string, not a number so it should be
830 instead of "830"
JP
 
S

Stuart McCall

Jean-Paul said:
No it's not a typo...
The result of your code is a new string, not a number so it should be 830
instead of "830"
JP

Ok, so convert it to the data type you want, ie:

lngResult = Clng(Replace("8:30", ":", ""))
or
intResult = Cint(Replace("8:30", ":", ""))

etc.

(PS - how did you expect to get 850 from "8:30"?)
 
M

Mike Painter

Stuart said:
Ok, so convert it to the data type you want, ie:

lngResult = Clng(Replace("8:30", ":", ""))
or
intResult = Cint(Replace("8:30", ":", ""))

etc.

(PS - how did you expect to get 850 from "8:30"?)

If 850 means 8.5 it's back to the drawing board.
 
J

Jean-Paul

I understand you must be all curious about the reason why I want to
change "8:30" into 850.

I must admit it looks strange and it probably is.

It all has to do with a program I currently work on and all has to do
with "making appointments" and setting it all out in a week-view layout.

I posted a question a few days ago to get some tips but haven't got much.

Thank you all for your kind help
If you guys have ideas about previous mails, let me know
JP
 
M

Mike Painter

If 850 means 8:30, then you need to use split to pick the string apart
Dim MyTimeIsYourTime as String
MyTimeIsYourTime= Split([yourTime],":")
MyTimeIsYourTime(1) = Int((MyTimeIsYourTime(1)/60)*100)
YourTime = Join(MyTimeIsYourTime, "")

MyTimeIsYourTime(0) will contain the hours and if I got the parenthesis
right MyTimeIsYourTime(0) will contain a two digit number wqhich is the
fraction time 100.
Note that the Join function has a zero length string as the delimiter.

Jean-Paul wrote:> I understand you must be all curious about the reason why
I want to
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top