number from a string

  • Thread starter Thread starter Jean-Paul De Winter
  • Start date 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
 
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"
 
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
 
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"?)
 
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.
 
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
 
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
 
Back
Top