Is there any data type that can store characters and numbers?
Printable View
Is there any data type that can store characters and numbers?
explain please do you mean STRING for example ?
when I run this code It comes up with an error saying type
mismatch, but when I just put numbers in the textbox (instead of the date) it runs fine.
Private Sub Command1_Click()
Dim file As Task
file.date = Text1.Text 'here's where the error comes up
Open "c:\windows\desktop\database.txt" For Random As 1 Len = 90
Put #1, 1, file
End Sub
Private Sub Form_Load()
Text1.Text = date
End Sub
Here's the code in the module
Type Task
date As Integer
End Type
Option Explicit
Dim file As Task
[Edited by Bjwbell on 07-11-2000 at 04:57 PM]
in your module you have :
date As Integer
change it to:
date As string
this should fix it ...
Thanks
welcome :-)
If what asabi has said is all you needed to get going, then cool. If you really want to do something with that date field though, other than store whatever free text the text box had, you could think about something like the following...
You can use this example as is if you create a command button called Command1 and a Text box called Text1.
The idea here is to let VBA do all the hard work of parsing what is typed in the text box into a real date for you.
The new concepts you may not be familiar with but which you will hopefully find useful are the Date data type and the error handling.
Note that this example allows the user to type an string and recieve a date. Even if the user types 36711.25, they will get a valid date. This is because of how VB stored Dates for you which is another topic you could look up.
Try the example and see what date it comes out to...
I hope it helpsCode:Private Sub Command1_Click()
' decalre the variable myDate as the correct type
Dim mydate As Date
' set up a local error handler
' this tells VB to note the error number but not to stop
' running if an error does happen. Just go on to the
' Next command
On Error Resume Next
' cdate will try to convert anything to a Date
' if it fails, an error will happen
mydate = CDate(Text1.Text)
' handle any error trapped. VB stored any error in the
' previous code as "Err". You can look for that in the
' VB help if you want to
If Err <> 0 Then
' just make sure that date is set to some default
mydate = 0
End If
'cancel the local error handler
On Error GoTo 0
' show the user what was typed as a real date
MsgBox "Date = " & mydate
End Sub
Paul Lewis