Results 1 to 14 of 14

Thread: Addition problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    Exclamation Addition problems

    I am creating a currency converter that not only converts the currency it also adds the total amount converted together and displays it in US$. My problem is that when I enter an amount to be converted it adds it to my total converted box, but when I add another amount to be converted it replaces the first amount instead of adding them together. How can I fix this? Also, when I close the application I lose all the previous data. How can I save this? I've have heard "SaveSetting" but I don't know how to use it.
    Thanks!!!

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Post some code...

    SaveSetting is easy

    SaveSetting "AppName","SomeName","DataDescription", Data

    ex:

    Data = txtTotal.text

    SaveSetting "ConverterApp","Settings","TotalConverted",Data

    to get it back

    Data = Getsetting("ConverterApp","Settings","TotalConverted","")

    in getsetting the last entry is the 'Default' meaning if the field is not there in the registry..it will set it to this value...in this case nothing
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    I tried it...

    I tried it, but it gives me an "invalid outside procedure" error.
    Keep in mind that I don't really know what I am doing, and the book I have mentions nothing of "SaveSetting"
    here is my code below if anyone wants to look.

    Data = lblAmountSpent.Caption
    SaveSetting "Currency Converter", "Settings", "TotalConverted", Data
    Data = GetSetting("Currency Converter", "Settings", "TotalConverted", "")
    Dim rate As Currency


    Private Sub Command1_Click()
    Text3.Text = Val(Text2.Text * rate)
    Option6.Value = 0
    lblAmountSpent.Caption = Format$(Text2.Text, "currency")
    End Sub


    Private Sub Option1_Click()
    rate = 2170
    If Option1.Value = 1 Then Text3.Text = rate * Text3.Text
    cboLog.AddItem Option1.Caption & Text3.Text
    End Sub
    Private Sub Option2_Click()
    rate = 2.19
    If Option2.Value = 1 Then Text3.Text = rate * Text3.Text
    End Sub

    Private Sub Option3_Click()
    rate = 7.35
    If Option3.Value = 1 Then Text3.Text = rate * Text3.Text


    End Sub

    Private Sub Option4_Click()
    rate = 0.68
    If Option4.Value = 1 Then Text3.Text = rate * Text3.Text

    End Sub

    Private Sub Option5_Click()
    rate = 1.12
    If Option5.Value = 1 Then Text3.Text = rate * Text3.Text
    End Sub

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    hmmm.. are you using VB6?

    is it erroring on the Savesetting?

    also...Dont use SaveSetting...then GetSetting right after that..

    When you close the app (Form_unload) use the
    SaveSetting to store the value

    then in the Form_Load() event use the GetSetting to retrieve it.



    try this...
    start a new project...
    add a command button

    paste this code in

    VB Code:
    1. Private Sub Command1_Click()
    2. MsgBox GetSetting("MyApp", "Startup", "Left", "")
    3.  
    4. End Sub
    5.  
    6. Private Sub Form_Load()
    7. SaveSetting "MyApp", "Startup", "Left", 50
    8. End Sub

    then run it..and click the button..does it show 50?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    it does...

    It does say 50...I am using VB 6.
    So what does "Left" mean?
    Can I change "Left" to what I want it to save and return? Like if I want it to save and return the value of lblAmountSpent?
    Thanks

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    i think i got your problem....

    try this

    VB Code:
    1. Dim Data As String
    2. Data = Cstr(lblAmountSpent.Caption ) 'use the Cstr() to make sure its a string
    3. SaveSetting "Currency Converter", "Settings", "TotalConverted", Data

    savesetting only allows a string to be entered...so that may be why it broke before...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    still get error message...

    I still get the same error message...Do you think I am putting the code in the wrong place? Also, If I use the SaveSetting will it help me keep a running total of amount converted. Now if I put in $600 dollars and convert it and then convert another $300 it will not add the two, it just replaces the first number. I attached my program files if you want to take a look...
    Thanks for all you help so far!!!

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    add it to the combo box?

    (I found the first problem...you have the code in the general declarations section)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    where...

    Where should I put the code? Under the Command button or the AmountSpent label?

  10. #10
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    hang on..I see what your doing...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  11. #11
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ok here... all fixed..and a few tweaks

    a delete button to clear the total

    and a formatted textbox to display the converted amounts nicley


    you still have to finish adding to the combo box
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    Awesome!!!

    thank you, I see what's happening now. Thanks for leaving the comments in there. I got the Converted amount and type to add in the combo box but there is no space between them. (ie Euro2436 instead of Euro 2436.
    the i wrote is
    cboLog.Additem Option1.Caption + text2.text

    i tried to do it this way but i keep getting errors.
    cboLog.Additem Option1.Caption + & " " & text2.text

    I thought the &" "& would be a space.

    But anyway thank you very much!!!

  13. #13
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    you were close.
    never use + to concantinate (spelling?) (add) 2 strings together always use &

    cboLog.Additem Option1.Caption & " " & text2.text

    I removed the + from that line..that should work fine
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    8

    yep I got it...

    Thanks, How would I set an error message to appear if the user does not have a currency type selected?

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