Форум программистов, компьютерный форум, киберфорум
C++/CLI
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 12.02.2013
Сообщений: 21

Как сравнить проверить, что введенное в textBox - число и где можно ввести собственные переменные

31.05.2013, 11:15. Показов 1226. Ответов 0
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Windows Forms. Пишу простой калькулятор. Столкнулся с проблемой. Сабж, вообщем.
Написал такое событие:
C++
1
2
3
4
5
6
7
8
9
long double a,b,rezult=0; //a,b-числа, rezult - результат действия с ними
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                if(
                     (textBox1->Text==Convert::ToString(rezult)) ||
                     (textBox1->Text==Convert::ToString(a)) ||
                     (textBox1->Text==Convert::ToString(b))
                  )  {textBox1->Clear();}
                textBox1->AppendText("1");
             }
Компилятор ругается.
Ошибка 1 error C3845: Калькулятор::Form1::rezult: только статические данные-члены можно инициализировать внутри класс ссылки или типа, передаваемого по значению
Ошибки 2-4 error C2668: System::Convert::ToString: неоднозначный вызов перегруженной функции

Думаю, нельзя так прям в основном коде вводить собственные переменные. Где для них место? Это надо создавать собственный .h-файл и подключать?

Добавлено через 10 минут
Извините, совсем не то спросил. Как проверить, что введенное в textBox - число я уже понял.
1. Как убрать эти ошибки?
2. Где можно создать свои переменные, функции?
3. Как проверить что в textBox введен какой-то символ? Есть для этого какое-то событие?

Добавлено через 16 минут
Файл Form.h
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#pragma once
namespace Калькулятор {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
 
    /// <summary>
    /// Сводка для Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: добавьте код конструктора
            //
        }
 
    protected:
        /// <summary>
        /// Освободить все используемые ресурсы.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
 
 
    protected: 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    private: System::Windows::Forms::TextBox^  textBox1;
    private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::Button^  button2;
    private: System::Windows::Forms::Button^  button3;
    private: System::Windows::Forms::Button^  button4;
    private: System::Windows::Forms::Button^  button5;
    private: System::Windows::Forms::Button^  button6;
    private: System::Windows::Forms::Button^  button7;
    private: System::Windows::Forms::Button^  button8;
    private: System::Windows::Forms::Button^  button9;
    private: System::Windows::Forms::Button^  button10;
    private: System::Windows::Forms::Button^  button11;
    private: System::Windows::Forms::Button^  button12;
    private: System::Windows::Forms::Button^  button13;
    private: System::Windows::Forms::Button^  button14;
    private: System::Windows::Forms::Button^  button15;
    private: System::Windows::Forms::Button^  button16;
    private: System::Windows::Forms::Button^  button17;
 
    protected: 
 
    private:
        /// <summary>
        /// Требуется переменная конструктора.
        /// </summary>
        System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Обязательный метод для поддержки конструктора - не изменяйте
        /// содержимое данного метода при помощи редактора кода.
        /// </summary>
        void InitializeComponent(void)
        {
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->button3 = (gcnew System::Windows::Forms::Button());
            this->button4 = (gcnew System::Windows::Forms::Button());
            this->button5 = (gcnew System::Windows::Forms::Button());
            this->button6 = (gcnew System::Windows::Forms::Button());
            this->button7 = (gcnew System::Windows::Forms::Button());
            this->button8 = (gcnew System::Windows::Forms::Button());
            this->button9 = (gcnew System::Windows::Forms::Button());
            this->button10 = (gcnew System::Windows::Forms::Button());
            this->button11 = (gcnew System::Windows::Forms::Button());
            this->button12 = (gcnew System::Windows::Forms::Button());
            this->button13 = (gcnew System::Windows::Forms::Button());
            this->button14 = (gcnew System::Windows::Forms::Button());
            this->button15 = (gcnew System::Windows::Forms::Button());
            this->button16 = (gcnew System::Windows::Forms::Button());
            this->button17 = (gcnew System::Windows::Forms::Button());
            this->SuspendLayout();
            // 
            // textBox1
            // 
            this->textBox1->BackColor = System::Drawing::SystemColors::ButtonHighlight;
            this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                static_cast<System::Byte>(204)));
            this->textBox1->Location = System::Drawing::Point(12, 12);
            this->textBox1->Name = L"textBox1";
            this->textBox1->ReadOnly = true;
            this->textBox1->Size = System::Drawing::Size(189, 31);
            this->textBox1->TabIndex = 12;
            this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(12, 68);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(37, 35);
            this->button1->TabIndex = 13;
            this->button1->Text = L"1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // button2
            // 
            this->button2->Location = System::Drawing::Point(55, 68);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(37, 35);
            this->button2->TabIndex = 14;
            this->button2->Text = L"2";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
            // 
            // button3
            // 
            this->button3->Location = System::Drawing::Point(98, 68);
            this->button3->Name = L"button3";
            this->button3->Size = System::Drawing::Size(37, 35);
            this->button3->TabIndex = 15;
            this->button3->Text = L"3";
            this->button3->UseVisualStyleBackColor = true;
            this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
            // 
            // button4
            // 
            this->button4->Location = System::Drawing::Point(12, 109);
            this->button4->Name = L"button4";
            this->button4->Size = System::Drawing::Size(37, 35);
            this->button4->TabIndex = 16;
            this->button4->Text = L"4";
            this->button4->UseVisualStyleBackColor = true;
            this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
            // 
            // button5
            // 
            this->button5->Location = System::Drawing::Point(55, 109);
            this->button5->Name = L"button5";
            this->button5->Size = System::Drawing::Size(37, 35);
            this->button5->TabIndex = 17;
            this->button5->Text = L"5";
            this->button5->UseVisualStyleBackColor = true;
            this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
            // 
            // button6
            // 
            this->button6->Location = System::Drawing::Point(98, 109);
            this->button6->Name = L"button6";
            this->button6->Size = System::Drawing::Size(37, 35);
            this->button6->TabIndex = 18;
            this->button6->Text = L"6";
            this->button6->UseVisualStyleBackColor = true;
            this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
            // 
            // button7
            // 
            this->button7->Location = System::Drawing::Point(12, 150);
            this->button7->Name = L"button7";
            this->button7->Size = System::Drawing::Size(37, 35);
            this->button7->TabIndex = 19;
            this->button7->Text = L"7";
            this->button7->UseVisualStyleBackColor = true;
            this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
            // 
            // button8
            // 
            this->button8->Location = System::Drawing::Point(55, 150);
            this->button8->Name = L"button8";
            this->button8->Size = System::Drawing::Size(37, 35);
            this->button8->TabIndex = 20;
            this->button8->Text = L"8";
            this->button8->UseVisualStyleBackColor = true;
            this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
            // 
            // button9
            // 
            this->button9->Location = System::Drawing::Point(98, 150);
            this->button9->Name = L"button9";
            this->button9->Size = System::Drawing::Size(37, 35);
            this->button9->TabIndex = 21;
            this->button9->Text = L"9";
            this->button9->UseVisualStyleBackColor = true;
            this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
            // 
            // button10
            // 
            this->button10->Location = System::Drawing::Point(12, 191);
            this->button10->Name = L"button10";
            this->button10->Size = System::Drawing::Size(37, 35);
            this->button10->TabIndex = 22;
            this->button10->Text = L"00";
            this->button10->UseVisualStyleBackColor = true;
            this->button10->Click += gcnew System::EventHandler(this, &Form1::button10_Click);
            // 
            // button11
            // 
            this->button11->Location = System::Drawing::Point(55, 191);
            this->button11->Name = L"button11";
            this->button11->Size = System::Drawing::Size(37, 35);
            this->button11->TabIndex = 23;
            this->button11->Text = L"0";
            this->button11->UseVisualStyleBackColor = true;
            this->button11->Click += gcnew System::EventHandler(this, &Form1::button11_Click);
            // 
            // button12
            // 
            this->button12->Location = System::Drawing::Point(98, 191);
            this->button12->Name = L"button12";
            this->button12->Size = System::Drawing::Size(37, 35);
            this->button12->TabIndex = 24;
            this->button12->Text = L".";
            this->button12->UseVisualStyleBackColor = true;
            this->button12->Click += gcnew System::EventHandler(this, &Form1::button12_Click);
            // 
            // button13
            // 
            this->button13->Location = System::Drawing::Point(164, 68);
            this->button13->Name = L"button13";
            this->button13->Size = System::Drawing::Size(37, 35);
            this->button13->TabIndex = 25;
            this->button13->Text = L"+";
            this->button13->UseVisualStyleBackColor = true;
            this->button13->Click += gcnew System::EventHandler(this, &Form1::button13_Click);
            // 
            // button14
            // 
            this->button14->Location = System::Drawing::Point(164, 109);
            this->button14->Name = L"button14";
            this->button14->Size = System::Drawing::Size(37, 35);
            this->button14->TabIndex = 26;
            this->button14->Text = L"--";
            this->button14->UseVisualStyleBackColor = true;
            this->button14->Click += gcnew System::EventHandler(this, &Form1::button14_Click);
            // 
            // button15
            // 
            this->button15->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
                | System::Windows::Forms::AnchorStyles::Left) 
                | System::Windows::Forms::AnchorStyles::Right));
            this->button15->Location = System::Drawing::Point(164, 150);
            this->button15->Name = L"button15";
            this->button15->Size = System::Drawing::Size(37, 35);
            this->button15->TabIndex = 27;
            this->button15->Text = L"x";
            this->button15->UseVisualStyleBackColor = true;
            this->button15->Click += gcnew System::EventHandler(this, &Form1::button15_Click);
            // 
            // button16
            // 
            this->button16->Location = System::Drawing::Point(164, 191);
            this->button16->Name = L"button16";
            this->button16->Size = System::Drawing::Size(37, 35);
            this->button16->TabIndex = 28;
            this->button16->Text = L"/";
            this->button16->UseVisualStyleBackColor = true;
            this->button16->Click += gcnew System::EventHandler(this, &Form1::button16_Click);
            // 
            // button17
            // 
            this->button17->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                static_cast<System::Byte>(204)));
            this->button17->Location = System::Drawing::Point(12, 232);
            this->button17->Name = L"button17";
            this->button17->Size = System::Drawing::Size(189, 35);
            this->button17->TabIndex = 29;
            this->button17->Text = L"=";
            this->button17->UseVisualStyleBackColor = true;
            this->button17->Click += gcnew System::EventHandler(this, &Form1::button17_Click);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->CausesValidation = false;
            this->ClientSize = System::Drawing::Size(213, 279);
            this->Controls->Add(this->button17);
            this->Controls->Add(this->button16);
            this->Controls->Add(this->button15);
            this->Controls->Add(this->button14);
            this->Controls->Add(this->button13);
            this->Controls->Add(this->button12);
            this->Controls->Add(this->button11);
            this->Controls->Add(this->button10);
            this->Controls->Add(this->button9);
            this->Controls->Add(this->button8);
            this->Controls->Add(this->button7);
            this->Controls->Add(this->button6);
            this->Controls->Add(this->button5);
            this->Controls->Add(this->button4);
            this->Controls->Add(this->button3);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->textBox1);
            this->HelpButton = true;
            this->MaximizeBox = false;
            this->MinimizeBox = false;
            this->Name = L"Form1";
            this->Text = L"Калькулятор beta";
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
 
