|
-
June 3rd, 2009, 03:55 AM
#1
vb6 conversion program problem
hi first of all i would like to state i am currently at college, ive been trying to get the isNumeric function to work with my Euro to pounds conversion. i can get it to work with my pounds to euro conversion, but even when i try to input numbers into the field when i have the euro to pounds option selected it says "please enter a valid number" (the message i have inputed when a user trys to input anything other than a number). heres my code, any help is much appreciated.
Code:
Option Explicit
Dim euroToSterlingRate As Currency 'declares the variable "euroToSterlingRate" as currency
Dim sterlingToEuroRate As Currency 'declares the variable "sterlingToEuroRate" as currency
Private Sub cmdChangeEuroToPoundRate_Click()
Dim EuroToPoundanswer As String 'declares the variable "EuroToPOundanswer as a string
'when the user presses the button a input box apears.
'when the user inputs a number into this input box and presses "ok",
'it changes the euro to pound conversion rate to the entered amount.
EuroToPoundanswer = InputBox("Enter the current Euro to pound coversion rate:")
If EuroToPoundanswer <> "" Then
euroToSterlingRate = EuroToPoundanswer
End If
End Sub
Private Sub cmdChangePoundToEuroRate_Click()
Dim answer As String 'declares the variable "answer" as a string
'when the user presses the button a input box apears.
'when the user inputs a number into this input box and presses "ok",
'it changes the pound to euro conversion rate to the entered amou nt.
answer = InputBox("Enter the current Pound to Euro conversion Rate: ")
If answer <> "" Then
sterlingToEuroRate = answer
End If
End Sub
Private Sub cmdClear_Click()
'when the user clicks this button the "txtConversionAmount" field is cleared
txtConversionAmount = ""
End Sub
Private Sub cmdConvert_Click()
'this button starts the conversion and displays the answer in a message box
If optPoundsToEuro.Value = True Then 'begins the if stament
Dim ConvertAmount As Single 'declares the variable "ConvertAmount" as single
Dim PoundtoEuroAnswer 'this declares the variable "PoundToEuroAnswer"
Dim userInput As String 'defines the variable "userInput" as string
userInput = txtConversionAmount.Text
If IsNumeric(userInput) Then
ConvertAmount = txtConversionAmount 'declares that the variable ConvertAmount=txtConversionAmount
'declares that the variable "PoundToEuroAnswer",
'="ConvertAmount" Multiplied by "sterlingToEuroRate".
PoundtoEuroAnswer = ConvertAmount * sterlingToEuroRate
'displays the answer of the amount converted into euros,
'followed by the word "euros".
MsgBox (PoundtoEuroAnswer & " euros")
Else
MsgBox ("please enter a valid number")
End If 'ends the if statemant
End If
If optEurosToPounds.Value = True Then
Dim EuroToPoundanswer 'this delcares the variable "EuroToPoundAnswer"
'="ConvertAmount" Multiplied by "eurotoSterlingRate"
If IsNumeric(userInput) Then
EuroToPoundanswer = ConvertAmount * euroToSterlingRate
MsgBox (EuroToPoundanswer & " pounds")
Else
MsgBox ("please enter a valid number")
End If
End If
End Sub
Private Sub cmdEuroToPoundCurrentRate_Click()
'this button displays the current Euro to pound conversion rate in a message box
MsgBox ("The Current Euro to Pound Conversion rate is: " & euroToSterlingRate)
End Sub
Private Sub cmdExit_Click()
'this button ends the program
End
End Sub
Private Sub cmdPoundToEuroCurrentRate_Click()
'this button displays the current pound to euro conversion rate in a message box
MsgBox ("The Current Pound to Euro Conversion Rate is " & sterlingToEuroRate)
End Sub
Private Sub Form_Load()
euroToSterlingRate = 2.7 'default value
sterlingToEuroRate = 4.9 'default value
End Sub
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
|