![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Please allow me to introduce myself. I stumbled across B4P as I've been trying to learn languages such as Visual C++ etc. I learn best by having a full syntax of commands and some good examples where I can substitute my own code.
My previous experience of coding is Psion OPL, HD6303X assembler (for PSION Org2) and various other 'Basic' type languages. I have fully registered for B4P and I'd welcome some help for some code as attached. I'm asking a series of questions - six in this case - and want the user to select their answer with a radio button, then move on to the next question. Before submitting, I'd like them to be able to review their answers and change. You'll see it populates an array Answer(). Going forward works fine, going back works fine too, until the transition between Q2 and Q1. Q1 takes on the answer from Q2, but only if Q2 has been answered. By using breakpoints and adding some tracing code, I see for some reason when hitting 'Prev' when on Q2 wishing to go to Q1, the Radio_Click Sub is invoked, populating Q1 with Q2s answer. But only if Q2 has been answered. I've stripped out all my other code to keep it clear. |
|
||||
|
Erel,
This behaviour looks strange. I renamed PrevBtn to PrevBtn1 I added a new button named it PrevBtn Deleted button PrevBtn1 Renamed Sub PrevBtn1 back to Sub PrevBtn And it works normally. Source QuestionExampleNew in this code when PrevBtn.Enabled=False is executed, the Radio_Click routine is not called. I also tried the following code in this code when PrevBtn.Enabled=False is executed, the Sender in the Radio_Click routine is RadioButton1 Code:
Sub ShowData
Label1.Text="Q"&(AnsRec+1)&". "
If Answer(AnsRec)=0 Then
For i=1 To 5
Control("RadioBtn"&i).Checked=False
Next
Else
Control("RadioBtn"&Answer(AnsRec)).Checked=True
End If
If AnsRec=0 Then
PrevBtn.Enabled=False
NextBtn.Enabled=True
Else If AnsRec=5 Then
PrevBtn.Enabled=True
NextBtn.Enabled=False
Else
PrevBtn.Enabled=True
NextBtn.Enabled=True
End If
End Sub
Code:
Sub ShowData
If AnsRec=0 Then
PrevBtn.Enabled=False
NextBtn.Enabled=True
Else If AnsRec=5 Then
PrevBtn.Enabled=True
NextBtn.Enabled=False
Else
PrevBtn.Enabled=True
NextBtn.Enabled=True
End If
Label1.Text="Q"&(AnsRec+1)&". "
If Answer(AnsRec)=0 Then
For i=1 To 5
Control("RadioBtn"&i).Checked=False
Next
Else
Control("RadioBtn"&Answer(AnsRec)).Checked=True
End If
End Sub
the Sender in the Radio_Click routine is RadioButton2 which gives the wrong information. Best regards
__________________
Klaus Switzerland |
|
|||
|
Many thanks Erel, that has enabled that Sub to execute as I had intended.
Klaus, from my understanding, the Radio_Click event is inadvertantly triggered when focus is shifted to the radio button. A bit like on desktop applications, when you press the <TAB> key; there is an order to which each control is focussed with the <TAB> (In visual C++ the programmer may define this sequence.) In my case, when the 'Prev' button was disabled, the next control in order was the Radio. This then generated the Radio_Click and wrongly populated the array. In your attached code, because you have moved things around, the unwanted event moves to the end; i.e. when you click the final 'Next' the last question is populated from the unwanted event. Again this is cured by shifting focus to the 'Prev' button before disabling 'Next' (I'm learning quickly...) |
|
||||
|
It works fine for me if you move the button enabling/disabling code after the radio button setting but I'm not sure why.
![]() Code:
Sub ShowData
Label1.Text="Q"&(AnsRec+1)&". "
If Answer(AnsRec)=0 Then
For i=1 To 5
Control("RadioBtn"&i).Checked=False
Next
Else
Control("RadioBtn"&Answer(AnsRec)).Checked=True
End If
If AnsRec=0 Then
PrevBtn.Enabled=False
NextBtn.Enabled=True
Else If AnsRec=5 Then
PrevBtn.Enabled=True
NextBtn.Enabled=False
Else
PrevBtn.Enabled=True
NextBtn.Enabled=True
End If
End Sub
Last edited by agraham : 05-05-2008 at 03:38 PM. |
|
||||
|
My post was not really clear, I didn't mention that for me the code with the Enabled=false at the end works OK also.
But for me it is still strange that the last RadioButton that had the focus is triggered when the PrevBtn.Enabled=false and this behaviour depends on the order we enter the buttons. If the buttons are entered in a different order the program has a 'normal' behaviour ! ? Best regards
__________________
Klaus Switzerland |
|
||||
|
When the button is disabled the focus moves to the "next" control.
Depending on the order you've added the controls the next control can be a different control. You can change the order of controls by using this method: Tab Order for Controls |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| event doubleclick and click on the cell (table object)... | micro | Questions & Help Needed | 2 | 08-19-2008 06:50 PM |
| Right Click ?? | pegamaster | Questions & Help Needed | 2 | 07-07-2008 07:11 PM |
| Click event during a for loop | pmu5757 | Questions & Help Needed | 7 | 04-12-2008 04:44 PM |
| TreeView Click Event | RandomCoder | Basic4ppc Wishlist | 5 | 02-28-2008 04:23 PM |
| Click function | neilnapier | Questions & Help Needed | 12 | 11-03-2007 07:51 PM |