|
Hmm... seems more like this is the correct answer:
double Y = ((y + Math.Abs(dMin)) * (dHeight - 1)) / (dMax - dMin);
Y = dHeight - 1 - Y;
This works with:
lst.Add(0);
lst.Add(3);
lst.Add(7);
lst.Add(10);
With the commented and uncommented values.
dHeight = 30 (since the control is 30 pixels high, but the pixel range is 0 through 29)
With the original formula, the 0 would get to 29 correctly, but the 10 would only go to 1.72. With the -5 / 15 range, it would go to 0.43.
With this new formula, both ways got to 0 & 29.
|
|
|
|
|
Ok, now I'm really confused... the min & max points are working now, but it seems like points in the middle are all wacky.
If my control is 30 pixels high, the mid point is going to be 14, right?
so if I give it 0, 3, 7, 10, my min & max is 0 & 10. So one would expect 5.5 to map to 14, but its mapping to 13.05 .
|
|
|
|
|
NM... I think I'm on crack again... LOL... the new formula does work. If my range is 0 to 10, the mid point is 5. And the mid point on a control 30 pixels high, the pixel range is 0 to 29, so the mid point is 14.5 .
|
|
|
|
|
Actually, this is in a WPF application, so by WPF convention, its an IEnumerable of doubles .
LOL, I guess my late at night answer was pretty close... I confused the whole 0 - 29 / 30 / 20 / 21 thing haha...
|
|
|
|
|
Ah, so I was pretty close... I guess I shouldn't try to write code at 11pm LOL... got thrown off by the 0 / 1 0 - 29 = 30 points thing haha... when I woke up this morning, I was like what the hell was I thinking?
|
|
|
|
|
I've had many mornings like that.
|
|
|
|
|
Wait a sec here... I'm testing this out...
Lets say I pass in 0 through 10
So 0 should transform to 29
and 10 should transform to 0
0 through 10 is 11 pixels
((0 + 0) / 11 * 30) = 0, 29 - 0 = 29, so that works
((10 + 0) / 11 * 30) = 27.27, 29 - 27.27 = 1.73 which doesn't work.
even if I do the multiplication first,
((10 + 0) * 30 / 11) = 27.27
|
|
|
|
|
Yeah, I think something is amiss...
List<double> lst = new List<double>();
lst.Add(0);
lst.Add(3);
lst.Add(7);
lst.Add(10);
double dMin = lst.Min();
double dMax = lst.Max();
double dHeight = 30;
double y = 10;
double Y = ((y + Math.Abs(dMin)) * dHeight) / (dMax - dMin + 1);
Y = dHeight - 1 - Y;
System.Diagnostics.Debug.WriteLine(Y);
With the -5 to 15 range, it gets closer, 0.43, so I guess that's a round off... if I truncate everything to ints, it comes out even worse, to 2 instead of 1.72.
|
|
|
|
|
Thank you for my Sunday puzzle !
private Dictionary<int, int> MapRangeValues(bool flipSign, List<int> sourceRange, List<int> mapToRange)
{
var dctTransform = new Dictionary<int, int>();
double ratio = Convert.ToDouble(mapToRange.Max() - mapToRange.Min()) / (sourceRange.Max() - sourceRange.Min());
int offset = mapToRange[0] - sourceRange[0] + 1;
foreach (var sInt in sourceRange)
{
int val = Convert.ToInt32(ratio*sInt) + offset;
if (flipSign)
{
val = mapToRange.Max() - val - 1;
}
else
{
val--;
}
dctTransform.Add(sInt, val);
}
return dctTransform;
}
private List<int> DataRange = Enumerable.Range(-5, 21).ToList();
private List<int> ControlRange = Enumerable.Range(0, 30).ToList();
private void testTheSucker()
{
textBox1.Clear();
textBox2.Clear();
var result1 = MapRangeValues(true, DataRange, ControlRange);
var result2 = MapRangeValues(false, ControlRange, DataRange);
foreach (var kvp in result1)
{
textBox1.Text += string.Format("{0}\t{1}\r\n", kvp.Key, kvp.Value);
}
foreach (var kvp in result2)
{
textBox2.Text += string.Format("{0}\t{1}\r\n", kvp.Key, kvp.Value);
}
} I am curious to see if this is as general purpose as I intend it to be: so, will test further. I am sure this can be improved (perhaps replaced with a few lines of Linq wizardry ?), and I'd welcome any feedback, corrections, ideas !
// first test results
-5 29
-4 28
-3 26
-2 25
-1 23
0 22
1 21
2 19
3 18
4 16
5 15
6 13
7 12
8 10
9 9
10 8
11 6
12 5
13 3
14 2
15 0
// second test results
0 -5
1 -4
2 -4
3 -3
4 -2
5 -2
6 -1
7 0
8 1
9 1
10 2
11 3
12 3
13 4
14 5
15 5
16 6
17 7
18 7
19 8
20 9
21 9
22 10
23 11
24 12
25 12
26 13
27 14
28 14
29 15
«If you search in Google for 'no-one ever got fired for buying IBM:' the top-hit is the Wikipedia article on 'Fear, uncertainty and doubt'» What does that tell you about sanity in these times?
modified 23-Nov-14 7:51am.
|
|
|
|
|
Wow! You went all out .
Richards answer was kind of a 1 liner though . Although he wasn't converting a list which you are...
Thanks!
|
|
|
|
|
Hi All,
I'm already a somewhat experienced C# programmer. My experience in the .NET world (besides the knowledge of C# itself) is with WPF, Winforms and some WCF.
I wanted your opinion of a good book to learn DB programming using .NET. My primary goal is to learn how to interact with the DB, how to make queries, different type of queries, LINQ etc. Query languages like SQL is a secondary goal, but if you also know of a book that teaches both my primary and secondary goals in one, that would be great.
Thank you very much
|
|
|
|
|
For your interest in Linq and SQL, I'd like to recommend Scott Guthrie's series of nine blog articles on Linq to SQL, links to which are listed here in a recent reply of mine in QA: [^].
There are some (free) books on-line at SyncFusion (including two by noted CodeProject member, Marc Clifton, but his books are not about SQL or Linq) which may interest you: [^], like: "Windows Azure SQL Reporting Succinctly," "Postgres Succinctly", "Entity Framework Code First Succinctly", "Mongo DB Succinctly," and others.
«If you search in Google for 'no-one ever got fired for buying IBM:' the top-hit is the Wikipedia article on 'Fear, uncertainty and doubt'» What does that tell you about sanity in these times?
|
|
|
|
|
Dear folks,
As you know the ILog Diagram, provids with it's own way of drawing objects, it use matrix, and it use it's own coordinate system,
What i intend to do, is to create a search dialog box, which don't be placed over the Node (UserSymbol) it self, and be placed side to the found content.
I was wonder if there are any kinda of ability to find a Node position - which already showing in view port - in pixel positioning?!
I'm using DiagramView Component of iLog Diagram.
Thank you.
modified 23-Nov-14 2:00am.
|
|
|
|
|
Hi to all.
Did anyone already work on C# wrapper for PocketSphinx for converting speech to text and will ing to share some ideas?
Thank you!
|
|
|
|
|
It's very unlikely you're going to find anyone who has used that library here.
Try asking your question in the Forums on the SrouceForge site for it, here[^].
|
|
|
|
|
There is a C# wrapper for Sphinx, called SharpSphinx, here: [^].
I've never tried it.
«If you search in Google for 'no-one ever got fired for buying IBM:' the top-hit is the Wikipedia article on 'Fear, uncertainty and doubt'» What does that tell you about sanity in these times?
|
|
|
|
|
hello
I implement Breadth First Search (BFS)in AI, but I receive the following error message: Exception of type 'System.OutOfMemoryException' was thrown.
Can't get rid of error message to do anything?
Help.
my code is:
try
{
while (FIFO.Count != 0)
{
node = (Node)FIFO.Dequeue();
if (node.State.GoalTest())
{
while (node.ParentNode != null)
{
txtResult.Text += node.Actions + Environment.NewLine;
txtResult.Text += node.State.AsString() + Environment.NewLine;
txtResult.Text += "============================" + Environment.NewLine;
node = node.ParentNode;
}
return;
}
else
{
action[] a = new action[4];
s = node.State.Succ(out a);
for (int i = 0; i < 4; i++)
{
if (s[i] != null)
{
n.State = s[i];
n.Actions = a[i];
n.Depth = node.Depth + 1;
n.ParentNode = node;
FIFO.Enqueue(n);
n = new Node();
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
"txtResult" would become rather big, wouldn't it? Write the output directly to the console, as opposed to building a lot of strings. And look up a StringBuilder.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Without your data and debugging this it's kinda difficult to tell - but if you enqueue a node whose State causes GoalTest to return false and as a result the new node that creates has the same state, then your FIFO count will always be nonzero and you will add nodes until the system runs out of memory.
I'd start by using the debugger to step though the code and work out where it is going.
Eddie's suggestion of a StringBuilder is a very good one, though!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
First, If you continuously generate data, and mostly objects, they took lot of space, even though you destroy any link to object data
that's what i previously experience with win form game, which had many frame rendering in a second, the memory slowly became full, and in about 90% it generate such error.
so what i done was to call Garbage Collector manually, GC.Collect() took some time to process, so you better run it in separate trade , and also not per any cycle of your loop...
Once you call it, lot of memory goes free... (as i mention before, it only work for objects which there are no link to, and are lost in memory without any reference from your application to)
Second, you also don't seem to clear your result string, it always got a +=, mean it just keep on growing, though if it's just that simple loop i don't think it gonna matter, but since i don't see your variable declaration, I'm afraid it growth too much big, through other processes, or a loop contain this process, which cause you run out of memory.
modified 23-Nov-14 2:07am.
|
|
|
|
|
Hello,
I am running into some problems with a program that I've written and I need some help. It is a C# .NET 2.0 Winforms application. It is being executed from a network drive, and runs under Windows XPand Windows 7. The platform target is x86. It does some SQL queries, reading and writing to a file stored on a network using SQLite. There are certain operations, which are not repeatable, in which the
user will click and the program will simply stall, going into the hourglass (or spinning circle). Usually when this happens, the program will crash with "The application has stopped working" error. I have an
exception handler, but apparently it is not catching the problem.
What measures can I take to find out the problematic code? Or to correct the errors? The users of the program get frustrated when the crashes occur as it slows down their work.
Thanks
Mike
|
|
|
|
|
Intermittent errors are the worst to try and find: if you can't duplicate it, you can't fix it.
And "The application has stopped working" tells you (and I) nothing at all about why it stopped - it's a generic message that you app did something it wasn't supposed to.
So the first thing you need is information!
You are going to have to add logging to your app - to try and work out roughly where it is when it crashes. I'd suggest starting at a high level, and logging the rough areas the user is using: enter and exit event handlers to a file until you can get a "feel" for which handlers are causing the problem. Then you can focus more logging into the methods that calls to try and work out what it's doing. Using File.AppendAllText is the simplest method, and should be relatively unobtrusive (util you get down into the nitty-gitty of low level methods, anyway). Try to keep old log files by renaming them when your app starts.
Going to take a while, I'm afraid - but there isn't a lot else you can do until you know roughly what area it is crashing in.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Those kinds of errors typically happen in non-UI portions of your code, otherwise you'd get the familiar 'Unhandled Exception' dialog with the continue or quit buttons.
If I were a betting sort, I'd look closely at how you're handling (and likely not) exceptions within portions of code where your SQL queries are run.
Sounds like some attempt(s) made to connect fail or abort, and then the code crashes due to the unhandled exception taking place (likely in another thread or class).
The madman is not the man who has lost his reason; the madman is the man who has lost everything except his reason.
--G.K. Chesterton
|
|
|
|
|
The only thing you can do in situations such as this, is to try and do some debugging to find out where it is hanging, and what circumstances are occurring at the time. What operations are the users doing, and what does that cause the application to do? Is it perhaps getting stuck accessing the network drive?
|
|
|
|
|
I have a GridView control with a few ButtonFields. What I want to achieve is to avoid the full post back when the user clicks one of these buttons. My idea is to use AsyncPostBackTrigger, but the problem is that it requires a ControlID and the ButtonField doesn't have an ID. I tried to add a regular Button to the Controls collection of the ButtonField, but it still doesn't invoke the RowCommand event.
|
|
|
|
|