Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2005, 03:21 PM
Authorized User
 
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Finding minimum in array

If I declare : Dim myArray() As Double, how can i find minimum in this array if i'm looking for date??
For example: array must contain date of birth and im looking for oldest person in array.
I'm using textboxes to fill the array.
Please help me!!!!

 
Old April 28th, 2005, 03:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

first of all.. if you are using dates declare it like dates ;)

second.. start with a value (for example today if you are looking for older dates) and then go through all the array, cheking if the date if older than what you have, and if it is then replace the one you have..

HTH

Gonzalo
 
Old April 28th, 2005, 05:04 PM
Authorized User
 
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your time but how can i compare dates?
I have Structure "Person" with 3 element.2 strings and date,then i declared array(Dim array() As Person).I need to fill it with 5 persons with textboxes(txtFirstname,txtLastname,txtDate)Then i'm looking for oldest person in this array and longest first and last name.This is what i was looking for.
If you know how can i do this please tell me!
thanks...

 
Old April 28th, 2005, 05:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

use this...

DateTime.op_LessThan(t1, t2)

where t1 and t2 are datetime objects

true if t1 is less than t2; otherwise false...


HTH

Gonzalo
 
Old April 28th, 2005, 05:15 PM
Authorized User
 
Join Date: Feb 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you don't understand me:)
I have 5 persons with 5 diferent dates of birth.
I need to find the oldest one in array.
I think i cleared this up to you.
now can you help me?

 
Old April 28th, 2005, 05:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You are going to have to do what you are trying to avoid- Loop through the list and find the date that's lowest.


Hal Levy
I am here to help you, not do it for you.
That is, unless you hire me. I am looking for work.
 
Old April 29th, 2005, 10:27 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I believe you can compare dates directly, using standard comparison operators.

Let’s say you have
Code:
    Dim tmpDate As Date
and your array, arr(), is loaded with simple dates (and is declared as an array of Dates). Let's further assume the number of elements is not more than an Integer can ID (a pretty safe assumption). Then, to ID the oldest:
Code:
    Dim i        As Integer
    Dim OldestID As Integer
    Dim tmpDate  As Date

    i = LBound(arr)
    OldestID = i    ' If no older date’s found, you’ll end up with this.

    For i = LBound(arr) + 1 To UBound(arr)
        If arr(i) > arr(OldestID) Then
            OldestID = i
        End If
    Next i
    Now Oldest ID is pointing to the oldest date, if there were no duplicates, or the first of the duplicates if there are any.

Does that help?
 
Old April 29th, 2005, 10:56 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

draganmit,

you should implement IComparable in your person class,

take a look at this thread,it has a student class it implements IComparable..

I think it could give you the idea.

keep in touch.

_____________
Mehdi.
software student.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Office 2003 absolute minimum w/VSTO? cjkoontz Visual Studio 2005 0 October 16th, 2008 10:36 AM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
Minimum Sample Code zoltac007 ASP.NET 2.0 Basics 1 May 20th, 2006 10:15 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.