|
If I copy'n'paste your code into an online C# compiler:
using System;
public class Program
{
public static void Main()
{
string inputString = "A1+0001852Kg 054";
string weightValueString = inputString.Substring(3, inputString.IndexOf("Kg") - 3);
Console.WriteLine(weightValueString);
double weightKg = double.Parse(weightValueString) / 1000;
string formattedWeight = weightKg.ToString("N2");
Console.WriteLine(formattedWeight);
}
} And run it, I get what I expect:
0001852
1.85 Which means that the problem isn't the code: it's the input string that you are actually processing - and we have no access to that, to it's source hardware, or to the code that reads it from the machine.
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!
modified 16-Mar-23 3:19am.
|
|
|
|
|
|
You do have to wonder sometimes, don't you?
"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!
|
|
|
|
|
I'd say for the OP to use N3, rather than N2, but as I can't see the question on the page right now, I can't directly answer it.
|
|
|
|
|
That bit of code without the initial string assignment and the usual "It don't work" message I'm afraid.
"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!
|
|
|
|
|
Ah, the usual "here are all the steps I've tried, debugging operations I've undertaken, logs and traces", where the OP has reached out as a last resort eh?
|
|
|
|
|
And even delete his own question! Cleans up after himself.
|
|
|
|
|
I have an update process in my app that downloads an installer and runs it. If the user cancels the installer it throws a Win32Exception. The problem is that in the Catch all I get is the Exception with the message "The operation was cancelled by the user". Other than the text of the message, there's really no way to know for sure what exception occurred. I don't want to rely on the exception message.
Any way to trap this specific issue?
Here's my code:
private static void StartInstaller()
{
try
{
_ = Process.Start(_localSetupFile);
Process[] processes;
do
{
processes = Process.GetProcessesByName(_processName);
Thread.Sleep(1000);
}
while (processes.Length == 0);
}
catch (Win32Exception e)
{
}
catch (Exception e)
{
throw;
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Is the installer an .MSI?
|
|
|
|
|
Have you looked at ClickOnce? I have a Silent Updater for .Net Framework v3.5+ that takes out all of the hard work: Silent ClickOnce Installer for Winform & WPF in C# & VB[^]. If your app is Dot Net Core Framework, I have a new article that I will release very soon, just need to finish the article writeup.
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
Win32Exception has a NativeErrorCode property which should return 1223 (0x4C7) when the user stops a process starting at a UAC prompt.
An example from my own code where I do something similar is probably clearer than more words!
private static void RestartWithRunAs(ProcessStartInfo psi) {
psi.UseShellExecute = true;
psi.ErrorDialog = true;
psi.Verb = "runas";
try {
Process.Start(psi);
} catch (System.ComponentModel.Win32Exception exc) {
const Int32 CancelledByUser = 1223;
if (exc.NativeErrorCode != CancelledByUser) {
throw;
}
}
}
See also
System Error Codes (1000-1299) (WinError.h) - Win32 apps | Microsoft Learn[^]
Alan.
|
|
|
|
|
Thanks. I'll give it a try
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
If this is not allowed please delete...
I'm looking for a programmer that can help me with a c# program I've started.
It's a CAD style program to design simple framework structures.
It's not a project for a larger development company, and I've tried websites that advertise professionals.
Mostly looking for help, but if someone is available to do more thats great too!!
Thanks,
Tom
|
|
|
|
|
This is not a recruitment site: I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
"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!
|
|
|
|
|
Understood. That's why I began with delete if not permitted.
Not trying to recruit or poach. looking for help with a program I'm writing.
|
|
|
|
|
There is also Fiverr[^] and Triplebyte[^]. The last one looks better than Fiver or Freelancer.
Hope this helps.
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
I've just noticed a new icon at the bottom right of CP messages. Just before the orange ribbon icon (bookmark this) and red flag icon (abusive / inappropriate / spam) there is now a bent black arrow icon. I haven't risked clicking it as there is no tooltip to say what it does. Does anyone know what is it for?
|
|
|
|
|
It just appears to be another way to get a link to the current message.
"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!
|
|
|
|
|
Thanks!
It does not seem to save any keystroke / mouse actions:
Old way
1) Right click message title in hierarchical list of topics
2) Select 'Copy Link' from popup menu
New way
1) Left click new arrow icon
2) Ctrl-C to copy the link
I'll request a tooltip to show what it does in 'Bugs and Suggs' (if no one has beaten me to it) as it is not intuitive
|
|
|
|
|
From the brief description is that I know there are a lot of existing applications, commercial and free that could already be described that way. So if you think you have a new product idea then hopefully you researched what is out there already.
If you just want to create this for yourself then you can create an open source site, start the code and then attempt by posting at other sites to convince others to contribute. But like the previous suggestion you need a vision that makes your idea (goal) unique.
If you are looking for a mentor then the scope of what you are attempting (again from the description) is not all that small so I am not sure you would find that just by looking online. Rather a heavy commitment. But perhaps paying for it as suggested might work. But you need to be specific about the mentoring part.
|
|
|
|
|
TBH, help is what I would like the most.
I'm in a very small industry.
It's more application specific and tools for what I do, is what I need.
I've written several LISP routines for AutoCAD that help however It only goes so far.
It's true a full CAD program is a huge commitment.
What I need is help with a few things, but I value peoples knowledge and time.
That's why the offer to hire a programmer. Never wanting to insult anyone's abilities.
Thanks!!
|
|
|
|
|
If the project is small enough then you should be able to hack your way through it with time.
If you know it isn't small then your choices are limited to the following
1. As I suggested, open source the site and then attempt to drum up interest.
2. Stop attempting to create the product and instead create a company that will build the product. You describe it and others build it. If the need exists in the 'small industry' and there is in fact a need and a way to monetize it then it should be possible to find someone to provide the seed capital to build it. Then instead of you building it you hire one or two others to build it. You will also need to find someone to sell it.
|
|
|
|
|
This will make more sense if my other message goes through.
But I'm also kind of embarrassed by my lack of knowledge.
What I've written so far does a lot but I struggle with understanding what feels like should be basic knowledge....
|
|
|
|
|
Here's a thought: since this is a "help" site (among other things), why don't you ask some "technical" questions that may give you some traction on your project instead of simply trying to hire a programmer, blind. The surest way to get scammed is to be as ignorant of the "true" nature of your project as possible.
"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
|
|
|
|
|
Hello community,
Looking for new contacts in Freiburg who want to work with me on an 8-bit music studio.
[Version]
[x] Smartphones and IPhones
[x] Standalone for Windows, Linux and MAC
[x] VST plugin
[Need Help]
[x] Musicians & DJ who like 8bit sounds are very welcome.
[x] .Net programmer for Linux, Windows and Mac
[using]
[x] GeorgRottensteiner SharpSid
[x] NAudio
[x] VST.NET
[x] sfxr
Greetings
Eric
|
|
|
|