|
Finally, I found the problem. I tried to use C# class library (NetFrameWork) instead of C# class library core.
|
|
|
|
|
Yes, targeting can be quite complicated these days.
If the library targets .NET Framework, then it can be referenced by applications targeting any version of .NET Framework greater than or equal to the target version. But it cannot be referenced by applications targeting .NET Core or .NET 5/6.
If the library targets .NET Standard 2.0, then it can be referenced by applications targeting .NET Framework 4.6.1 or later, .NET Core 2.0 or later, or .NET 5/6. But you won't be able to use the new features introduced in .NET Core 3.0 or .NET 5/6.
If the library targets .NET Standard 2.1, then it can be referenced by applications targeting .NET Core 3.0 or later, or .NET 5/6. It cannot be referenced by applications targeting any version of .NET Framework. You will be able to use the new features introduced in .NET Core 3.0, but not those introduced in .NET Core 3.1 or .NET 5/6.
If the library targets .NET Core, then it can be referenced by that version of .NET Core, later versions of .NET Core, or .NET 5/6. It cannot be referenced by applications targeting any version of .NET Framework.
If it targets .NET 5, then it can only be referenced by applications targeting .NET 5/6.
This is Microsoft's idea of simplifying things!
.NET Standard | Microsoft Docs[^]
Oh, and there's also the option of multi-targeting, in case the above options weren't complicated enough:
Multi-targeting for NuGet Packages in your project file | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Why such a complex piece of code to solve a simple problem?
public int NumberExtract()
{
if (!Int32.TryParse(text, out value)
{
throw new FormatException("text is not a valid number");
}
return value;
}
|
|
|
|
|
Maybe the numerals exist inside text that also contains alpha characters.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
If you throw an exception when input is invalid you can use Parse instead
|
|
|
|
|
If you think the problem is DevExpress related, try their (excellent) support forums.
public bool TryGetDigits(string str, out int iresult)
{
StringBuilder sb = new StringBuilder
(
new string(str.Where(ch => Char.IsDigit(ch)).ToArray())
);
if (Int32.TryParse
(
sb.ToString(),
out iresult)
)
{
return true;
}
return false;
} usage:
int iresult = 0;
bool gotSomeDigits = TryGetDigits("2ergtgwegwg1", out iresult);
if (gotSomeDigits )
{
}
else
{
}
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
I'm not sure why you've got the StringBuilder in there? You've already created the string you need and passed it into the constructor.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: I'm not sure why you've got the StringBuilder in there? Because little embroidered habanera peppers on old blue jeans is ... intriguing ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Hi.
I use C# in Visual Studio and SQL Server. In my form I have a label that receives the name of a bank and a Textbox that must be filed with the bank balance. This couple repeats for the number of bank accounts of the client. After I retrieve the balances, I use the following snipet:
if (TabSaldo.Rows.Count > 0)
{
for (i = 0; i < Nbancos; i++)
{
foreach (Control c1 in Gb_Bancos.Controls)
{
if (c1.Name.Contains("Lb_Banco" + (i + 1).ToString()))
c1.Text = LinhaSaldo[i].ItemArray[1].ToString();
if (c1.Name.Contains("Tb_Banco" + (i + 1).ToString()))
{
c1.Text = LinhaSaldo[i].ItemArray[2].ToString();
TotalBancos += float.Parse(LinhaSaldo[i].ItemArray[2].ToString()) / 100;
}
}
}
}
It's working fine, but when I make the conversion from string to float (line starting with (TotalBancos +=) the conversion ignores the decimal point. Example: if the balance is 113,54 it sums 11354. As you see, I had to include a division by 100, for it to work. Please does anyone know what is wrong here?
Thanks.
|
|
|
|
|
Why are you converting something to a string in order to parse it to a float?
Either it's a string to start with - in which case it's a waste of time and looks like the coder didn't know what he was doing - or it is a numeric value already - in which case why are you trying to parse it at all?
If I try to abstract your code:
float tb = 0.0F;
tb += float.Parse("666.66") / 100;
Console.WriteLine(tb);
Then I get what I expected: 6.6666 so there are a couple of possibilities:
1) LinhaSaldo[i].ItemArray[2] is not the value you expect it to be.
2) TotalBancos is not a floating point variable.
We can't check either of those so, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"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!
|
|
|
|
|
Hi, OriginalGriff.
I use debugging and the values retrieved are correct. The line
LinhaSaldo[i].ItemArray[2]
is used because of the code:
DataTable TabSaldo = Banco.LeSaldoBanco(Dtp_DataSaldo.Text);
DataRow[] LinhaSaldo = TabSaldo.Select(null, null, DataViewRowState.CurrentRows);
In this code I retrive data from the database and LinhaSaldo is used to access the data. The only form to do this that I know is by doing:
c1.Text = LinhaSaldo[i].ItemArray[2].ToString();
I've put messages to show me the retrieved values and they are OK, but after the line above, they are multiplied by 100. In other words, the decimal point was ignored. I´v tried many things, but none works. I also executed the program step by step, but nothing.
If you have any suggestion, I would apprecciate it.
|
|
|
|
|
You should not use float or double types in financial applications, as they can lose precision. Use the Decimal type or convert all values to the smallest denomination (cents etc.) and use integers..
|
|
|
|
|
Richard.
I changed the types. Thanks for your help.
|
|
|
|
|
Could, in addition to the ideas from the other respondents, be a culture thing. In some cultures, ',' is a thousands separator so your 113,54 could be treated as a misplaced thousands separator and assumed to be 11,354 which is 11354. If in your culture ',' is a decimal separator (which I am guessing is why you are dividing by 100 to get 113.54 [using my locale's decimal separator]) and your program is not using the same culture then it will misinterpret the value.
See, for example, c# - float.Parse() doesn't work the way I wanted - Stack Overflow[^]
See, for example, Single.Parse Method (System) | Microsoft Docs[^] (I know this is for single, rather than for float; but they work the same way and the version for float is playing hide-and-seek).
|
|
|
|
|
Hi, jsc42.
I tried what you suggested and it aparently works.
Thanks.
|
|
|
|
|
Hello.
I'm programming in C# with Visual Studio using forms.
I have a form with 8 textboxes, inside a groupbox. Depending on the data I retrieve from a database, I need to make some of them invisible. So, at running time I have to make them invisible. The names of the Textboxes are Tb_1, Tb_2 an so on. For example, if I retrive the number of fields as 6, I must make 2 of them invisible (the last 2). Can anybody help me do this?
Thanks.
|
|
|
|
|
|
To add to what Gerry has said, you can set the visibility without knowing the names, provided they are added to the GroupBox in the right order (you can reorder them by editing the myCodeFile.designer.cs file carefully):
int tbNo = 0;
foreach (control c in MyGroupBox.Controls)
{
if (c is TextBox tb)
{
tb.Visible = tbNo++ < numberYouWantToSee;
}
}
"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!
|
|
|
|
|
Hi OriginalGriff.
I think your solution works fine. Thank you.
|
|
|
|
|
A better design is to make them disabled (control.enabled = false) instead of playing with the visibility. Then you avoid having controls in different places or holes in your form.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
A generalization. Nothing wrong with collapsing part of the UI if it provides more real estate where it's needed and wanted depending on the context. You just need a (anchor) "plan" that doesn't disorient. No different than toggling ribbons, toolbars, menus, popups and the like.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Of course it is a generalisation but disabling is still generally the accepted solution. If real estate is such a problem then introduce the OP to tabs!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hi,
In the past I've dealt with this issue (UI holes) in different ways, depending on layout; in a TableLayoutPanel, you can hide rows or columns by setting width or height to #0.
In a Panel, docking can be used to resize visible controls when other controls are hidden: accordion style controls are easily created.
I don't think the OP here needs these techniques, or, I'd post an example.
Depending on context, and end-user, a "hole" may be better than "pretty" ... its "absence" can convey information.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Hi,
The following code causes error when the active sheet has a name other than "DataSet1". I want to handle errors in these codes:
IWorkbook workbook = spreadsheetControl.Document;
Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;
try
{
spreadsheetControl.Invoke((MethodInvoker)delegate { workbook.Worksheets.ActiveWorksheet = workbook.Worksheets["DataSet1"]; });
}
catch (ArgumentOutOfRangeException ex)
{
MessageBox.Show(ex.ToString());
return;
}
But, there is runtime error inside Try block that says:
Quote: System.ArgumentOutOfRangeException: 'Worksheet with this name is not found.
How can I control error handing in this situation?
modified 31-Jul-21 23:07pm.
|
|
|
|