Question: In Visual Studio, how do I fix this exception being thrown? I just got help with the first exception, but now I have more. Also,

In Visual Studio, how do I fix this exception being thrown?
I just got help with the first exception, but now I have more. Also, would it be helpful to put breakpoints anywhere?
Here is my code so far..
App.h
#pragma once
#include "UI.h"
#include
class App : public wxApp
{
public:
virtual bool OnInit() override;
};
UI.h
#pragma once
#include "wx/event.h"
#include "wx/sizer.h"
#include
#include
#include
#include
class uiFrame : public wxFrame
{
public:
uiFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
wxTextCtrl* textBox;
void buttonClick(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
};
App.cpp
#include "App.h"
#include "UI.h"
#include
bool App::OnInit()
{
uiFrame* frame = new uiFrame ("Calculator", wxDefaultPosition, wxSize(300,400));
frame->Show(true);
return true;
}
UI.cpp
#include "UI.h"
#include
#include "App.h"
#include
#include
#include
wxBEGIN_EVENT_TABLE(uiFrame, wxFrame)
EVT_BUTTON(wxID_ANY, uiFrame::buttonClick)
wxEND_EVENT_TABLE()
uiFrame::uiFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(NULL, wxID_ANY, title, pos, size)
{
wxBoxSizer* calcSizer = new wxBoxSizer(wxVERTICAL);
textBox = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
calcSizer->Add(textBox,0, wxEXPAND | wxALL, 5);
wxGridSizer* buttonGrid = new wxGridSizer(5,5,5,5);
for (int i =0; i =9; i++)
{
wxString label = wxString::Format("%d", i);
wxButton* numButton = new wxButton(this, wxID_ANY, label);
buttonGrid->Add(numButton,0, wxEXPAND);
numButton->Connect(wxID_ANY, wxEVT_BUTTON, wxCommandEventHandler(uiFrame::buttonClick), this);
}
wxArrayString operators;
operators.Add("+");
operators.Add("-");
operators.Add("*");
operators.Add("/");
operators.Add("%");
operators.Add("sin");
operators.Add("cos");
operators.Add("tan");
operators.Add("=");
operators.Add("-");
operators.Add("Clear");
operators.Add(".");
operators.Add("Neg");
for (const wxString& oper : operators)
{
wxButton* operButton = new wxButton(this, wxID_ANY, oper);
buttonGrid->Add(operButton,0, wxEXPAND);
operButton->Connect(wxID_ANY, wxEVT_BUTTON, wxCommandEventHandler(uiFrame::buttonClick), this);
}
calcSizer->Add(buttonGrid,1, wxEXPAND | wxALL, 5);
SetSizer(calcSizer);
}
void uiFrame::buttonClick(wxCommandEvent & event)
{
wxButton* button = wxDynamicCast(event.GetEventObject(), wxButton);
if (!button) return;
{
wxString label = button->GetLabel();
wxString currentText;
if (textBox)
{
currentText = textBox->GetValue();
}
else
{
currentText = "Error: textBox is null";
}
if (label.IsNumber())
{
currentText += label;
}
else if (label =="+"|| label =="-"|| label =="*"|| label =="/"|| label =="%"|| label == "sin" || label == "cos" || label == "tan")
{
currentText +=""+ label +"";
}
else if (label =="=")
{
wxStringTokenizer tokenizer(currentText,"");
double result =0;
wxString lastOp;
while (tokenizer.HasMoreTokens())
{
wxString token = tokenizer.GetNextToken();
if (token.IsNumber())
{
double number;
token.ToDouble(&number);
if (lastOp =="+")
{
result += number;
}
else if (lastOp =="-")
{
result -= number;
}
else if (lastOp =="/")
{
result /= number;
}
else if (lastOp =="*")
{
result *= number;
}
else if (lastOp =="&")
{
result = fmod(result, number);
}
else if (lastOp == "sin")
{
result = sin(number);
}
else if (lastOp == "cos")
{
result = cos(number);
}
else if (lastOp == "tan")
{
result = tan(number);
}
}
else
{
lastOp = token;
}
}
currentText = wxString::Format("%.2f", result);
}
else if (label == "Clear")
{
currentText ="";
}
else if (label =="-")
{
if (!currentText.IsEmpty())
{
currentText.RemoveLast();
}
}
else if (label ==".")
{
currentText +=".";
}
else if (label == "Neg")
{
if (currentText.StartsWith("-"))
{
currentText = currentText.Mid(1);
}
else
{
currentText ="-"+ currentText;
}
}
textBox->SetValue(currentText);
}
}
wxIMPLEMENT_APP(App);
In Visual Studio, how do I fix this exception

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!