Results 1 to 7 of 7

Thread: ***RESOLVED*** Data type conversion error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Sunny Scottsdale Arizona
    Posts
    254

    ***RESOLVED*** Data type conversion error

    I need to be able to divide two currency values in an MSFlexGrid to come up with a percent value.

    The challenge is that I need to have error handling to be sure that if the user puts in a $.0 currency value I do not get an error.

    Ex.

    Private Sub MSFlexGrid1_LeaveCell()

    With MSFlexGrid1
    .TextMatrix(1, 1) = Format(.TextMatrix(2, 1) / .TextMatrix(3, 1), "0.0%")
    End With

    End Sub
    Last edited by Jefftopia; Jul 26th, 2002 at 09:07 AM.

  2. #2
    Lively Member
    Join Date
    Jul 2002
    Location
    Planet Earth
    Posts
    99

    Re: Data type conversion error

    Originally posted by Jefftopia
    I need to be able to divide two currency values in an MSFlexGrid to come up with a percent value.

    The challenge is that I need to have error handling to be sure that if the user puts in a $.0 currency value I do not get an error.

    Ex.

    Private Sub MSFlexGrid1_LeaveCell()
    Code:
    With MSFlexGrid1
               if .textMatrix(3,1) > 0 And .textMatrix(2,1) > 0 then
                .TextMatrix(1, 1) = Format(.TextMatrix(2, 1) / .TextMatrix(3, 1), "0.0%")
               End
    End With
    End Sub

    You may need to convert the values to decimals...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    In addition to what SoCalled said, I'd create variables, do the math in memory with the variables, and then write the results back to the appropriate column in my grid.

  4. #4
    Lively Member
    Join Date
    Jul 2002
    Location
    Planet Earth
    Posts
    99
    Originally posted by Hack
    In addition to what SoCalled said, I'd create variables, do the math in memory with the variables, and then write the results back to the appropriate column in my grid.
    Nice, am thinking you mean this would be more efficient, since l would imagine vb would have to locate each value in the memory array, as opposed to having a single memory location for each value.

    Would also make the code easier to read and reduce the likelyhood of bugs.

  5. #5
    Member
    Join Date
    Jul 2002
    Location
    CHILE
    Posts
    36
    Try this

    Private Sub MSFlexGrid1_LeaveCell()
    Dim x as Double

    With MSFlexGrid1
    if .textMatrix(3,1) > 0 And .textMatrix(2,1) > 0 then
    x = (.TextMatrix(2, 1) / .TextMatrix(3, 1)
    End
    .TextMatrix(1, 1) =format(x,"0.0%")
    End With

    End Sub

    hope that help

  6. #6
    Lively Member
    Join Date
    Jul 2002
    Location
    Planet Earth
    Posts
    99
    Setting x to 0 above the if then right....

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Sunny Scottsdale Arizona
    Posts
    254

    Cool

    thx--I am going with the variable method. Works well!

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