Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split contents into 3 fields 1

Status
Not open for further replies.

CupraSA

Technical User
Mar 14, 2009
10
0
0
ZA
Hi,

This is probably such a simple thing to do but i just dont know how...

txtDateRecieved.Text = mobjADORst.Fields("DATERECIEVED")
which contains "2009/10/01 11:23"

I need to split the contents into 3 fields:
txtDate should contain "2009/10/01"
txtHour should contain "11"
txtMinu should contain "23"

I figured out how to populate the first field by doing the following:
Dim Sdate As String * 10

but how do I get the time to populate into the other 2 fields?

thanks
 
There are various ways to do this. I would suggest you do a little research on the following functions....

Format
Hour
Minute



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks you got me thinking. ok so the following does the trick

Code:
    Dim Sdate As String * 10
    Dim Shour As String
    Dim Smin As String

    Sdate = txtDateRecieved.Text
    Shour = mobjADORst.Fields("DATERECIEVED")
    Smin = mobjADORst.Fields("DATERECIEVED")
    
    txtDate.Text = Sdate
    txtHour.Text = Hour(Shour)
    txtMin.Text = Minute(Smin)
 
There is a better way.

Code:
Dim MyDate As Date

myDate = cDate(mobjADORst.Fields("DATERECIEVED"))

txtDate.Text = Left$(myDate, 10)
txtHour.Text = Hour(myDate)
txtMin.Text = Minute(myDate)

There are a couple reasons why this is better. First, there is only one declared variable, so this will use less memory (only slightly less). Second, this method gets the data from the recordset object just once. Getting data from the recordset object is slower than getting data from a locally declared variable.

Now, please don't misunderstand me. I'm not suggesting that this method is going to be noticeably faster, or use noticeably less memory. You will not notice the difference at all. But... there may come a time where you need to do something similar in a loop. With enough iterations, the difference in memory and execution speed may become noticeable.

More importantly, I'm glad my brief suggestion in my original response was able to help.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top