none
how to gnore Negative signal in excel RRS feed

  • Question

  • hi

    I want to find the difference between the two columns of the excel when exporting data from the Datagrid View with the negative signal ignored
    The following code works but does not delete the negative sign

    For I = 2 To excelWorksheet.UsedRange.Rows.Count If String.IsNullOrEmpty(excelWorksheet.Range("f" & I).Value) = False AndAlso String.IsNullOrEmpty(excelWorksheet.Range("g" & I).Value) = False Then excelWorksheet.Range("h" & I).Value = "=f" & I & "-g" & I

    ' End If Next



    try code not work

     For I = 2 To excelWorksheet.UsedRange.Rows.Count
                    If String.IsNullOrEmpty(excelWorksheet.Range("f" & I).Value) = False AndAlso String.IsNullOrEmpty(excelWorksheet.Range("g" & I).Value) = False Then
                        excelWorksheet.Range("h" & Math.Abs(I)).Value = "=f" & I & "-g" & I
    
    '
                    End If
                Next

    Sunday, December 23, 2018 8:25 PM

Answers

  • What you are attempting to do should fail as you have option strict off and the compiler is deciding things for you. 

    Your logic would work in JavaScript as JavaScript understand what you are doing.

    For it to work in .NET with zero methods, only math

    Dim i As Integer = -3
    Dim result = "f" & (i * -1).ToString()

    Result is f3

    Dim i As Integer = 3
    Dim result = "f" & (i * -1).ToString()

    Result f-3


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ahmeddc Sunday, December 23, 2018 11:26 PM
    Sunday, December 23, 2018 11:10 PM
    Moderator

All replies

  • Hi

    I do not understand your question fully. There is something about 'ignoring a minus sign' which I read as finding the Absolute value of a subtraction. If so, then here is an example:

         Dim a, b As Double
        a = 1.2345 : b = 4.5678
    
        Dim res1 As Double = Math.Abs(a - b)
        ' res1 = 3.333300000000
        Dim res2 As Double = Math.Abs(b - a)
        ' res2 = 3.333300000000
    


    Regards Les, Livingston, Scotland

    Sunday, December 23, 2018 9:28 PM
  • What you are attempting to do should fail as you have option strict off and the compiler is deciding things for you. 

    Your logic would work in JavaScript as JavaScript understand what you are doing.

    For it to work in .NET with zero methods, only math

    Dim i As Integer = -3
    Dim result = "f" & (i * -1).ToString()

    Result is f3

    Dim i As Integer = 3
    Dim result = "f" & (i * -1).ToString()

    Result f-3


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ahmeddc Sunday, December 23, 2018 11:26 PM
    Sunday, December 23, 2018 11:10 PM
    Moderator