Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,037 questions

55,894 answers

573 users

How to calculates the distance between two decimal numbers (absolute difference) in VB.NET

1 Answer

0 votes
Imports System

Module DistanceBetweenNumbers

    ' Function that returns the distance between two decimal numbers
    Function DistanceBetween(a As Double, b As Double) As Double
        ' The distance is the absolute value of the difference
        Return Math.Abs(a - b)
    End Function

    Sub Main()

        ' Test values
        Dim x1 As Double = 100
        Dim y1 As Double = 45

        Dim x2 As Double = 100
        Dim y2 As Double = -15

        Dim x3 As Double = -100
        Dim y3 As Double = -125

        Dim x4 As Double = -600
        Dim y4 As Double = 100

        ' Print results
        Console.WriteLine("Distance between " & x1 & " and " & y1 & " = " & DistanceBetween(x1, y1))
        Console.WriteLine("Distance between " & x2 & " and " & y2 & " = " & DistanceBetween(x2, y2))
        Console.WriteLine("Distance between " & x3 & " and " & y3 & " = " & DistanceBetween(x3, y3))
        Console.WriteLine("Distance between " & x4 & " and " & y4 & " = " & DistanceBetween(x4, y4))

    End Sub

End Module


' run:
'
' Distance between 100 and 45 = 55
' Distance between 100 and -15 = 115
' Distance between -100 and -125 = 25
' Distance between -600 and 100 = 700
'

 



answered Jun 28 by avibootz

Related questions

...