CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2008
    Posts
    93

    CString array question

    here is the code i need to ask about.

    in header file:

    CString Amsg[18];
    CString Bmsg[18];

    BOOL appeartwice;
    BOOL press;

    int switch;
    int LED;
    int i;


    in the cpp file:

    Amsg[0]="Hello";
    Bmsg[0]="Hello";
    ......
    ......
    Amsg[17]="GoodBye"
    Bmsg[17]="GoodBye"

    for(i=0; i<18; i++)
    {
    if(Amsg[i]==Bmsg[i])
    {
    appeartwice= TRUE;
    }
    }

    if(switch == 1) //Button pressed
    {
    press=TRUE;
    }

    if((appeartwice==TRUE)&&(press==TRUE))
    {
    LED=1; //LED turn on.
    }
    else if(((appeartwice==FALSE)&&(press==TRUE))||((appeartwice==TRUE)&&(press==FALSE)))
    {
    LED=0; //LED turn off
    }



    now the question i want to ask is if this if(Amsg[i]==Bmsg[i]) condition valid for Visual C++ to read it?

    or is the way to compare CString array with Cstring array is different?

    i build my whole program with no errors detected but when i run it i have error window popped out.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CString array question

    What happens if you put a break point on the line:

    Code:
    appeartwice= TRUE;
    What do the array strings look like in the watch window?

    Code:
    Amsg[i]
    Bmsg[i]

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CString array question

    Your if statment is valid. CStrings have the == operator defined for comparisons. Surely your debugger can provide some information about the error, or at a minimum there is some kind of message in the "error window".

  4. #4
    Join Date
    Apr 2008
    Posts
    93

    Re: CString array question

    Quote Originally Posted by Arjay
    What happens if you put a break point on the line:

    Code:
    appeartwice= TRUE;
    What do the array strings look like in the watch window?

    Code:
    Amsg[i]
    Bmsg[i]
    i cant use the watch window as i cant select or add variables into the watch window.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CString array question

    Quote Originally Posted by ashwarrior
    i cant use the watch window as i cant select or add variables into the watch window.
    What version of Visual Studio are you using?

  6. #6
    Join Date
    Apr 2008
    Posts
    93

    Re: CString array question

    visual c++ 6.0

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CString array question

    Upgrade your compiler to 2008 or at least 2005 and try again.

    So many improvements have been made to the IDE since the 10 year old VC6 came out.

    For example, the watch Window. Nowadays, you can drag your variable in the watch window on-the-fly and see the values.

    You can even hover over the variable in the source code while debugging and see the value.

    You can see UNICODE strings without having to type ',su' after the string.

    These are just 3 improvements that I can think of and there are 100's more.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CString array question

    Quote Originally Posted by ashwarrior
    visual c++ 6.0
    Quote Originally Posted by ashwarrior
    i cant use the watch window as i cant select or add variables into the watch window.
    I never had such a problem in vc++6.0. Neither with Debug window nor with a watch one.
    ashwarrior, you are surely doing something wrong or not completely.
    Victor Nijegorodov

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CString array question

    Watch windows work in VC6, but that isn't really important. The program seems to be crashing. The debugger should be able to tell him something useful with or without watch windows.

  10. #10
    Join Date
    Apr 2008
    Posts
    93

    Re: CString array question

    Quote Originally Posted by Arjay
    Upgrade your compiler to 2008 or at least 2005 and try again.

    So many improvements have been made to the IDE since the 10 year old VC6 came out.

    For example, the watch Window. Nowadays, you can drag your variable in the watch window on-the-fly and see the values.

    You can even hover over the variable in the source code while debugging and see the value.

    You can see UNICODE strings without having to type ',su' after the string.

    These are just 3 improvements that I can think of and there are 100's more.
    Where i download the latest compiler?

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