title: Visual C++ Debug Assertion Fail
body: <p>When Ever I compile my program it say "Debug Assertion Failed".<br>
  And when I click ignore twice my app shows up.<br>
  How can I fix it?</p>
  
  <p>The whole code is below in case you want to test it for your self. The app increases in number as the scroll bar is moved to the right and decreases as the scroll bar is moved to the left. But my main problem is the debug assertion failed. If you can please post the part of the code that has problem and how I can fix it or fix it and post the code. Is there any way to get rid of that run time error with out using a try and catch. I mean to fix that problem please. This is a project and I have only a week and a half to do it. If you can help me with this project your help would be greatly appreciated. I am fairly new to visual c++. Part of the error is:</p>
  
  <blockquote>
    <p>Program E:\BHCCHardwareStore\Debug\BHCCHardwareStore.exe FIle:f\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp Line: 196. For information on how your program can cause an assertion failure see the Visual C++ documentation on asserts.
    (Press Retry to debug the application). </p>
  </blockquote>
  
  <p>Now when I click ignore it kind of displays the app perfectly fine. And the app seems to work just fine. How can I fix this error This code is not the entire code I am cutting and pasting?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;strstream&gt;
  #include &lt;afxwin.h&gt;
  #include &lt;string.h&gt;
  const int IDC_SB1 = 100;
  const int IDC_CS1 = 101;
  const int IDC_CS2 = 102;
  const int IDC_BUTTON = 103;
  
  const int MIN_RANGE = 0;
  const int MAX_RANGE = 100;
  class CApp :public CWinApp
  {
  public:
      virtual BOOL InitInstance();
  };
  
  CApp App;
  
  class CSource :public CFrameWnd
  {
      CScrollBar*sb1;
      CStatic* cs1;
      CStatic* cs2;
      CButton* button;
  public:
      CSource();
      afx_msg void OnHScroll(UINT nSBCode,
          UINT nPos, CScrollBar* pSccrollBar);
      afx_msg void handleButton();
      DECLARE_MESSAGE_MAP();
  };
  
  BEGIN_MESSAGE_MAP(CSource, CFrameWnd)
      ON_WM_HSCROLL()
      ON_BN_CLICKED(IDC_BUTTON, handleButton)
  END_MESSAGE_MAP()
  
  //Window cONSTRUCTOR
  
  CSource::CSource()
  {
  
  }
  
  void CSource::OnHScroll(UINT nSBCode,
      UINT nPos, CScrollBar* pScrollBar)
  {
      int pos, dividend = 0, holder = 0, x = 0;
      char array[9];
      //;
      pos = pScrollBar-&gt;GetScrollPos();
      switch (nSBCode)
      {
      case SB_LINEUP:
          pos -= 1;
          break;
      case SB_LINEDOWN:
          pos += 1;
          break;
      case SB_PAGEUP:
          pos -= 10;
          break;
      case SB_PAGEDOWN:
          pos += 10;
          break;
      case SB_TOP:
          pos = MIN_RANGE;
          break;
      case SB_BOTTOM:
          pos = MAX_RANGE;
          break;
      case SB_THUMBTRACK:
          pos = nPos;
          break;
      default:
          return;
      }
  
      if (pos &lt; MIN_RANGE)
          pos = MIN_RANGE;
      else if (pos &gt; MAX_RANGE)
          pos = MAX_RANGE;
      sb1-&gt;SetScrollPos(pos, TRUE);
  
      //Set the labels to the new values
      char s[100];
      TCHAR s1[100];
      std::ostrstream ostr(s, 100);
      ostr &lt;&lt; "Decimal Value = " &lt;&lt; pos &lt;&lt; std::ends;
      for (int i = 0; i &lt; 100; i++){
          s1[i] = (TCHAR) s[i];
      }
      SetDlgItemText(IDC_CS1, s1);
      ostr.seekp(std::ios::beg);
  
      dividend = pos;
      for (int y = 0; y &lt; 9; y++)
          array[y] = '0';
      int remainder = dividend % 2;
      int quotient = dividend / 2;
      array[x] = (char)(remainder + 48);
      do
      {
          remainder = quotient % 2;
          quotient = quotient / 2;
          array[++x] = (char)(remainder + 48);
      } while (quotient != 0);
      array[8] = '\0';
      ostr &lt;&lt; "Binary Value = " &lt;&lt; _strrev(array) &lt;&lt; std::ends;
      SetDlgItemText(IDC_CS2, s1);
  }
  
  void CSource::handleButton()
  {
      int result;
      result = MessageBox(_T("Are you sure?"), _T("Exiting"),
          MB_ICONQUESTION | MB_YESNO);
      if (result == IDYES)
      {
          Beep(1000, 100);
          DestroyWindow();
      }
      else
          Beep(200, 100);
  }
  
  //Initialize the application and the main window
  BOOL CApp::InitInstance()
  {
      m_pMainWnd = new CSource();
      m_pMainWnd-&gt;ShowWindow(m_nCmdShow);
      m_pMainWnd-&gt;UpdateWindow();
      return TRUE;
  }
  </code></pre>