PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → WM17 - no browse was initialized
WM17 - no browse was initialized
Iniciado por guest, 24,feb. 2015 06:32 - 9 respuestas
Publicado el 24,febrero 2015 - 06:32
I am trying to retrieve data from DB and populate it in a Looper using following code:
dsMyData is Data Source sSQL is string bRetCode is boolean I is int //Variables to store Student info for Populating Looper nStudentID is int sStudentName is string sStudentNum is string bIsPresent is boolean nStudentDivID is int sStudentDivName is string IF COMBO_SubjectType = "Optional" THEN //Means Optional Subject sSQL = "SELECT DISTINCT sm_id, em_serial_no, sm_fname, sm_lname, em_div_id, div_division_name FROM student_master AS sm INNER JOIN enrollment_details AS em ON (sm_id = em_sm_id) INNER JOIN div_master ON (em_div_id = div_id) WHERE (em_std_id = " + COMBO_Standards..StoredValue + " AND em_sub_id = " + COMBO_Subject..StoredValue + ") ORDER BY em_serial_no;" ELSE sSQL = "SELECT DISTINCT sm_id, em_serial_no, sm_fname, sm_lname, em_div_id, div_division_name FROM student_master AS sm INNER JOIN enrollment_details AS em ON (sm_id = em_sm_id) INNER JOIN div_master ON (em_div_id = div_id) WHERE (em_div_id = " + COMBO_Division..StoredValue + " AND em_std_id = " + COMBO_Standards..StoredValue + " AND em_sub_id = " + COMBO_Subject..StoredValue + ") ORDER BY em_serial_no;" END bRetCode = HExecuteSQLQuery(dsMyData,hQueryDefault,sSQL) IF bRetCode = True THEN IF HNbRec(dsMyData) > 0 THEN HReadFirst(dsMyData) I = 1 Info(HListItem(dsMyData,hLstAll)) FOR I = 1 _TO_ HNbRec(dsMyData) nStudentID = dsMyData.sm_id sStudentName = dsMyData.em_serial_no sStudentNum = dsMyData.sm_fname + " " + dsMyData.sm_lname bIsPresent = True nStudentDivID = dsMyData.em_div_id sStudentDivName = dsMyData.div_division_name Info(nStudentID,sStudentName,sStudentNum,sStudentDivName) //<=== Code works till here but after this line gives error //Add to Looper LooperAdd(LOOP_StudentPresenceData,I) LOOP_StudentPresenceData.ATT_StudentID = nStudentID LOOP_StudentPresenceData.ATT_StudentName = sStudentName LOOP_StudentPresenceData.ATT_StudentNum = sStudentNum LOOP_StudentPresenceData.ATT_StudentPresent = bIsPresent LOOP_StudentPresenceData.ATT_StudentDivID = nStudentDivID LOOP_StudentPresenceData.ATT_StudentDivName = sStudentDivName HReadNext(dsMyData) END //FOR i = 1 _TO_ HNbRec(dsMyData) END //IF HNbRec(dsMyData) > 0 THEN ELSE //IF bRetCode = True THEN Error("Error ",HErrorInfo()) END //IF bRetCode = True THEN But...but... is does not work. It gives the error No browse was initialized. I have been banging my head for last 2 days trying to get this code up and running without success. I am using SQLite as this is an Android app as back end.

Can someone please help here...

TIA

Yogi Yang
Publicado el 24,febrero 2015 - 07:14
Hi Yogi
Not sure but my guess would be that the loop To HnbRec(dsMyData) is clearing the buffer so the HReadNext fails

I would change the loop as follows HReadFirst(dsMyData) i= 1 WHILE HFound(dsMyData) //Do your thing HReadNext(dsMyData) END
HTH

David
Publicado el 24,febrero 2015 - 07:43
I don't think so because this WHILE code is also not working
WHILE NOT HOut(dsMyData) //Do your thing HReadNext(dsMyData) END

TIA

Yogi Yang
Publicado el 24,febrero 2015 - 07:50
Yogi .
If hNbRec() return more then 0 the you have your data, THEN
use or WHILE() or FOR (dont combine it)
You don't need "I" and hNbRec() to read data source.
if you use FOR then Hreadnext() is intruder. Don't use it. Use this code below

FOR EACH dsMyData

NEXT

or

HreadFist(dsMyData)
WHILE Hout(dsMyData) = False

HreadNext(dsMyData)
END

