|
Step one is to get a slider control and see what properties and events it exposes. Then go from there.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
This is easy to do with TrackBar Controls in WinForms, but, first, you have to precisely define what "linkage" is: do the TrackBars have independent value ranges, or, over-lapping ranges ?
If changing one TrackBar's value can change the other TrackBars' values, you'll need to prevent recursion.
Need a "read-out:" position a Label over the TrackBar and use that, or use a ToolTip.
Clarify your goal, and show some code.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I want one track bar to hold the total of the other track bars. So if the total is 100 the track bars added together can't add up to greater than 100.
Track bars set out like say:
10
20
50
20
Total 100
Or
30
10
30
30
Total 100
|
|
|
|
|
Okay, this a good first step in specifying behavior.
The next step is to define the minimum and maximum range for each trackbar; of course, you can change this at run-time with code.Member 13670442 wrote: one track bar to hold the total of the other track bars Are you saying that this trackbar sets the maximum value of the total of values of the other trackbars ? If so, how would changing its values affect the current values of the other trackbars ?
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Yes. The other track bars would be limited by the Total track bar. If the Total track bar is 100 all the track bars must add up to that track bar and no more. If I were to move the Total track bar down the other track bars move down too. Until they react zero.
50
10
10
10
10
Total 90
10
0
0
0
10
Total 20
If having the Total track bar isn't possible I could do it without a Total tack bar. I just need the code that will link multiple track bars together.
|
|
|
|
|
I'm trying to write an algorithm in C#, this algorithm includes so many transfer function in laplace space, such as 2nd order high-pass or low-pass filters, integrals and derivatives, I converted all of them into discrete form, but I don't know how to add them to my C# code. for example how can I implement this transfer function in C# code:
H(z)= 4/(2z+3)
|
|
|
|
|
Maybe I'm missing something, but isn't your example just:
public double H(double z)
{
return 4.0 / ( 2.0 * z + 3.0);
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am making a DAQ-Simulator that shall simulate generation of analog (0-1V) and digital 1 or 0 signals.
When I call my method sampling () and display the sensor data in my textbox, I always get the same numbers for my Analog sensors. Since this is a Random generation it should have been different numbers every time I click on Sample button
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
<pre lang="c#">namespace DAQ_Simulator
{
public partial class Form1 : Form
{
int counter;
int maxSid = 10;
int maxAI, maxDI;
string sTxt;
private DateTime datetime;
Sensor[] sObj = new Sensor[10];
public Form1()
{
InitializeComponent();
}
private void displaySensorData(object sender, EventArgs e)
{
}
private void groupSampl_Enter(object sender, EventArgs e)
{
}
private void textSampling_TextChanged(object sender, EventArgs e)
{
}
private void btnSampling_Click(object sender, EventArgs e)
{
sampling();
}
private void groupLogg_Enter(object sender, EventArgs e)
{
}
private void txtLogging_TextChanged(object sender, EventArgs e)
{
}
private void labelLoggingText_Click(object sender, EventArgs e)
{
}
private void btnLogging_Click(object sender, EventArgs e)
{
}
private void labelSensorValues_Click(object sender, EventArgs e)
{
}
private void textSensorValues_TextChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void sampling()
{
for (counter = 0; counter < maxSid; counter++)
{
sObj[counter] = new Sensor(counter);
}
for (counter = 0; counter < maxSid; counter++)
{
for (counter = 0; counter < 10; counter++)
{
sObj[counter] = new Sensor(counter);
}
for (counter = 0; counter < maxSid; counter++)
{
sTxt += sObj[counter].GetAnalogValue().ToString("F3");
textSensorValues.Text = sTxt;
}
textSensorValues.Text=sTxt;
}
}
}
}
This is my Sensor class where I call the GetAnalogValue() from:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAQ_Simulator
{
public class Sensor
{
double dVal;
bool bVal;
int sId;
Random rSensVal;
public Sensor(int id)
{
sId = id;
rSensVal = new Random(id);
dVal = 0.0F;
}
public double GetAnalogValue()
{
dVal += rSensVal.NextDouble();
return dVal;
}
public int GetDigitalValue()
{
Random bVal = new Random(2);
int digital = bVal.Next(2);
return digital;
}
public int GetSensId()
{
return sId;
}
modified 8-Feb-18 12:54pm.
|
|
|
|
|
You're specifying the same seed each time, so you'll get the same sequence of pseudo-random numbers each time.
You can generate the same sequence of random numbers by providing the same seed value to the Random(Int32) constructor.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Your Random instance is a local variable, which means you create a new one each time you call the GetDigitalValue method. Since the Random constructor begins the sequence with a seed value based on the computer clock, if you create several Random instances close together, it is very likely - particularly with modern fast computers - that the same seed value will be used, and as a result all teh instances will generate the same sequence.
Change your Random instance to a private static variable, and you will get different results.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: Since the Random constructor begins the sequence with a seed value based on the computer clock, ...
Except in the posted code, where each instance is passed a seed value. Either the index of the sensor, in the Sensor constructor; or 2 in the GetDigitalValue method.
So it's no wonder they always return the same sequence of values.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Dear All, Please kindly help me,
I am using Gridview in C# Windows Application and need your help to solve my issues bellow :
How i can make function in each cell column B which can automatically write words PASS and FAIL with the following Roles:
- First cell in column B : It will automatically write "PASS"
- Second cell in column B : If value in second cell column A less than Value in First cell column A then in second cell column B will Automatically "FAIL" otherwise will "PASS"
- Third cell in column B : If value in third cell column A less than value in First cell column A then in third cell column B will Automatically "FAIL" otherwise will "PASS"
Note : I am not using Database connection for GridView data,
GridView - Google Photos[^]
Sorry for my bad English words, Really appreciate and thanks in advance for help
Thanks,
Deden
modified 8-Feb-18 3:53am.
|
|
|
|
|
|
Use an Event handler for the column A. Whenever a cell's value changes you reset the appropriate cell in column B
|
|
|
|
|
Hi Richard, Thanks a lot for replied,
Actualy This is use for checking Log data from fingerprint device,
Cells on column A in Gridview will automaticaly fill by Log data from finger print,
I need column B to show the result PASS or FAIL
Please advice, Thanks in advance
|
|
|
|
|
Then you need to check which events get fired when the log data information arrives at the view. How is this done automatically?
|
|
|
|
|
I'd recommend calculating "pass" or "fail" before loading the data into a gridview. Gridviews shouldn't used to manipulate data, but to display it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
I am populating the root nodes of the treenode1 via the formload() function, I guess you could say they are hard coded.
After that I want to select a root node (which will be a domain) and enumerate the OUs of that domain and then make the outputted (via the code below) sub nodes of the root node (domain) that is already listed.
The function below makes the output, root nodes under the formload() created root nodes instead of subnodes under the formload() created root nodes, how can I make them subnodes of the original formload() root nodes?
Sorry if this is written in a confusing manner, I've tried to reread it and make it less confusing amidst my own confusion.
private void searchForOus(string ouPath)
{
DirectoryEntry ADentry = new DirectoryEntry(ouPath, @"domain\user", "password", AuthenticationTypes.Secure);
DirectorySearcher Searcher = new DirectorySearcher(ADentry);
Searcher.Filter = ("(objectClass=organizationalUnit)");
foreach (DirectoryEntry entry in Searcher.SearchRoot.Children)
{
Console.WriteLine(entry.Path);
if (entry.Path == "LDAP://OU=Core Member Servers,dc=XXX,dc=XXX,dc=XX,dc=XXX")
{
if (ShouldAddNode(entry.SchemaClassName))
{
treeView1.Nodes.Add(GetChildNode(entry));
}
}
}
private TreeNode GetChildNode(DirectoryEntry entry)
{
TreeNode node = new TreeNode(entry.Name.Substring(entry.Name.IndexOf('=') + 1));
foreach (DirectoryEntry childEntry in entry.Children)
{
if (ShouldAddNode(childEntry.SchemaClassName))
{
node.Nodes.Add(GetChildNode(childEntry));
}
}
return node;
}
private bool ShouldAddNode(string schemaClass)
{
bool returnValue = false;
if (schemaClass == "organizationalUnit")
{
returnValue = true;
}
return returnValue;
}
|
|
|
|
|
I don't see you creating the root node that you want to add sub-nodes to and using that outside the recursive call. See if this gives you some ideas:
1. take/create the selected root node of the file/directory structure
2. create the root level TreeNode that maps to root #1
e. recursively iterate the sub-nodes of #1, selecting by your 'should add' function
DirectoryEntry ADentry = new DirectoryEntry(ouPath, @"domain\user", "password", AuthenticationTypes.Secure);
DirectorySearcher Searcher = new DirectorySearcher(ADentry);
Searcher.Filter = "@(objectClass=organizationalUnit)";
string EntryPath = @"LDAP:/OU=Core Member Servers,dc=XXX,dc=XXX,dc=XX,dc=XXX");
string schemaClass = @"organizationalUnit";
TreeNode WorkingTreeNode;
private void searchForOus(string ouPath)
{
foreach (DirectoryEntry entry in Searcher.SearchRoot.Children.Where(ent => ent.Path == EntryPath))
{
Console.WriteLine(entry.Path);
WorkingTreeNode = new TreeNode(entry.Name);
treeView1.Nodes.Add(WorkingTreeNode);
if (ShouldAddNode(entry.SchemaClassName))
{
WorkingTreeNode.Nodes.Add(GetChildNode(entry));
}
}
}
} Note: this code "sketch" has not been compiled/tested; use it for ideas, only.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I have to make an app where the users inputs the # of units they purchased in a text box. Then, they click a "calculate" box and it yields 3 labels: Their % of savings, their amount saved, and their total after savings. Here is my code for the calculate button click event.
So first I declare my variables:
const double PACKAGE_COST_double = 99;
int purchased;
double retail;
double discountrate;
double saved;
double total;
Then I have my formulas for each of my variables:
purchased = int.Parse(purchasedTextBox.Text);
saved = (purchased * PACKAGE_COST_double) * discountrate;
retail = purchased * PACKAGE_COST_double;
total = retail * discountrate;
Then I have my if/else statement to determine what the discountrate is going to be:
if (purchased >= 100)
{
discountLabel.Text = "50%";
discountrate = .5;
}
else if (purchased >= 50 && purchased <= 99)
{
discountLabel.Text = "40%";
discountrate = .4;
}
else if (purchased >= 20 && purchased <= 49)
{
discountLabel.Text = "30%";
discountrate = .3;
}
else if (purchased <= 19 && purchased >= 10)
{
discountLabel.Text = "20%";
discountrate = .2;
}
else if (purchased >= 0 && purchased <= 10);
{
discountrate = 0;
}
And at this point I am pretty much lost. I am not sure what to do now. I know I need to incorporate a try/catch, I have a red line under discountrate when I use it in the first formula at the top, and I am not sure where to go from here. Any help/critiques/comments would be greatly appreciated!
|
|
|
|
|
|
You are trying to use the discountrate variable in a calculation before you have given it a value.
double discountrate;
purchased = int.Parse(purchasedTextBox.Text);
saved = (purchased * PACKAGE_COST_double) * discountrate;
You could also simplify your if else blocks.
And leave setting the label until the end by a simple calculation:
if (purchased >= 100)
{
discountrate = .5;
}
else if (purchased >= 50)
{
discountrate = .4;
}
else if (purchased >= 20)
{
discountrate = .3;
}
else if (purchased >= 10)
{
discountrate = .2;
}
else
{
discountrate = 0;
}
discountLabel.Text = string.Format("{0}%", discountrate * 100);
|
|
|
|
|
Thanks! I finished the assignment but I am quite sure that my code is very poorly written. I need help cleaning it up. I feel like it can be written with fewer variables and cleaner, fewer lines of code. (Also, to the guy who refers to himself as a "prick", I wasn't sure how to implement that thing into my code. I tried but I got an error. I do not know what that is. Thanks for your help though!)
Here's what I have so far!! (it works perfectly, as an application):
namespace Software_Sales
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
const double PACKAGE_COST_double = 99;
const double FIFTY_PCT_double = .5;
const double FORTY_PCT_double = .4;
const double THIRTY_PCT_double = .3;
const double TWENTY_PCT_double = .2;
const double ZERO_PCT_double = 0;
double retail;
double discountrate;
double saved;
double total;
int purchased;
purchased = int.Parse(purchasedTextBox.Text);
try
{
purchased = int.Parse(purchasedTextBox.Text);
if (purchased >= 100)
{
discountrate = .5;
saved = (purchased * PACKAGE_COST_double) * FIFTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else if (purchased >= 50)
{
discountrate = .4;
saved = (purchased * PACKAGE_COST_double) * FORTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else if (purchased >= 20)
{
discountrate = .3;
saved = (purchased * PACKAGE_COST_double) * THIRTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else if (purchased >= 10)
{
discountrate = .2;
saved = (purchased * PACKAGE_COST_double) * TWENTY_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
else
{
discountrate = 0;
saved = (purchased * PACKAGE_COST_double) * ZERO_PCT_double;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
}
discountLabel.Text = string.Format("{0}%", discountrate * 100);
totalLabel.Text = total.ToString("c");
total = retail - saved;
retail = purchased * PACKAGE_COST_double;
savedLabel.Text = saved.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|
|
As it is working I suggest you keep it in a safe place . However as I suggested earlier you can simplify your if/else blocks by removing the common code and putting it at the end. Also, why set the discountrate to a hard coded value when you previously declared constants for the various rates? So it could be something like:
if (purchased >= 100)
{
discountrate = FIFTY_PCT_double;
}
else if (purchased >= 50)
{
discountrate = FORTY_PCT_double;
}
else if (purchased >= 20)
{
discountrate = THIRTY_PCT_double;
}
else if (purchased >= 10)
{
discountrate = TWENTY_PCT_double;
}
else
{
discountrate = ZERO_PCT_double;
}
saved = (purchased * PACKAGE_COST_double) * discountrate;
retail = purchased * PACKAGE_COST_double;
total = retail - saved;
discountLabel.Text = string.Format("{0}%", discountrate * 100);
totalLabel.Text = total.ToString("c");
total = retail - saved;
retail = purchased * PACKAGE_COST_double;
savedLabel.Text = saved.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
|
|
|
|
|
Thanks so much! This is the simplest version I have been able to come up with. Can someone help me with my catch exception bit? It doesn't seem to work very well.
namespace Software_Sales
{
public partial class salesForm : Form
{
public salesForm()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
const double PACKAGE_COST_double = 99;
const double FIFTY_PCT_double = .5;
const double FORTY_PCT_double = .4;
const double THIRTY_PCT_double = .3;
const double TWENTY_PCT_double = .2;
const double ZERO_PCT_double = 0;
double retail;
double discountrate;
double saved;
double total;
int purchased;
purchased = int.Parse(purchasedTextBox.Text);
try
{
purchased = int.Parse(purchasedTextBox.Text);
if (purchased >= 100)
{
discountrate = FIFTY_PCT_double;
}
else if (purchased >= 50)
{
discountrate = FORTY_PCT_double;
}
else if (purchased >= 20)
{
discountrate = THIRTY_PCT_double;
}
else if (purchased >= 10)
{
discountrate = TWENTY_PCT_double;
}
else
{
discountrate = ZERO_PCT_double;
}
retail = purchased * PACKAGE_COST_double;
saved = (purchased * PACKAGE_COST_double) * discountrate;
total = retail - saved;
discountLabel.Text = string.Format("{0}%", discountrate * 100);
totalLabel.Text = total.ToString("c");
savedLabel.Text = saved.ToString("c");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|