•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 391,944 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,882 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 3981 | Replies: 3 | Solved
![]() |
•
•
Join Date: Aug 2005
Posts: 24
Reputation:
Rep Power: 3
Solved Threads: 0
hi guy,
i need this ugently.. hope someone can help me out..
i need to get data from database,
but want it to take randomly and also dont want to get data duplicate.
Ex; i get data A from DB, then there will be a next button. i wan to go next data after i click it,
and get data c, later i dont wan to get back A & C again.
i`m doing Question and Answer thing.
thanks alot..
i need this ugently.. hope someone can help me out..
i need to get data from database,
but want it to take randomly and also dont want to get data duplicate.
Ex; i get data A from DB, then there will be a next button. i wan to go next data after i click it,
and get data c, later i dont wan to get back A & C again.
i`m doing Question and Answer thing.
thanks alot..
•
•
Join Date: Nov 2005
Location: Montreal, QC (Almost)
Posts: 130
Reputation:
Rep Power: 3
Solved Threads: 9
Hi Bang2711,
First of all you are missing two .dlls in your .zip file:
XVoice.dll
ExButton.dll
Next, I see you have references to both DAO and ADODB in your project, unless you actually use both (and from what I see you are only using DAO) remove the one you are not using to avoid conflicts, OR specify which type you are using,
i.e. Dim rstdb1 As DAO.Recordset OR
Dim rstdb1 As ADODB.Recordset
Otherwise VB will pick which ever one it wants to...
Now to a possible soution.
An idea come to my mind as soon as I read your post and here it is.
Create a user defined type and a public variable of that type:
You do NOT want to set a limit here since you want to be able to resize it dynamically depending on the data in your DB.
Next you load your array with the IDs from your table PicSentenses and FALSE in the boolean part.
Then you use your random code to get the next array element to use verifying for Used, I would create a function that returns a new random number within the range of subscripts of DBWordsArr
To guard against a infinite loop I would also keep counters of how many items I have in the array and of how many I have used so far.
Whenever you visit on node of your array you set the Used flag to TRUE and then you cannot get that item back until you have gone through the entire array and reset all the Used flags to FALSE.
Hope this makes sense and that it helps
Have fun
Yomet
P.S. I have not tested this code as I just typed it here in the answer window...
First of all you are missing two .dlls in your .zip file:
XVoice.dll
ExButton.dll
Next, I see you have references to both DAO and ADODB in your project, unless you actually use both (and from what I see you are only using DAO) remove the one you are not using to avoid conflicts, OR specify which type you are using,
i.e. Dim rstdb1 As DAO.Recordset OR
Dim rstdb1 As ADODB.Recordset
Otherwise VB will pick which ever one it wants to...

Now to a possible soution.
An idea come to my mind as soon as I read your post and here it is.
Create a user defined type and a public variable of that type:
Public Type DBWords DataID As Long Used As Boolean End Type Public DBWordsArr() As DBWords
You do NOT want to set a limit here since you want to be able to resize it dynamically depending on the data in your DB.
Next you load your array with the IDs from your table PicSentenses and FALSE in the boolean part.
Set rstdb1 = db.OpenRecordset("SELECT ID FROM PicSentenses")
rstdb1.MoveLast 'Will get an accurate RecordCount
rstdb1.MoveFirst
ReDim DBWordsArr(rstdb1.RecordCount -1)
i = 0
'Unless you want to use a 1-based array
'ReDim DBWordsArr(1 to rstdb1.RecordCount)
'i = 1
While Not rstdb1.EOF
DBWordsArr(i).DataID = rstdb1!ID
DBWordsArr(i).Used = False
rstdb1.MoveNext
i = i + 1
Wend
'ALWAYS close your recordsets in VB otherwise you are prone to memory leaks, yes EVEN in VB... :)
rstdb1.Close
Set rstdb1 = NothingThen you use your random code to get the next array element to use verifying for Used, I would create a function that returns a new random number within the range of subscripts of DBWordsArr
i = GetNextElement()
While DBWordsArr(i).Used
i = GetNextElement()
Wend
Set rstdb2=db.OpenRecordset("SELECT * FROM PicSentenses WHERE ID = " & DBWordsArr(i).DataID)To guard against a infinite loop I would also keep counters of how many items I have in the array and of how many I have used so far.
Whenever you visit on node of your array you set the Used flag to TRUE and then you cannot get that item back until you have gone through the entire array and reset all the Used flags to FALSE.
Hope this makes sense and that it helps
Have fun
Yomet
P.S. I have not tested this code as I just typed it here in the answer window...
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
access avatar backup breach broadband code combo crime daniweb data data protection data transfer database design drive dropdownlist forensics government hacker hard hardware hitachi ibm internet linux medicine module net news normalization reuse security server sql storage survey terabyte web wikipedia
- retrieving a single cell of data from a MySQL database (PHP)
- How to store data in data grid to database by single mouse click in Asp.net (ASP.NET)
- copy data from excel to vb database (Visual Basic 4 / 5 / 6)
- Inserting Data into Access Database (Java)
- Unable to insert data into SQL Database (ASP)
- Filtering data from an access database (Visual Basic 4 / 5 / 6)
- Posting form data to an Oracle database (JavaScript / DHTML / AJAX)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: sql statement
- Next Thread: how to publish?


have a great day..
Linear Mode