#pragma endregion
long double a,b,rezult=0; //a,b-числа, rezult - результат действия с ними
short int make; //if(make==1) sum if 2 - -, if 3 *, if 4 - /
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("1");
             }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("2");
         }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("3");
         }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("4");
         }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("5");
         }
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("6");
         }
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {            
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("7");
         }
private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("8");
         }
private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("9");
         }
private: System::Void button10_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("00");
         }
private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) {
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText("0");
         }
private: System::Void button12_Click(System::Object^  sender, System::EventArgs^  e) {
             
             if(textBox1->Text==Convert::ToString(rezult))  {textBox1->Clear();}
                textBox1->AppendText(".");
         }
 
 
 
         //Далее идут вычисления
 
 
 
private: System::Void button13_Click(System::Object^  sender, System::EventArgs^  e) {
             a=Convert::ToDouble(textBox1->Text);
             make=1;
             textBox1->Clear();
         }
private: System::Void button14_Click(System::Object^  sender, System::EventArgs^  e) {
             a=Convert::ToDouble(textBox1->Text);
             make=2;
         }
private: System::Void button15_Click(System::Object^  sender, System::EventArgs^  e) {
             a=Convert::ToDouble(textBox1->Text);
             make=3;
         }
private: System::Void button16_Click(System::Object^  sender, System::EventArgs^  e) {           
             a=Convert::ToDouble(textBox1->Text);
             make=4;
         }
