CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    5

    Bad response to radiobuttons in loop

    I have 2 radiobuttons, each button has a loop in it. The problem is that I need to click a radio button 2 to 3 times before it gets selected. I know my code is clumsy and would appreciate some help in cleaning it up. Mostly in getting an easy selection of the radio buttons.
    Thanks

    //EIO0 Analog Input Section
    private: System::Void rdoEIO0AnIn_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {

    this->lblEIO0d->Text=" ";
    LoopOn1=TRUE;
    LoopOn2=FALSE;

    //Set EIO0 to Analog Input
    ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_BIT, 8, 1, 0);

    //Loop
    while(LoopOn1=TRUE){

    //Read EIO0 (Channel 8)
    lngErrorcode=eGet(lngHandle,LJ_ioGET_AIN,8,&valEIO0,0);

    //Send analog value stored in valEIO0 to label lblEIO0 after converting to string
    this->lblEIO0->Text=valEIO0.ToString("0.00");

    HWND hwnd = ::FindWindow(NULL,TEXT("LabJack U3"));
    DoEvents(hwnd);

    //One second delay
    time_t start_time, cur_time;
    time(&start_time);
    do
    {
    time(&cur_time);
    }
    while((cur_time - start_time) < 1);



    if(rdoEIO0AnIn->Checked ==false){
    break;

    }
    }
    }

    //EIO0 Digital input section
    private: System::Void rdoEIO0DlIn_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {


    this->lblEIO0->Text =" ";
    LoopOn2=TRUE;
    LoopOn1=FALSE;

    //Set EIO0 to digital I/O
    ePut(lngHandle,LJ_ioPUT_ANALOG_ENABLE_BIT, 8,0,0);

    while(LoopOn2=TRUE){
    //Read EIO0 (Channel 8)
    lngErrorcode=eGet(lngHandle,LJ_ioGET_DIGITAL_BIT,8,&valEIO0d,0);

    //Send analog value stored in valEIO0 to label lblEIO0 after converting to string
    //this->lblEIO0d->Text=valEIO0d.ToString();
    //If valEIO0 is 1 send "High" to textbox
    if ( valEIO0d == 1){
    this->lblEIO0d->Text="High";
    }

    //If valEIO0 is 0 send "Low" to textbox
    if ( valEIO0d == 0){
    this->lblEIO0d->Text="Low";
    }

    //If for any reason anything other then 1 or 0 is outputted send "Error" to textbox
    else {
    this->lblEIO0->Text="Error";
    this->lblEIO0->Text=" ";

    }

    HWND hwnd = ::FindWindow(NULL,TEXT("LabJack U3"));
    DoEvents(hwnd);


    time_t start_time, cur_time;
    time(&start_time);
    do
    {
    time(&cur_time);
    }
    while((cur_time - start_time) < 1);

    if(rdoEIO0DlIn->Checked ==false){
    break;

    }

    }
    }


    // This function simply processes any messages when called
    // To call use DoEvents(hwnd);

    int DoEvents(HWND hwnd)
    {
    MSG msg;
    //while(PeekMessage(&msg, GetSafeHwnd(), 0, 0, PM_REMOVE))
    while ( PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE) )
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }

    return 0;
    }

    };
    }

  2. #2
    Join Date
    Dec 2008
    Posts
    11

    Re: Bad response to radiobuttons in loop

    could you check for the BN_CLICKED notification?
    then do your processing?
    like this
    Code:
    switch(msg){
    case WM_COMMAND:{
        switch(LOWORD(wParam){
             case BN_CLICKED:{
                   if((HWND)lParam==hRadio1){
                      //do processing
                   }else if((HWND)lParam==GetDlgItem(hwnd,IDC_RADIO2)){
                      //do processing...
                   }
             }break;
        }
    }break;
    }
    could you not?
    or is that what you are doing?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured