Results 1 to 7 of 7

Thread: data types

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    Is there any data type that can store characters and numbers?

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    264
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    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]

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    264
    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    Thanks

  6. #6
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    264
    welcome :-)
    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

  7. #7
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    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
  •  



Click Here to Expand Forum to Full Width