Results 1 to 2 of 2

Thread: Possible format error?

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Possible format error?

    VB6: Forex Margin Calculator
    Creating a math prog that is trying to refine the value of the Lots text box.
    Balance = 19.00
    Leverage = 50
    Lots = 1.0
    If Balance = 19 then a for statement must decrease Lots until Lots x Leverage equals Balance. What is happening is for statement is decreasing Lots by 0.01 and Lot of 1.0 should reach .38 and change text box value to .38 and exit sub. What is happening is when lots equals .43 its saying .42999999999.

    Is there something wrong with my code?


    Dim Balance, Lots, Margin As Double
    Dim Leverage As Integer
    Const Mini = 50 '50.00
    Const Standard = 100 '100.00

    Private Sub cmdCalculate1_Click()
    Dim i As Integer
    '--- Memory ---
    Lots = txtLots1.Text
    Balance = txtBal1.Text
    If optMini1.Value = True Then Leverage = 50
    If optStandard1.Value = True Then Leverage = 100
    '--- FindLots ---
    If chkFindLots.Value = 1 Then
    Dim Fbal As Integer: Fbal = Balance
    For i = 1 To 100
    If Lots * Leverage = Fbal Then
    txtLots1.Text = Lots
    Exit Sub
    End If
    Lots = Lots - 0.01
    Next i
    End If
    'If Balance < Leverage Then 'Margins
    ' MsgBox "Leverage of $" & Leverage & ".00 is not met": Exit Sub
    'Else
    ' Margins = Balance / Leverage: lblMargins.Caption = Margins
    'End If
    End Sub

    Private Sub Form_Load()
    'Reclaim memory
    Lots = 0: ExtLots = 0: Leeway = 0: Balance = 0
    'txtBal1 = "": txtLots1 = "": lblLeeway = "": lblMargins = ""
    End Sub
    Attached Files Attached Files

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