Results 1 to 7 of 7

Thread: Why do i get a Type mismatch error?

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question

    Hello, i am remaking this Temperature converter program to convert Feherinhite to Celcis and well i have a bug and i don't know what i have done wrong, and i get an error that says "type mismatch error" and i was like hm....does that mean i dimmed the wrong way like, somthing shoulda been a string insteed of a integer but then i took them all to varient and i still get an error but this time it says, "ByRef type mismatch", i had to working with this other code but i wanted to try and experiment with Functions insteed of just writing it all in the form load even producer, here is the code i wrote so far.
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim FTemp As Integer          'faherenhite temp
    Dim CTemp As Integer          'Celcis Temp
    Dim Prompt As String          'Message
    
    Prompt = "Please Enter your Feherinhite degree to be converted to Celcis."
    Do
        FTemp = InputBox(Prompt, "Feherinhite to Celcis")
        If FTemp <> "" Then
        CTemp = ConversionFtoC(FTemp)
        MsgBox (CTemp), , "Celcis Degree"
        End If
        Loop While FTemp <> ""
    
    End Sub
    
    Public Function ConversionFtoC(X As Integer)
    ConversionFtoC = Int((X - 32) * 5 / 9)

  2. #2
    Guest

    Quick answer, maybe wrong but.....

    X looks like it may not always be an integer or whole number try declaring as something else

  3. #3
    Guest
    You are passing an argument ByRef. Pass the arguement ByVal on the line that you get an error on.

    I'm pretty sure it should look something like this.

    Code:
    Public Function ConversionFtoC(ByVal X As Integer)

  4. #4

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Hey thanks Jethro, that did the trick!

    hey thanks, all i had to do was change the X to a varient insteed of an integer,
    X is the value of Fahernhite!
    For instance:
    Code:
    Public Function ConversionFtoC(X As Integer)
    ConversionFtoC = Int((X - 32) * 5 / 9) ' X is wahtever number the inputbox puts in, like say i type in 32 that will make that X = 32 and then the FUnction will be (32-32)*5/9) adn that will = 0 degrees celcis! i don't think i have been spelling celcis right... but anyways i think that answers your question, and thanks for answering mine!

  5. #5
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Use SINGLE type variables instead of INTEGERs

    DocZaf
    {;->
    If you get an OVERFLOW error (which you might - change to type DOUBLE variables)

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Your problem is in the line If FTemp <> "" Then where you are trying to compare an Integer (FTemp) with a string (""). You also have a problem if you enter non-numeric data. Try this instead:
    Code:
    Dim FTemp As Integer          'faherenhite temp
    Dim CTemp As Integer          'Celcis Temp
    Dim Prompt As String          'Message
    Dim strInput As String
    
    Prompt = "Please Enter your Feherinhite degree to be converted to Celcis."
    Do
        strInput = InputBox(Prompt, "Feherinhite to Celcis")
            If strInput <> "" Then
                If Not IsNumeric(strInput) Then
                    MsgBox "Not numeric, try again"
                Else
                    CTemp = ConversionFtoC(CInt(strInput))
                    MsgBox (CTemp), , "Celcis Degree"
                End If
            End If
    Loop While strInput <> ""

  7. #7
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Thumbs up

    Try this... Hope nobody else has already answered but my computer is locking on me so I can't tell:

    Code:
    Public Function ConversionFtoC(X As Integer)
    ConversionFtoC = Int((X - 32) * 5 / 9)
    End Function
    
    Public Sub Display()
    Dim FTemp                     'faherenhite temp
    Dim CTemp As Integer          'Celcis Temp
    Dim Prompt As String          'Message
    
    Prompt = "Please Enter your Feherinhite degree to be converted to Celcis."
    Do While LCase(FTemp) <> "done"
    FTemp = InputBox(Prompt, "Feherinhite to Celcis")
    If LCase(FTemp) <> "done" Then
            MsgBox ConversionFtoC(Int(FTemp)), , "Celcis Degree"
    End If
    Loop
    End Sub
    
    Private Sub Form_Load()
    Display
    End Sub
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

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