Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 30th, 2008, 08:35 PM
Newbie
 
Join Date: Aug 2008
Posts: 5
Default help me plz,this about arrays

use one dimensional arrays to solve the following problem .read in 20 number ,each of which is between 10 and 100 inclusive . as each number is input print it only if it is not a duplicate of number already input .provide for the worst case in which all 20 numbers are different,
i want this in VB6.plz help me .
i would be thanks for any help.
Reply
  #2  
Old August 31st, 2008, 04:09 PM
Member
 
Join Date: Aug 2008
Location: Sao Paulo - Brasil
Age: 52
Posts: 71
Default

Hello.

May be using a List of Integer is a better and clean solution.

Try this

CODE
Dim myNumber As New List(Of Integer)
Dim iTmp As Integer

Private Sub getNumber() 'Create your own way to get the number
iTmp = 0
iTmp = InputBox("Type a number: ", "Give a try")

If myNumber.Contains(iTmp) Then
'You already have this number
'Do what you need to do
MessageBox.Show("Number is already there. Try again.")
Else
'You do not have the number into you list
myNumber.Add(iTmp)
MessageBox.Show("Number included.")
End If
End Sub

Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
getNumber()
End Sub
Reply
  #3  
Old August 31st, 2008, 04:22 PM
Member
 
Join Date: Aug 2008
Location: Sao Paulo - Brasil
Age: 52
Posts: 71
Default

Hello, just in case you realy want to use array...

CODE
Public Class Form1

Dim aMyArray(20) As Integer
Dim iTmp As Integer
Dim iNumItems As Integer
Dim bExist As Boolean = False

Private Sub getNumber() 'Create your own way to get the number
'Initialization
iTmp = 0
iNumItems = aMyArray.Length

iTmp = InputBox("Type a number: ", "Give a try")

For jTmp As Integer = 0 To iNumItems - 1
If aMyArray(jTmp) = iTmp Then
'You already have this number
'Do what you need to do
bExist = True
MessageBox.Show("Number is already there. Try again.")
Exit For
End If
bExist = False
Next

If Not bExist Then 'Adds the number to array
aMyArray(iTmp) = iTmp
End If

End Sub

Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
getNumber()
End Sub
End Class
Reply
  #4  
Old September 1st, 2008, 05:45 PM
Newbie
 
Join Date: Aug 2008
Posts: 5
Default

thank for your help that was helpful ,so thanks very much
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles