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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need recommendation on a good VB Book!!!

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
I'm new with Visual Basic and I guess I need all the help I can get. I have this simple code to format the user entry into a date format (mm/yy/dd).
<code>
Private Sub dob_LostFocus()
Dim b As Date
b = dob.Text
dob.Text = Format(b, &quot;m/d/yy&quot;)
End Sub
</code>
it does format the text entry but it shows the wrong date.
ie. user entry: 030285 format: 12/10/92

Any help will be greatly appreciated. I also need recommendation on a good VB book.
 
If you reference the windows common controls you will get a date picker which allows the user to pick a date from a calender, this is the easiest way to ensure you get the correct date format you require.

You can also bind the control to your data source like a normal text box.

The controls properties include date formats ect ect.

My favorite book on VB is the Microsoft Press Programming Microsoft Visual Basic 6.0 by Francesco Balena.

According to the back cover it is £56.99 here in the UK, it is $59.99 in the US or $89.99 in Canada

 
The value that you enter in the text box is considered as a number rather than a Date. As such its value is interpreted as the number of days passed since Jan 1, 1900.

So the first thing you have to do is to make sure Vb understands this number as a Date e.g. by inserting at the appropriate places a &quot;/&quot; sign. This is exactly what the following code does:

Private Sub Text1_LostFocus()
With Text1
Dim EditedDate As String
EditedDate = Left$(.Text, 2) &amp; &quot;/&quot; &amp; Mid$(.Text, 3, 2) &amp; _
&quot;/&quot; &amp; Right$(.Text, 2)
.Text = Format(EditedDate, &quot;m/d/yy&quot;)
End With
End Sub


Text1 is the name of the Text box into which you enter the date.

Of course it would be easier if the Edited Date was directly entered into the text box!
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
A great beginner's Visual Basic book I would strongly recommend is Visual Basic 6.0 Step by Step by Microsoft Press. It comes with the VB6 Learning Edition. You learn the basics and create some very fun projects along the way. WROX also has an excellent VB6 beginner's book.
 
I would strongly recomend that you buy Beginning Visual Basic 6 by Peter Wright at Wrox Press. It's $49.99 but it's worth every penny.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top