Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
16
Erster Beitrag:
vor 3 Jahren, 1 Monat
Letzter Beitrag:
vor 2 Jahren, 10 Monaten
Beteiligte Autoren:
Yogi Yang, DerekT, Fabrice Harari, Bart VDE

WM17-Last Element in Looper Control returns wrong value

Startbeitrag von Yogi Yang am 07.10.2014 08:09

I am show user a list of values in a Looper Control which are names (string) and True/False values (boolen) as check box. When the data is loaded in Looper by default the checkbox is always checked.

Here the user can check or uncheck as per their needs and update the data.

When the user clicks update button it does not update the last element (in this case checkbox) data correctly. What must be the problem? Is there any bug in the WM17?

I am developing for Android.

Here is the code:

FOR I = 1 TO LOOP_StudentPresence..Occurrence
IF LOOP_StudentPresence.CBOX_StudentPresent..Value = 1 THEN
IF Length(sSQL) > 0 THEN
sSQL = sSQL + "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence.STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 1, am_date='" + EDT_Date + "';"
ELSE
sSQL = "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence.STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 1, am_date='" + EDT_Date + "';"
END
ELSE
IF Length(sSQL) > 0 THEN
sSQL = sSQL + "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence.STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 0, am_date='" + EDT_Date + "';"
ELSE
sSQL = "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence.STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 0, am_date='" + EDT_Date + "';"
END
END //IF LOOP_StudentPresence.CBOX_StudentPresent..Value = True THEN
END //FOR I = 1 TO LOOP_StudentPresence..Occurrence



TIA

Yogi Yang

Antworten:

Hi,

I think you should use your indexer "I" in your statements in the looper


Regards,
Bart

von Bart VDE - am 07.10.2014 09:15
I have used "I" indexer in Looper but some how the code after pasting in the editor seems to get changed?

It seems the code parser is removing the square braces. :(.

I am pasting the code again but replacing the square braces with default round braces:

FOR I = 1 TO LOOP_StudentPresence..Occurrence
IF LOOP_StudentPresence(I).CBOX_StudentPresent..Value = 1 THEN
IF Length(sSQL) > 0 THEN
sSQL = sSQL + "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence(I).STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 1, am_date='" + EDT_Date + "';"
ELSE
sSQL = "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence(I).STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 1, am_date='" + EDT_Date + "';"
END
ELSE
IF Length(sSQL) > 0 THEN
sSQL = sSQL + "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence(I).STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 0, am_date='" + EDT_Date + "';"
ELSE
sSQL = "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresence(I).STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 0, am_date='" + EDT_Date + "';"
END
END //IF LOOP_StudentPresence(I).CBOX_StudentPresent..Value = True THEN
END //FOR I = 1 TO LOOP_StudentPresence..Occurrence


TIA

Yogi Yang

von Yogi Yang - am 07.10.2014 14:32
Yogi

Is 'STC_StudentID' the control or the attribute for the control?

If it is the control then set an attribute (as value) and try this in your code.

von DerekT - am 07.10.2014 16:14
DerekT,

STC_StudentID is a static control in the Looper.

I am not getting any problem in accessing this value. I am getting wrong value when I am reading the value of Check Box control (CBOX_StudentPresent..Value) only in case of last time in the Looper.

TIA

Yogi Yang

von Yogi Yang - am 08.10.2014 13:55
Hi

it looks like you found the source of your problem. In a looper, you should ALWAYS work with attributes and NEVER directly with the fields. If you work directly with fields, some things will work and some will not.

Best regards

von Fabrice Harari - am 08.10.2014 14:40
Yogi

Cannot see from your code why this would only be in the last row.
I would still set attributes (as value) for these controls as loopers work much better when using these.

In the code I would have......

FOR I = 1 _TO_ LooperCount(LOOP_StudentPresence,toTotal)

//Note the underscore either side of the TO - if you do not do this then the count
//element (in your case ..occurrence) is re-evaluated on each iteration.

END

When checking the value of the checkbox

IF LOOP_StudentPresence(I).attStudentPresent = 1 THEN
//Do stuff
END

von DerekT - am 08.10.2014 14:43
It seems I am banging my head in the wrong direction. :mad:

The problem is not with the last control/element it is with focus (I think)!

Let me try and explain.

If I click on the check box to uncheck it (as all check boxes are checked by default) and then immediately I click on the Save button to save the data the check box that was last clicked (or unchecked) will not get updated and its value will be returned as checked (true).

But if I click on empty area of the Looper and then click on save the check box value gets updated correctly! :confused:

I don't know as to why this is happening though.

If any one has any ideas as to what the heck is happening please direct me to a correct working solution.

TIA

Yogi Yang

von Yogi Yang - am 10.10.2014 15:51
Yogi
Have you now changed your looper/code to use attributes?

von DerekT - am 11.10.2014 09:16
DerekT,

Sorry have never used Attributes.

Can you guide me as to how to use them in case of Looper?

The help is not that informative and I cannot understand as to how to use it from the help.

TIA

Yogi Yang

von Yogi Yang - am 13.10.2014 06:46
Yogi
I do try not to be critical on here but for you to continue posting issues without actually attempting to apply a suggested solution (mine 7/10, confirmed by Fabrice 08/10) will never help you.
It is also misleading to others who may have a similar issue by leading them to believe that the advice offered was not the answer to the issue.

No one on here (with the possible exception of Fabrice) knows it all - if you do not understand what has been proposed - own up straight away as ultimately it benefits everyone.

So rant over ------ to answer your last post.......

Open the description of your looper, select the 'General' tab.
If you have manually added controls to your looper, continue else use the 'Add-Remove-Edit' buttons.

Click the 'New' button (top of window) - attribute definition fields will display.......

Attribute: Enter a name - this will be the name you use in your code.
Control: Select the control to which the attribute will apply.
Property: Select the property of the selected control that the attribute will manage.

The default Property of an attribute is 'Value' - a control requires a separate attribute for each property required.
The naming convention is up to you, if it were me then for your 'STC_StudentID' I would name the attribute 'attStudentID' for the content, 'attStudentIDcap' for the caption and so on.

Once the necessary attributes have been added edit your code to substitute the control name with the attribute name.

von DerekT - am 13.10.2014 08:48
DerekT,

Those who help have a right to scold. I am sorry I annoyed you. Actually this is for the first time that I have a need to use Looper control.

From what Fabrice and you have suggested I think Attribute feature is important but at the moment I am more comfortable in accessing the (sub) controls and their values in a looper like this: LOOP_StudentPresence(I).CBOX_StudentPresent..Value

Anyways, I tired understanding and using the Attribute feature of Looper but failed to see how it can help me. Probably it is because of my programming background. Personally I feel this feature to be an over kill. (just my 2 cents) ;)

