Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

avoid dataset iteration 2x

Status
Not open for further replies.

cjburkha

Programmer
Jul 30, 2004
76
0
0
US
Hi,

I am making a faq page and questions and answers are stored in a record of a db.

I have this faqDS, but I can't find a way to avoid looping the ds 2x.

Code:
for i = 0 to faqDS.tables(0).rows.count - 1
    createQuestion(faqDS.tables(0).rows(i).item("question")
next i

for i = 0 to faqDS.tables(0).rows.count - 1
    createAnswer(faqDS.tables(0).rows(i).item("answer")
next i

This is a problem I have seen before, needing to do something with one row of each collumn of ds, then something else with a diff row of each collumn.

Maybe this is bad data-design? but even splitting into two tables, I still have two loops.

I could store my info in an array
Code:
for i = 0 to faqDS.tables(0).rows.count - 1
   allQuestions(i) = item("question")
   allAnswers(i) = item("ansewer")
next i

but now I actually have 3 loops. ^^

Any hints or tips are appriciated,

CJB
 
Can't you do this?

for i = 0 to faqDS.tables(0).rows.count - 1
createQuestion(faqDS.tables(0).rows(i).item("question")
createAnswer(faqDS.tables(0).rows(i).item("answer")
next i

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
In a way I can. The problem is, I need to do ALL createQuestion before I do ANY createAnswer.

I can do a temp state :

Code:
dim questionString as string = ""
dim answerString as string = ""

for i = 0 to faqDS.tables(0).rows.count - 1
    questionString += createQuestion(faqDS.tables(0).rows(i).item("question")
   answerString += createAnswer(faqDS.tables(0).rows(i).item("answer")
next i

realAnswer = questionString
realAnswer += answerString
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top