473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with loops

Hello, I have two problems I’m having trouble solving. The first involves a program that opens a text file with a bunch of random numbers out of order listed line by line. I have to list the Highest and the second Highest in a list box using loops and if statements. I had no trouble figuring out how to get the highest but how do I go about generating the second highest. The code is listed below.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
  2.         Dim SR As IO.StreamReader = IO.File.OpenText("BID.TXT")
  3.         Dim Bids As Double
  4.         Dim Highest As Double = 0
  5.         Dim SecondHighest As Double
  6.  
  7.         Do While (SR.Peek <> -1)
  8.             Bids = CDbl(SR.ReadLine)
  9.  
  10.             If Bids > Highest Then
  11.                 Highest = Bids
  12.             End If
  13.         Loop
  14.         SR.Close()
  15.  
  16.  
  17.  
  18.         lstdisplay.Items.Add("The Highest Bid is: " & FormatCurrency(Highest))
  19.  
  20.  
  21.  
  22.  
  23.     End Sub
The second problem I am having is similar to the first but I have another text file that consists of a bunch names that are listed in Alphabetical order. Some of the names are repeated more than once. I have to use loops and if statements to display the file of names but for those that are repeated in the text file only list once. I have no clue how to go about doing this one. Any help would be great.
Thanks.
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim SR As IO.StreamReader = IO.File.OpenText("NAMES.TXT")
  3.         Dim Name As String
  4.  
  5.  
  6.         Do While (SR.Peek <> -1)
  7.             Name = SR.ReadLine
  8.  
  9.  
  10.         Loop
  11.  
  12.  
  13.  
  14.     End Sub
May 2 '08 #1
2 1058
kadghar
1,295 Expert 1GB
Check line 10
Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
  2.         Dim SR As IO.StreamReader = IO.File.OpenText("BID.TXT")
  3.         Dim Bids As Double
  4.         Dim Highest As Double = 0
  5.         Dim SecondHighest As Double
  6.  
  7.         Do While (SR.Peek <> -1)
  8.             Bids = CDbl(SR.ReadLine)
  9.             If Bids > Highest Then
  10.                 secondHighest = Highest 'Yeah!, thats it.
  11.                 Highest = Bids
  12.             End If
  13.         Loop
  14.         SR.Close()
  15.         lstdisplay.Items.Add("The Highest Bid is: " & FormatCurrency(Highest))
  16.  
  17.     End Sub
^.^ For the other one, aplies the same thing.
May 2 '08 #2
Hey thanks a lot!!!
You defiantly helped me out.
May 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
1
by: Kolus Maximiliano | last post by:
Hello, I don't know if this is *entirely* a postgresql question or if it's my screwup with the database design. First, a little introduction to the problem: I maintain a database of open...
3
by: Sean Shanny | last post by:
To all, We are running postgresql 7.4.1 on an G5 with dual procs, OSX 10.3.3 server, 8GB mem, attached to a fully configured 3.5TB XRaid box via fibre channel. I think we have run into this...
15
by: Együd Csaba | last post by:
Hi All, I've a problem with the perfprmance of the production environment. I've two db servers. One on my laptop computer (2Ghz, 1GB, WinXP, Cygwin, Postgres 7.3.4) and one on a production server...
4
by: Giovanni Bajo | last post by:
Hello, I found this strange: python -mtimeit "sum(int(L) for L in xrange(3000))" 100 loops, best of 3: 5.04 msec per loop python -mtimeit "import itertools; sum(itertools.imap(int,...
13
by: andreas | last post by:
Hi, I want to do some calculation like ( t1 and t2 are known) for i = t1 to t2 for j = t1 to t2 ..... ..... for p = t1 to t2 for q = t1 to t2
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
9
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
0
by: GeniusTse | last post by:
Hi all, I found a big performance difference between two query with different "Limit" and I think it is not make sense Table: person_item PKey: (person_id, time) Index: (time) Query1)...
3
by: Ri0o | last post by:
hi, i have to make a sudoku solver using python quickdraw, i've started on it and this is what i got so far here is the link to the assignment...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.