|
-
Jul 11th, 2000, 03:27 PM
#1
Thread Starter
Addicted Member
Is there any data type that can store characters and numbers?
-
Jul 11th, 2000, 03:41 PM
#2
Hyperactive Member
explain please do you mean STRING for example ?
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jul 11th, 2000, 03:53 PM
#3
Thread Starter
Addicted Member
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]
-
Jul 11th, 2000, 03:59 PM
#4
Hyperactive Member
in your module you have :
date As Integer
change it to:
date As string
this should fix it ...
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jul 11th, 2000, 04:09 PM
#5
Thread Starter
Addicted Member
-
Jul 11th, 2000, 04:11 PM
#6
Hyperactive Member
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jul 11th, 2000, 04:45 PM
#7
Hyperactive Member
Need any more hints?
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...
Code:
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
I hope it helps
Paul Lewis
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|