At the moment I am a bit pressed for time and R & D as I have to submit my work in time. When I get time I will study this feature deeply to see how it works

TIA

Yogi Yang

von Yogi Yang - am 16.10.2014 04:12
DerekT,

Ok I tried the Attribute way in Looper but still the problem persist. :(

Currently what I have done is added an extra looper element at the end and in this I am hiding all the controls except one CheckBox which the user has to click to get proper result.

I know this not the way to go but I am not able to get the updated value of last clicked (focused) control.

von Yogi Yang - am 20.10.2014 05:50
Yogi
Always difficult to assimilate/debug other peoples code from afar.
If I get the opportunity I will knock up a quick project to test what I think you are doing.

Are you getting this issue in the simulator and/or on the device?

Have you stepped through your code in the debugger - is the last row ignored or is it just that the cbox of that row that is not avaiable?

Have you tested what value is being retuned by 'FOR I = 1 TO LOOP_StudentPresence..Occurrence' ?

Have you tried replacing this with 'FOR I = 1 _TO_ LooperCount(LOOP_StudentPresence,toTotal)' ?

von DerekT - am 20.10.2014 08:54
DerekT,

Here is the code that creates looper elements and loads data into it from remote MySQL DB.

I is int

bRetCode is boolean
sSQL is string
sBatchNum is string

nStudentID is int
sStudetnName is string

IF COMBO_Standards 0 THEN
ELSE
Error("Error # " + AccessMySQL.mySQLErreur, AccessMySQL.mySQLGetErrorMessage())
BTN_SaveAttendence..Visible = False
END //IF bRetCode = True THEN


Here is the code that will read the content of the Looper and save it to remote MySQL DB

I is int

bRetCode is boolean
sSQL is string
sBatchNum is string

IF COMBO_Standards = 0 THEN
Info("Please select Standard")
RETURN
END
IF COMBO_Subject 0 THEN
sSQL = sSQL + "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresenceData.STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 0, am_date='" + EDT_Date + "';"
ELSE
sSQL = "INSERT INTO attendance_master SET am_sm_id=" + LOOP_StudentPresenceData.STC_StudentID + ", am_bm_id=" + COMBO_BatchMaster + ", am_attendence= 0, am_date='" + EDT_Date + "';"
END
END //IF LOOP_StudentPresence.CBOX_StudentPresent..Value = True THEN
END //FOR I = 1 TO LOOP_StudentPresence..Occurrence

//Execute Code here to insert Data in DB
bRetCode = AccessMySQL.mySQLExec(sSQL, 0)

IF bRetCode = True THEN
Info("Student Attendence updated")
Close()
ELSE
Error("Error # " + AccessMySQL.mySQLErreur, AccessMySQL.mySQLGetErrorMessage())
END //IF bRetCode = True THEN


It is not possible to debug my app in WM IDE as I am using Web Services to access remote MySQL DB and the emulator of the IDE does not support Sockets.

I have tried this app in both physical Samsung mobile as well as in the Android Emulator.

But the problem is same in both.

I tired the Attribute part but as the problem was not solved I removed it.

I have built a Test case and uploaded to DropBox. Please use this link to download and test.

In this test project I have create two loopers in 1st I am using the tradational way of accessing the controls and their contents and in the 2nd I am using Attributes to access the controls and their data.

How to Test?
1. Start the app
2. Click on the first check box in the left Looper
3. Click the button above left Looper
4. Check the result in pop up info, it will return 0 for the checkbox in spite of the fact that it is checked
5. In the same way try out in right Looper (here I am using the Attribute feature of Looper)

TIA

Yogi Yang

von Yogi Yang - am 20.10.2014 14:08

Re: WM17-Last Element in Looper Control returns wrong value (Solved)

Just to update others.

It seems I have found a solution for this problem.

If we execute LooperDisplay() function on a looper it seems that all elements in the looper return values properly!

My case the Looper is populated using Programming.

HTH

Yogi Yang

von Yogi Yang - am 25.01.2015 14:49
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.