E sad mi se javlja problem da za svaki textbox gde pretvaram vrednosi u double dolazi do greske kad je textbox prazan, pa dodelim vrednosti na samom pocetku programa svakom textbox-u vrednost nula,
medjutim ne bi trebalo nikakve vrednosti da ima textbox, pogotovo ne nula, jer bi trebalo da postavljam neke uslove za dalje resavanje gde naravno parametri trougla ne smeju imati vrednost nula gde to ima smisla,
pa mi je palo napamet da ako je textbox prazan on uopste ne radi transformaciju iz stringa u double, kroz if naredbu, medjutim posle ne mogu da koristim te iste varijable/promenljive van if/else naredbe.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
at.Text = bt.Text = ct.Text = Ot.Text = Pt.Text = rt.Text = Rto.Text = hat.Text = hbt.Text = hct.Text= usta.Text = ustb.Text = ustg.Text= "0" ;
}
private void Trougao_Click(object sender, EventArgs e)
{
}
private void Resitrougao_Click(object sender, EventArgs e)
{
if ((string.IsNullOrEmpty(at.Text)) & (string.IsNullOrEmpty(bt.Text)) & (string.IsNullOrEmpty(ct.Text)) & (string.IsNullOrEmpty(Ot.Text)) & (string.IsNullOrEmpty(rt.Text)) & (string.IsNullOrEmpty(Pt.Text)) & (string.IsNullOrEmpty(hat.Text)) & (string.IsNullOrEmpty(hbt.Text) & string.IsNullOrEmpty(hct.Text) & string.IsNullOrEmpty(Rto.Text) & string.IsNullOrEmpty(usta.Text) & string.IsNullOrEmpty(ustb.Text) & string.IsNullOrEmpty(ustg.Text)))
{
}
else
{
double at1 = double.Parse(at.Text);
double bt1 = double.Parse(bt.Text);
double ct1 = double.Parse(ct.Text);
double Ot1 = double.Parse(Ot.Text);
double Pt1 = double.Parse(Pt.Text);
double rt1 = double.Parse(rt.Text);
double Rto1 = double.Parse(Rto.Text);
double hat1 = double.Parse(hat.Text);
double hbt1 = double.Parse(hbt.Text);
double hc1 = double.Parse(hct.Text);
double usta1 = double.Parse(usta.Text);
double ustb1 = double.Parse(ustb.Text);
double ustg1 = double.Parse(ustg.Text);
}
if ((at1 == 0) || (bt1 == 0) || (ct1 == 0))
{
}
else
{
Ot1 = at1 + bt1 + ct1;
}
double p = Ot1 / 2;
Pt1 = Math.Sqrt(p * (p - at1) * (p - bt1) * (p - ct1));
at.Text = at1.ToString();
bt.Text = bt1.ToString();
ct.Text = ct1.ToString();
rt.Text = rt1.ToString();
Rto.Text = Rto1.ToString();
hat.Text = hat1.ToString();
hbt.Text = hbt1.ToString();
hct.Text = hct1.ToString();
usta.Text = usta1.ToString();
ustb.Text = ustb1.ToString();
ustg.Text = ustg1.ToString();
Ot.Text = Ot1.ToString();
Pt.Text = Pt1.ToString();
}
private void at_TextChanged(object sender, EventArgs e)
{
}
}
}
i u desription dobijem ovo:
Error 1 The name 'at1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 49 18 Planimetrija
Error 5 The name 'at1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 54 23 Planimetrija
Error 10 The name 'at1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 57 38 Planimetrija
Error 13 The name 'at1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 58 23 Planimetrija
Error 2 The name 'bt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 49 32 Planimetrija
Error 6 The name 'bt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 54 29 Planimetrija
Error 11 The name 'bt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 57 50 Planimetrija
Error 14 The name 'bt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 59 23 Planimetrija
Error 3 The name 'ct1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 49 46 Planimetrija
Error 7 The name 'ct1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 54 35 Planimetrija
Error 12 The name 'ct1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 57 62 Planimetrija
Error 15 The name 'ct1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 60 23 Planimetrija
Error 18 The name 'hat1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 63 24 Planimetrija
Error 19 The name 'hbt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 64 24 Planimetrija
Error 20 The name 'hct1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 65 24 Planimetrija
Error 4 The name 'Ot1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 54 17 Planimetrija
Error 8 The name 'Ot1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 56 24 Planimetrija
Error 24 The name 'Ot1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 69 23 Planimetrija
Error 9 The name 'Pt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 57 13 Planimetrija
Error 25 The name 'Pt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 70 23 Planimetrija
Error 16 The name 'rt1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 61 23 Planimetrija
Error 17 The name 'Rto1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 62 24 Planimetrija
Error 21 The name 'usta1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 66 25 Planimetrija
Error 22 The name 'ustb1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 67 25 Planimetrija
Error 23 The name 'ustg1' does not exist in the current context C:\Users\Panterloki\Desktop\Planimetrija\Planimetrija\Form1.cs 68 25 Planimetrija
A ako stavim ovu drugu if/else naredbu da bude deo prve else naredbe funkcionise, medjutim ako ne dodelim vrednost svakom textboxu kao sto sam to uradio da na pocetku programa radi,
ali mi posle te dodeljene vrednosti za 0 smetaju jer parametri trougla ne bi smeli da budu 0 :D. Da li neko ima ikakvu ideju, kako da resim ovaj problem, hvala unapred.