3 Replies - 849 Views - Last Post: 12 December 2015 - 11:18 AM Rate Topic: -----

#1 HarveyJHamilton   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-December 15

Debugging Help with My Currency Calculator in VB6

Posted 11 December 2015 - 06:43 AM

Hello, I have been learning VB6 for about 4-5 weeks now and for an assignment for my college course you have to code a currency calculator for Euros, Dollars and Pounds. The program also has to have another form where exchange rates can be changed from that form using a button and text boxes. You also have to create a password form to access that form to change the exchange rates. I have done all the main coding and I am currently 'validating' the code (I think it is called validating). The problem is that if the user of the program clicks the update button on the exchange rate changing form whilst all the text boxes are empty, I get an error.
Here is a screen shot of the error and the GUI of each form -
The Error
https://gyazo.com/4b...0ee9e0fc28cf422
Form 1, The Currency Exchanging Form
https://gyazo.com/94...58c03192dc6da4e
Password, The Password Form
https://gyazo.com/ce...f5a3b1b107db9ba
Form 2, The Exchange Rate Editor Form
https://gyazo.com/a6...b5473a5dbd8c10d

Also, here is the code for Form 2.
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click

        ' These six If statements are to move the value of the text boxs on form 2 into the global variables found in the Global Variable Rates class. The If statements are used to say that if any of the text boxes are blank, then the values within the global variables stay the same
        If txtGBPtoUSD.Text = "" Then
            Global_Variable_Rates.GBPtoUSD = Global_Variable_Rates.GBPtoUSD
        Else
            Global_Variable_Rates.GBPtoUSD = txtGBPtoUSD.Text
        End If

        If txtGBPtoEUR.Text = "" Then
            Global_Variable_Rates.GBPtoEUR = Global_Variable_Rates.GBPtoEUR
        Else
            Global_Variable_Rates.GBPtoEUR = txtGBPtoEUR.Text
        End If

        If txtUSDtoGBP.Text = "" Then
            Global_Variable_Rates.USDtoGBP = Global_Variable_Rates.USDtoGBP
        Else
            Global_Variable_Rates.USDtoGBP = txtUSDtoGBP.Text
        End If

        If Global_Variable_Rates.USDtoEUR = "" Then
            Global_Variable_Rates.USDtoEUR = Global_Variable_Rates.USDtoEUR
        Else
            Global_Variable_Rates.USDtoEUR = txtUSDtoEUR.Text
        End If

        If Global_Variable_Rates.EURtoGBP = "" Then
            Global_Variable_Rates.EURtoGBP = Global_Variable_Rates.EURtoGBP
        Else
            Global_Variable_Rates.EURtoGBP = txtEURtoGBP.Text
        End If

        If Global_Variable_Rates.EURtoUSD = "" Then
            Global_Variable_Rates.EURtoUSD = Global_Variable_Rates.EURtoUSD
        Else
            Global_Variable_Rates.EURtoUSD = txtEURtoUSD.Text
        End If
    End Sub



I used If statements to try and fix the problem of having empty text boxes, but they don't seem to help.
Any help will be extremely appreciated.
Thank you,
- Harvey

Is This A Good Question/Topic? 0
  • +

Replies To: Debugging Help with My Currency Calculator in VB6

#2 Neku   User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 269
  • Joined: 21-May 09

Re: Debugging Help with My Currency Calculator in VB6

Posted 12 December 2015 - 08:37 AM

what is the exact error that you get?
looking at this code, it seems it should work properly where the only problem is not when the textbox is empty but when it has space or invaild characters in it.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Debugging Help with My Currency Calculator in VB6

Posted 12 December 2015 - 09:09 AM

Quote

Hello, I have been learning VB6 for about 4-5 weeks now

No you haven't, that's VB.NET. Topic moved to VB.NET forum.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Debugging Help with My Currency Calculator in VB6

Posted 12 December 2015 - 11:18 AM

Note that these statements
Global_Variable_Rates.GBPtoUSD = Global_Variable_Rates.GBPtoUSD

are redundant, they don't achieve anything.

You need to tell us what line the error (InvalidCastException, string "" to double) occurs on.

The error itself is because the empty string "" won't automatically be converted to a double 0.0.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1