-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextBoxBaseParsers.cs
More file actions
75 lines (74 loc) · 2.44 KB
/
Copy pathTextBoxBaseParsers.cs
File metadata and controls
75 lines (74 loc) · 2.44 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Physics_Data_Debug
{
public class TextBoxBaseParsers
{
public static double Parser(TextBoxBase textBox, double defaultVariable, bool isNegativeCheck)
{
double variable;
if (double.TryParse(textBox.Text, out double parse))
{
if (isNegativeCheck == true)
{
// Here you already can use a valid double 'doubleValue'
if (parse >= 0) // It's a positive number.
{
variable = parse;
}
else // Negative returns to default
{
textBox.Text = defaultVariable.ToString();
variable = defaultVariable;
}
}
else
{
variable = parse;
}
}
else
{
// Here you can display an error message like 'Invalid value'
textBox.Text = defaultVariable.ToString();
variable = defaultVariable;
}
return variable;
}
public static double HistoryAmountPointsParser(TextBoxBase textBox, double defaultVariable, bool isOverTwoCheck)
{
double variable;
if (double.TryParse(textBox.Text, out double parse))
{
if (isOverTwoCheck == true)
{
// Here you already can use a valid double 'doubleValue'
if (parse >= 2) // It's a positive number over 2.
{
variable = parse;
}
else // Negative returns to default
{
textBox.Text = defaultVariable.ToString();
variable = defaultVariable;
}
}
else
{
variable = parse;
}
}
else
{
// Here you can display an error message like 'Invalid value'
textBox.Text = defaultVariable.ToString();
variable = defaultVariable;
}
return variable;
}
}
}