|
Hi All,...
I am reading into a rich text box a small number (0.385 to 0.457) which is read into a Rich Text Box as a string
and my though was to use Text.ConvertTo(float) in the following way
Value_Extract = ((Convert.ToDecimal(rtbIncoming.Text));
Value_Extract is a float...
This does not work compiles and Bang falls over when run, had look on Stack Overflow they seem to do in a similar way. Is this the correct way?? As VS helpfully tells me I need to cast a float as a decimal, decimal.tryparse??
modified 3-Jan-24 8:25am.
|
|
|
|
|
I typically use float.TryParse(string, out float result); This returns true if successful and false if not.
HTH
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
Hi,
Thanks for that float.TryParse(), will I be able to get out as a floating point?..
|
|
|
|
|
Yes:
if (float.TryParse(myTextBox.Text, out float result))
{
Console.WriteLine(result);
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Are you sure it compiles? String doesn't have a ConvertTo method, and you can't pass the Decimal type as an argument like that.
Assuming the text is a valid number, then Convert.ToSingle(rtdData.Text) should give you a float back. Or Convert.ToDecimal(rtdData.Text) would give you a decimal , which you would then have to cast to store in a float variable.
But these methods will throw an exception if the text is not a valid number. It would be better to use float.TryParse / decimal.TryParse so that you can notify the user if the value can't be parsed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay, I will give that a go...
It hasn't crashed yet!!
modified 3-Jan-24 9:04am.
|
|
|
|
|
I notice that VS Intellisense wants to tag every LINQ query I code with ".ToList()".
It is in fact an extra step that imposes unnecessary overhead when all you need is an IEnumerable in the chain. It just gets worse as the "frame rate" increases. While List<> is prefered "internally", it doesn't pay to be reflex "converting" when it isn't necessary. (IMO)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
It doesn't "want" to append it. It's just that the "AI" has seen it so much in all of the code in its training repositories that it thinks that's what is most likely to come next.
|
|
|
|
|
I doesn't "want" to but can't help itself? Caught up in the herd mentality? And that makes it "OK"?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
An AI in only as good as the training set it's taught with, so yeah, you could say it's following the heard.
I never said that makes it "OK". All I said is what it's doing.
|
|
|
|
|
lol. Yep.
I have certainly seen developers do that. They can't figure out how to do it in the initial clause so they end up processing it in memory.
Definitely not a good thing for working with a database.
Sigh...unfortunately I have also seen this happen implicitly by the library. I can see it by profiling in SQL Server while running a linq expression. That makes everything horribly wrong. It means I have no way to verify except by profiling everything.
I have seen all of the following by profiling.
- It dragged the entire table into the app space and then applied the clauses.
- It did an in clause by doing a while loop over each in parameter. So 200 separate SQL calls.
- It did a join by doing a different SQL call for each table and then joining in memory.
None of the above makes me want to ever use linq again.
|
|
|
|
|
Just use your best judgement as always. Intellisense helps you type faster (some of the time), but it's no substitute for intelligence.
ToList'ing everything all the time is obviously silly.
|
|
|
|
|
It really depends what I want to do with the list. I'll leave it as an enumerable until the point I want to do more than one thing with it. Suppose I wanted to check to see if the list had something in it before I started processing in it - the fact that I'm going to be calling Any and foreach (for example), suggests to me that I should materialise the enumerable and then act on it. If I don't, I'm just going to end up materialising it twice under the covers.
|
|
|
|
|
Hi,
I'm looking for a solution to make a circular slider control like volume control with the value inside.
I'm working on a winform.
If someone have a tips on an idea to start.
Thanks for your help
|
|
|
|
|
This is not exactly what you have asked for - nut perhaps an inspiration for doing :
Search[^]
|
|
|
|
|
write the C# windows form based program that allow user conversion of number system
|
|
|
|
|
And if I refuse?
After all, this is your assignment, not ours.
Now, if you have questions about the assignment, things you're having problems with, fine, ask your questions and describe your problems.
|
|
|
|
|
1. Learn basics of C#
2. Learn basics of converting between number systems (this is NOT a coding process)
3. Learn how to code 2 in C#.
4. Learn how to do a UI in C#
4. Put 1 to 4 together to create the solution.
|
|
|
|
|
|
Sounds more like an "architecture" thing than a coding thing.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
nice quote (and I'm french) ... even if I'm not a fan of Napoleon.
We coded then for me it is a code but true it's also about architecture, or to be more accurate it is how we code an architecture.
|
|
|
|
|
How to make an easy messenger with C#?
|
|
|
|
|
You start with a set of GOOD requirements and specifications.
Seriously, your question isn't answerable. You, and by extension we, know nothing of what you want this app to do, what devices you want to support, the type of interface, message delivery options, message caching, storage requirements, nothing at all!
We know nothing about you either and your skill set. The fact that you're even asking this question and how you asked it suggests your skills are quite limited, so that's going to be a rather large problem.
|
|
|
|
|
Console.Write( "Hello, world!" );
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
namespace ATAS.Indicators.Technical
{
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using ATAS.Indicators.Technical.Properties;
using OFT.Attributes;
[DisplayName("5.Heiken Ashi Z")]
[Category("# 1234")]
public class HeikenAshiz : Indicator
{
private readonly CandleDataSeries _candles = new CandleDataSeries("Heiken Ashi Z"){ Visible = true };
private readonly PaintbarsDataSeries _bars= new PaintbarsDataSeries("Bars Z"){ Visible = false };
public HeikenAshiz()
{
Panel = IndicatorDataProvider.NewPanel;
DataSeries[0]= _bars;
DataSeries.Add(_candles);
}
protected override void OnCalculate(int bar, decimal value)
{
var candle = GetCandle(bar);
_bars[bar] = Colors.Transparent;
if (bar == 0)
{
_candles[bar] = new Candle()
{
Close = candle.Close,
High = candle.High,
Low = candle.Low,
Open = candle.Open
};
}
else
{
var prevCandle = _candles[bar - 1];
_candles[bar] = new Candle()
{
Close = (candle.Open+candle.Close+candle.High+candle.Low)*0.25m,
High = candle.High,
Low = candle.Low,
Open = (prevCandle.Open+ prevCandle.Close)*0.5m,
};
}
}
protected override void OnApplyDefaultColors()
{
if (ChartInfo is null)
return;
_candles.UpCandleColor = Color.FromRgb(14, 203, 129);
_candles.DownCandleColor = Color.FromRgb(246, 70, 93);
_candles.BorderColor = Color.FromRgb(127, 127, 127);
}
}
}
modified 7-Dec-23 2:55am.
|
|
|
|