Results 1 to 8 of 8

Thread: Array Task Storing Product Codes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2009
    Posts
    76

    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.

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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.

  3. #3
    Junior Member
    Join Date
    Dec 2007
    Posts
    24

    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2009
    Posts
    76

    Re: Array Task Storing Product Codes

    i also need the code for entering and storing the product codes

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Array Task Storing Product Codes

    Quote Originally Posted by cheese0897 View Post
    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.

  6. #6
    Junior Member
    Join Date
    Dec 2007
    Posts
    24

    Re: Array Task Storing Product Codes

    yeah jcis is right... he already give the concept... refer his post #2

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2009
    Posts
    76

    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

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width