Solved

Checking for duplicate within a 2 dimensional static array

Posted on 2004-04-13
6
246 Views
Last Modified: 2010-04-17
Hi, I'm trying to ask the user to enter a bookid within a text box.  But I want to verify that the entry hasn't been made.  It would caompre against the bookarray(arrayindex, 0) within the 2 dimensional array of records and if it isn't there, then go to the bottom and then add to the array the new entry.....
The array index was declared at the beginning of Dim bookarray(50, 5) As String.  Need some help. Thanks


Public Sub Readbookfile()
   
    arrayindex = 1
    Do While Not EOF(1)
        Input #1, strBookid, strBooktitle, strCat, strAuthor, strCost, strFlag
           
        bookarray(arrayindex, 0) = strBookid
        bookarray(arrayindex, 1) = strBooktitle
        bookarray(arrayindex, 2) = strCat
        bookarray(arrayindex, 3) = strAuthor
        bookarray(arrayindex, 4) = strCost
        bookarray(arrayindex, 5) = strFlag
        arrayindex = arrayindex + 1
    Loop
    Close #1
   
End Sub
0
Comment
Question by:PhenominAL
  • 4
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
drnick earned 250 total points
ID: 10820680
dim d as boolean
dim i as integer

d = false
for i=0 to 49
if( instr(1, bookarray(i, 0), Trim(strBookId), Text) = 0) then
 d = true;
 break;
 end if
next

if not d then

'insert

else

'already there

end if
0
 

Author Comment

by:PhenominAL
ID: 10821756
Could that be integrated into a DO WHILE LOOP? Or am I complicating it?
0
 

Author Comment

by:PhenominAL
ID: 10821764
such as ...

Private Sub AddRecord()
Dim Addbookid As String
       
        txtBookInfo(0).Text = Addbookid
        arrayindex = 1
       
        Do While Addbookid <> bookarray(arrayindex, 0)

just wanted to know if i'm starting on the right foot....



0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:PhenominAL
ID: 10821871
and I would want to add it to the last spot in the array using the ubound(bookarray(arrayindex))
0
 
LVL 5

Expert Comment

by:drnick
ID: 10823265
no, to do-looping would be ok

that last-spot-adding:
it would maybe a good idea to resize the array by using redim with preseve before going ubound
0
 

Author Comment

by:PhenominAL
ID: 10826298
Really? I thought REDIM and PRESERVE were only for dynamic arrays...how would you use them for static arrays?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now