Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:06:11+00:00 2026-05-24T05:06:11+00:00

I have a list of specific class. In this list , a position class

  • 0

I have a list of specific class.
In this list , a position class is included.
And that position class includes X and Y coordinates.
I have Current Coordinates and the coordinates in list .
I want to calculate the distance for each item in List and find which item has minimal distance.
Here is my code :

  For Each item As ITEMX In xHandle.ItemList

        Dim CurrX As Integer = txt_TrainX.Text
        Dim CurrY As Integer = txt_TrainY.Text
        Dim NextX As Integer = item.Position.x
        Dim NextY As Integer = item.Position.y

        Dim distance As Integer = DistanceBetween(CurrX, CurrY, NextX, NextY)


    Next

so distance is the distance between my coordinates and the item.
I calculate it for each item in list but how do i find the minimal one ?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:06:12+00:00Added an answer on May 24, 2026 at 5:06 am

    Create a variable for the minimal value, and check it against each value in the loop.

    You should parse the text from the controls outside the loop, it’s a waste to do that over and over again inside the loop. You should also turn on strict mode so that you don’t do implicit conversions that shouldn’t be implicit.

    Dim minimal As Nullable(Of Integer) = Nothing
    
    Dim CurrX As Integer = Int32.Parse(txt_TrainX.Text)
    Dim CurrY As Integer = Int32.Parse(txt_TrainY.Text)
    
    For Each item As ITEMX In xHandle.ItemList
    
      Dim NextX As Integer = item.Position.x
      Dim NextY As Integer = item.Position.y
    
      Dim distance As Integer = DistanceBetween(CurrX, CurrY, NextX, NextY)
    
      If Not minimal.HasValue or distance < minimal.Value Then
        minimal.Value = distance
      End If
    
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would you list out the modules that have been included in a specific
I have a list of xml elements that i need to search for specific
I have a list of puzzles that are tagged with specific Themes. Think questions
I have a list of fields/columns that comprises of Sharepoint specific fields/columns, my own
i have list of rows that user select and i want to delete them,
I want to implement a custom collection that contains instances of my class. This
I have an assembly, and I want to list all classes that inherit from
So I have this code: jQuery('div[class=someClass] :input:not(:button)').each(function() { if (input type is drop-down) {
I have a models in Django that are something like this: class Classification(models.Model): name
I have a list where I save the objects created by a specific class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.