|
-
Apr 5th, 2009, 06:15 PM
#1
Thread Starter
Lively Member
Array Task Storing Product Codes
I have to write a program to store product codes in an array. Product Codes have 6 characters and each code must be different from all the other codes. After the user enters a product code check that code has not been used already, and output an appropriate message if it has. I have no code to show you as i have no idea
Last edited by cheese0897; Apr 5th, 2009 at 06:28 PM.
-
Apr 5th, 2009, 07:51 PM
#2
Re: Array Task Storing Product Codes
For entering data you can use a TextBox and a Button, then when the user clicks the button verify there is a number in the TextBox using IsNumeric(). About the Array, (assuming it's not a fixed length array) you can initialize it like ReDim ArrName(0) in Form_Load event. Then you need to verify if the number has been entered before, use a FOR / NEXT loop to to compare every item inside the array with this number. Finally, if it's not present you can add it using ReDim Preserve ArrName(UBound(ArrName) + 1) and then ArrName(UBound(ArrName)) = TheNumber. Try this and send feedback for every trouble it could arise.
-
Apr 5th, 2009, 09:25 PM
#3
Junior Member
Re: Array Task Storing Product Codes
hi cheese is this what you mean?
Function used to find if a value exists in an Array
Code:
Public Function IsInArray(FindValue As Variant, arrSearch As Variant) As Boolean
On Error GoTo LocalError
If Not IsArray(arrSearch) Then Exit Function
If Not IsNumeric(FindValue) Then FindValue = FindValue 'FindValue = UCase(FindValue)
IsInArray = InStr(1, vbNullChar & Join(arrSearch, vbNullChar) & vbNullChar, _
vbNullChar & FindValue & vbNullChar) > 0
End Function
-
Apr 6th, 2009, 01:38 AM
#4
Thread Starter
Lively Member
Re: Array Task Storing Product Codes
i also need the code for entering and storing the product codes
-
Apr 6th, 2009, 01:46 AM
#5
Re: Array Task Storing Product Codes
 Originally Posted by cheese0897
i also need the code for entering and storing the product codes
There is a difference between asking for help with the code and asking for the code.
Is it homework? You'll learn much more if you try to do it yourself and ask specific questions when you need help.
-
Apr 6th, 2009, 03:09 AM
#6
Junior Member
Re: Array Task Storing Product Codes
yeah jcis is right... he already give the concept... refer his post #2
-
Apr 6th, 2009, 08:34 AM
#7
Thread Starter
Lively Member
Re: Array Task Storing Product Codes
i would try and do it myself but my teacher has told me nothing about arrays so i have no clue
-
Apr 6th, 2009, 01:26 PM
#8
Re: Array Task Storing Product Codes
There is a tutorial about them in the "Data Types/Variables" section of our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)
That combined with what jcis posted back in post #2 should be enough for you to make good progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|