You can also try this.
nPosition is int = LooperAdd(LOOP_StudentPresenceData)
LOOP_StudentPresenceData[nPosition].ATT_StudentID = nStudentID
LOOP_StudentPresenceData[nPosition].ATT_StudentName = sStudentName
and so on...
Publicado el 24,febrero 2015 - 12:11
ICI,

I tried is like this
WHILE HOut(dsMyData) = False nStudentID = dsMyData.sm_id sStudentName = dsMyData.em_serial_no sStudentNum = dsMyData.sm_fname + " " + dsMyData.sm_lname bIsPresent = True nStudentDivID = dsMyData.em_div_id sStudentDivName = dsMyData.div_division_name Info(nStudentID,sStudentName,sStudentNum,sStudentDivName) //Add Item to Looper nPosition is int = LooperAdd(LOOP_StudentPresenceData) LOOP_StudentPresenceData[nPosition].ATT_StudentID = nStudentID LOOP_StudentPresenceData[nPosition].ATT_StudentName = sStudentName LOOP_StudentPresenceData[nPosition].ATT_StudentNum = sStudentNum LOOP_StudentPresenceData[nPosition].ATT_StudentPresent = bIsPresent LOOP_StudentPresenceData[nPosition].ATT_StudentDivID = nStudentDivID LOOP_StudentPresenceData[nPosition].ATT_StudentDivName = sStudentDivName HReadNext(dsMyData) END
But then the while loop is never executed.
Publicado el 24,febrero 2015 - 12:22
If I use the For Loop like this
nTotalStudents = HNbRec(dsMyData) IF nTotalStudents > 0 THEN HReadFirst(dsMyData) FOR I = 1 _TO_ nTotalStudents nStudentID = dsMyData.sm_id sStudentName = dsMyData.em_serial_no sStudentNum = dsMyData.sm_fname + " " + dsMyData.sm_lname bIsPresent = True nStudentDivID = dsMyData.em_div_id sStudentDivName = dsMyData.div_division_name Info(nStudentID,sStudentName,sStudentNum,sStudentDivName) //I get error after the above code line is executed! //Add Item to Looper nPosition is int = LooperAdd(LOOP_StudentPresenceData) LOOP_StudentPresenceData[nPosition].ATT_StudentID = nStudentID LOOP_StudentPresenceData[nPosition].ATT_StudentName = sStudentName LOOP_StudentPresenceData[nPosition].ATT_StudentNum = sStudentNum LOOP_StudentPresenceData[nPosition].ATT_StudentPresent = bIsPresent LOOP_StudentPresenceData[nPosition].ATT_StudentDivID = nStudentDivID LOOP_StudentPresenceData[nPosition].ATT_StudentDivName = sStudentDivName HReadNext(dsMyData) END //FOR I = 1 _TO_ nTotalStudents BTN_SaveAttendence..Visible = True CBOX_SelectAll..Visible = True CBOX_SelectAll..Value = True END //IF nTotalStudents > 0 THEN
Now I am getting the error message which is in a bit more elaborate form.

It is: No browse was initialized for on file.

What does this mean?

Do we have to initialize Browse for a field? If Yes then how?

TIA

Yogi Yang
Publicado el 24,febrero 2015 - 12:32
Yogi Yang,
I sometimes test a query in a separate sqlite tool or viewer to see if it returns records. Apart from WM, because it is sometimes a bit unclear how WM changes the query.
Publicado el 24,febrero 2015 - 12:45
Arie,

That is right. In fact I build my queries using SQLite Manager tool which allows me to build queries and test them.

So my queries are proper and they do return data.

TIA

Yogi Yang
Publicado el 24,febrero 2015 - 12:59
Isn't your for-loop running 1 too many, because you already start with a hreadfirst?
FOR I = 1 _TO_ nTotalStudents
should be
FOR I = 1 _TO_ (nTotalStudents-1)

To me using a FOR loop this way looks quite unusual. Why not using:
HReadFirst(dsMyData)
WHILE NOT HOut(dsMyData)
HReadNext(dsMyData)
END

or even shorter
FOR EACH dsMyData
END
Publicado el 24,febrero 2015 - 13:03
Hello Yogi

I appreciate you say it doesn't work using the read loop but putting a for/end loop in place is not the way to try and make it work.
Debug the standard read loop - without any middle part works- because that is the part to fix first
IF HreadFirst(dsMyData) WHILE NOT HOut(dsMyData) HReadNext(dsMyData) END //WHILE NOT HOut(dsMyData) END //IF HreadFirst(dsMyData)
If that does not work then the problem is in dsMydata

Regards
Al