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
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.
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
Re: Array Task Storing Product Codes
i also need the code for entering and storing the product codes
Re: Array Task Storing Product Codes
Quote:
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.
Re: Array Task Storing Product Codes
yeah jcis is right... he already give the concept... refer his post #2
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
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.