donniedarko801
asked on
Parsing Combobox.Text to use in a TimeSpan - How?
Hello Experts,
Here's what I have and it works great!
Private dtm_Time_Preset As TimeSpan = TimeSpan.Parse("00:00:05")
Here's what I want and it doesn't work at all!
Private dtm_Time_Preset As TimeSpan = TimeSpan.Parse(cbo_Preset.
Thankx for any help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx Fernando.
By the way, could this approach ever work? Because it doesn't...
dtm_Time_Preset = TimeSpan.Parse(cbo_Hr & ":" & cbo_Min & ":" & "00")
By the way, could this approach ever work? Because it doesn't...
dtm_Time_Preset = TimeSpan.Parse(cbo_Hr & ":" & cbo_Min & ":" & "00")
If cbo_Hr and cbo_Min are ComboBox object then you need to reference the text box of the control to get the string like this:
dtm_Time_Preset = TimeSpan.Parse(cbo_Hr.Text & ":" & cbo_Min.Text & ":" & "00")
dtm_Time_Preset = TimeSpan.Parse(cbo_Hr.Text
ASKER
Genious!
No far from that, LOL :=)
Fernando, I didn't see your post when I posted mine. But you are absolutely right on.
Personally, I prefer to use the String.Format method instead of concatinating strings using "&" all over the place. So I would code the line in the post above like this:
dtm_Time_Preset = TimeSpan.Parse(String.Form at("{0}:{1 }:00", cbo_Hr.Text, cbo_Min.Text))
I find this format much easier to read and less prone to error with missing quotes, especially for SQL statements!
Personally, I prefer to use the String.Format method instead of concatinating strings using "&" all over the place. So I would code the line in the post above like this:
dtm_Time_Preset = TimeSpan.Parse(String.Form
I find this format much easier to read and less prone to error with missing quotes, especially for SQL statements!
ptakja; I agree with that the format method is much neater.
Your code works fine because the control has already been created. The author of the question is using a Private declaration which can not be used in as a local variable in a sub.
see my post.
Fernando