private: System::Void button17_Click(System::Object^  sender, System::EventArgs^  e) {
             b=Convert::ToDouble(textBox1->Text);
         }
};
}
Добавлено через 24 минуты
Просьба модераторам удалить эту тему!
Вопрос перенес вот сюда: https://www.cyberforum.ru/visu... ost4647217
0
IT_Exp
Эксперт
34794 / 4073 / 2104
Регистрация: 17.06.2006
Сообщений: 32,602
Блог
31.05.2013, 11:15
Ответы с готовыми решениями:

Как с Label ввести число чтоб оно ввелось в код и потом его можно было сравнить с другим числом
Подскажите как с Label ввести число чтоб оно ввелось в код и потом его можно было сравнить с другим числом, и если число ,например, 5=5...

Как сравнить число в массиве введенное с клавиатуры?
Выполнил задание, но очень коряво { class Program { int a = new int; public void genRand() ...

Проверить, что введенное вами число делится без остатка на 3
&quot;&quot;Составьте программу, проверяющею верно ли утверждение что введенное вами число делится без остатка на 3&quot;&quot;

0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
BasicMan
Эксперт
29316 / 5623 / 2384
Регистрация: 17.02.2009
Сообщений: 30,364
Блог
31.05.2013, 11:15
Помогаю со студенческими работами здесь

Проверить, верно ли утверждение, что введенное целое число делится без остатка на 3
Составьте программу, проверяющую, верно ли утверждение, что введенное вами целое число делится без остатка на 3.Если будете продолжать...

Проверить, верно ли утверждение, что введенное целое число делится на 3 без остатка
Ветвление. 1). Составьте программу, проверяющую верно ли утверждение что введенное вами целое число делится на 3 без остатка. 2). ...

Как в компонент Edit ввести отрицательное число, чтобы в Label выходило сообщение, что нужно ввести число >0?
Как в компонент Edit ввести отрицательное число, чтобы в Label выходило сообщение, что нужно ввести число &gt;0? Если вводить в Edit, то...

Как проверить, что ты верно нашел собственные числа и вектора матрицы?
Здравствуйте! Подскажите, пожалуйста, как можно проверить правильность найденных собственных чисел и матриц. Интернет не предлагать :)...

Как найти сумму цифр, образующих число, введенное в TextBox
В TextBox вводиться двухзначное число. Как найти сумму цифр, образующих это число?


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
Новые блоги и статьи
Программный контроль заполнения реквизита табличной части документа
Maks 02.04.2026
Алгоритм из решения ниже реализован на примере нетипового документа "СписаниеМатериалов", разработанного в конфигурации КА2. Задача: реализовать контроль заполнения реквизита "ПричинаСписания". . .
wmic не является внутренней или внешней командой
Maks 02.04.2026
Решение: DISM / Online / Add-Capability / CapabilityName:WMIC~~~~ Отсюда: https:/ / winitpro. ru/ index. php/ 2025/ 02/ 14/ komanda-wmic-ne-naydena/
Программная установка даты и запрет ее изменения
Maks 02.04.2026
Алгоритм из решения ниже реализован на примере нетипового документа "СписаниеМатериалов", разработанного в конфигурации КА2. Задача: при создании документов установить период списания автоматически. . .
Вывод данных в справочнике через динамический список
Maks 01.04.2026
Реализация из решения ниже выполнена на примере нетипового справочника "Спецтехника" разработанного в конфигурации КА2. Задача: вывести данные из ТЧ нетипового документа. . .
Программное заполнения текстового поля в реквизите формы документа
Maks 01.04.2026
Алгоритм из решения ниже реализован на нетиповом документе "ВыдачаОборудованияНаСпецтехнику" разработанного в конфигурации КА2, в дополнении к предыдущему решению. На форме документа создается. . .
К слову об оптимизации
kumehtar 01.04.2026
Вспоминаю начало 2000-х, университет, когда я писал на Delphi. Тогда среди программистов на форумах активно обсуждали аккуратную работу с памятью: нужно было следить за переменными, вовремя. . .
Идея фильтра интернета (сервер = слой+фильтр).
Hrethgir 31.03.2026
Суть идеи заключается в том, чтобы запустить свой сервер, о чём я если честно мечтал давно и давно приобрёл книгу как это сделать. Но не было причин его запускать. Очумелые учёные напечатали на. . .
Модель здравосоХранения 6. ESG-повестка и устойчивое развитие; углублённый анализ кадрового бренда
anaschu 31.03.2026
В прикрепленном документе раздумья о том, как можно поменять модель в будущем
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru