|
-
Jun 21st, 2000, 06:07 AM
#1
Thread Starter
Registered User
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)
-
Jun 21st, 2000, 06:23 AM
#2
Quick answer, maybe wrong but.....
X looks like it may not always be an integer or whole number try declaring as something else
-
Jun 21st, 2000, 06:26 AM
#3
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)
-
Jun 21st, 2000, 06:29 AM
#4
Thread Starter
Registered User
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!
-
Jun 21st, 2000, 06:30 AM
#5
Fanatic Member
Use SINGLE type variables instead of INTEGERs
DocZaf
{;->
If you get an OVERFLOW error (which you might - change to type DOUBLE variables)
-
Jun 21st, 2000, 06:32 AM
#6
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 <> ""
-
Jun 21st, 2000, 06:37 AM
#7
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|