What do you intend to do during the scan?
If you are looking for changes then you could use a FileSystemWatcher to do the "scanning" for you.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
To use the DataSource property of the data grid you must also bind any DataGridColumns you create to the columns of the data table. To do this you set the DataPropertyName property to the name of the bound column in the data table.
If you do not do this then the data grid creates new columns for each column in the data table. (Perhaps this is why you cannot change the colours of the cells when using DataSource.)
Setting cell colours when using a DataSource is best done in the DataGrid.CellFormatting event as the data grid uses this to determine how to display the cell.
The snippet below changes the background for modified cells.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
// get bound row for cell being formatted.
var drv = dataGridView1.Rows[e.RowIndex].DataBoundItem as DataRowView;
// if row not bound then ignore it
if (drv == null || drv.Row == null)
return;
// get local reference to row
var row = drv.Row;
// if row has original and current (new) value then test further
if (row.HasVersion(DataRowVersion.Current) && row.HasVersion(DataRowVersion.Original))
{
// get original and current values
object original = row[e.ColumnIndex, DataRowVersion.Original];
object current = row[e.ColumnIndex, DataRowVersion.Current];
// if original not same as current then change background colour of cell
if (!current.Equals(original))
e.CellStyle.BackColor = Color.PowderBlue;
}
}
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
try this
B162_Calc = Financial.IRR(ref testvalues, 1);
Thanks for the input but this thread is over a year old.
I think by now the original problem has probably been solved.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
@nick.crane please read this post by @EJP, be sure that this man has a true,
float has only 8 singnificant number possitions, otherwise loose precision in numeric form, double 11 or 12, you can test that by using String.format or DecimalFormat (by @Hovercraft Full Of Eels)
my post here only compare number output v.s. MsExcell, because everywhere is MsExcell, then I can't interesting about real number precision
Firstly, float is accurate to 7 (7.225) significant digits and double to 15 (15.995).
Re: post by @EJP: I question the accuracy of his test. if ((d % 0.01) != 0.0) is using the floating point modulus calculation!!
How accurate is that?
A better test is to compare the rounding against an integer equivalent.
Something like this.
public class RoundingCounterExample
{
private static double roundOff(double x, int position)
{
double a = x;
double temp = Math.pow(10.0, position);
a *= temp;
a = Math.round(a);
return (a / temp);
}
public static void main(String[] args)
{
int count = 0, errors = 0;
// integer loop (not inaccurate double loop)
for (int x = 0; x < 100000; x++)
{
count++;
// get rounded value using integers
// integer division always rounds down but Math.round rounds to nearest so use +50 to simulate this
int y = (x + 50) / 100;
// divide beyond integer division to test rounding function (d is now 1000 x smaller than y + a little bit)
double d = x / 100000.0;
// round d to 3 decimal places (rounded = y/1000) (little bit removed)
double rounded = roundOff(d, 3);
// multiply back up to integer level to test against y
int z = (int)(rounded*1000.0);
// check if value is OK
if (y != z)
{
// count errors
errors++;
}
}
// report error incidents.
System.out.println(count + " trials " + errors + " errors");
}
}
Note: I'm not a Java programmer. I used .Net to test this code and the error incident came out at 12 in 100000! By all means check it out for yourself.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
This is probably too late but I'll post it anyway.
@hfx642
Cashiers count up so as not to have to do the math. This is because people are much better at determining the unit boundaries for currency than are computers.
Counting up using a computer algorithm would be more complex than testing largest first as the OP is doing.
@CoolPrizes
The first hint you got from JamesCherill was the best one. (But you seemed to ignore it.)
This is a code snippet of what is meant by "you need to subtract that from the balance remaining".
double changeLeft = changeGiven;
int billBack20 = (int)(changeLeft / TWENTY_DOLLAR);
changeLeft = Math.Round(changeLeft - (billBack20 * TWENTY_DOLLAR), 2);
int billBack10 = (int)(changeLeft / TEN_DOLLAR);
changeLeft = Math.Round(changeLeft - (billBack10 * TEN_DOLLAR), 2);
The rest is up to you.
P.S. I tried using changeLeft -= billBack10 * TEN_DOLLAR; but when it calculated 10.35 - 10 the result was 0.3499999999999.
This resulted in a missing penny at the end. (Probably the same error is in that sample code you found).
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
You do not need to store every key the user types; the TextBox will do that for you. Just use the Text property when you need it.
If you use an OpenFileDialog the user can select the source file.
If you use a FolderBrowserDialog the user can select a destination folder.
If you still allow the user to type in a file name or folder path then you need to validate them using the System.IO.File.Exists and System.IO.Directory.Exists methods.
You could have a default folder or root folder which you add to any non-full paths the user gives you.
The ListBox has a SelectedItems property that contains only the selected items from the ListBox.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
In MS SQL Date is a keyword.
Not sure about MySQL but if it is the same then either:
1) Change your column name to something else.
or
2) Put [] around the column name in you command strings.
E.G UPDATE WaynokaLogger SET [Date] = @Date WHERE AccountID = @id
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Welcome to DaniWeb,
Please explain better what you are trying to achieve.
Also, post code of where you are having trouble so we know you have made some effort.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
@walid86 The way you coded it there is a problem with this line:
Console.WriteLine("Miles Per Gallon = {0:N2}", CalculateMilesPerGallon(289, 12.2));
Since CalculateMilesPerGallon is called it will cause an infinite recursive loop.
As I said before this line (and Console.Read(); ) needs to be in a separate method; more like this.
using System;
namespace MilesPerGallon
{
class MainClass
{
public static double CalculateMilesPerGallon(int milesTraveled, double gallonsUsed)
{
return milesTraveled / gallonsUsed;
}
public static void Main(string[] args)
{
Console.WriteLine("Miles Per Gallon = {0:N2}", CalculateMilesPerGallon(289, 12.2));
Console.Read();
}
}
}
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
When what do i write to stop it again..
p.kill();
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Just force the Checked property to false instead of the Enabled property. That way they both stay enabled, but only one is ever checked.
Alternatively, you could use RadioButtons instead. These automatically uncheck when one is clicked.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
As it seems you have control of both the called method and the UserControl override that calls the method you can choose where to do the error handling.
Remember that when a handler is called the Object sender parameter is the control that raised the event, so you could update the control state in the handler routine rather than in the controls event override.
private void textBox_TextChanged(object sender, EventArgs e)
{
var textbox = sender as TextBox;
if (textbox == null)
return;
// do something with textbox.
}
Or you could pass your own event args object (derived from the EventArgs object required for the handler).
// Your own custom EventArgs class (must derive from the class needed for the event called)
public class MyTextEventArgs : EventArgs
{
public bool OK { get; set; }
}
//Event override in UserControl
protected override void OnTextChanged(EventArgs e)
{
var args = new MyTextEventArgs();
base.OnTextChanged(args);
if (args.OK)
{
// do something
}
}
// Event handler function that returns a value using custom EventArgs
private void textBox_TextChanged(object sender, EventArgs e)
{
var args = e as MyTextEventArgs;
if (args == null)
return;
args.OK = true; // or false
}
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
OK, I found this thread that at the end discusses the very same issue.
There is no solution given but it made me think of something you could try.
Instead of setting the format back to Short in the ValueChanged event try using the CloseUp event which fires when the calendar window is closed.
(This worked fine when I tested it, but then so does using ValueChanged).
Let me know how you get on.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
So each post has its own vote count and each user has rep points.
If I up(down) vote a post I can choose to modify the posters rep by whatever is my current +/- rep effect and with that the comment I give is visible.
However, sometimes I wish to add a comment but not affect the rep points which it seems I can not do.:confused:
So then as well as "can't add reputation without influencing the vote count", I can't add a comment without adding reputation. Is this correct?
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Just could not resist trying this.
The code below moves the image inside the PictureBox; the PictureBox does not move.
The code paints the image in the PictureBox explicitly in the Paint event handler.
In fact this will paint the image on to any control; it could be a Panel or event the base Form.
It only handles one image but could be made to handle more by using arrays or collections in place of loadedImage and imageBounds.
Hope you like it.
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
openFD.InitialDirectory = "C:";
openFD.Title = "Select an Image";
openFD.FileName = "";
openFD.Filter = "JPEG Images|*.jpg|GIF Images|*.gif|BMP Images|*.bmp";
if (openFD.ShowDialog() == DialogResult.OK)
{
// load image to image object
loadedImage = Image.FromFile(openFD.FileName);
// set initial rectangle bounds for image
imageBounds = new Rectangle(new Point(), loadedImage.Size);
// refresh the picture box to show new image
pictureBox1.Refresh();
}
}
Image loadedImage = null; // image loaded from file
Rectangle imageBounds = new Rectangle(); // current position of image
Size SizeOfImageOffset; // offset of image relative to mouse while moving
bool imageClicked = false; // flag indicating mouse clicked on image
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
// test if mouse click inside image bounds
imageClicked = imageBounds.Contains(e.Location);
// capture relative position of mouse to Top,Left of image
SizeOfImageOffset = (Size)imageBounds.Location - (Size)e.Location;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
// if image was clicked and mouse is captured
if (imageClicked && pictureBox1.Capture)
{
// set new location for image based on relative mouse position
imageBounds.Location = (Point)(SizeOfImageOffset + (Size)e.Location);
// force re-paint of picture box
pictureBox1.Refresh();
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// always paint the image on the box (after it is loaded)
if (loadedImage != null)
e.Graphics.DrawImage(loadedImage, imageBounds);
}
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
So you won't see any changes persisted to the database.
Actually, if the database file in the project is marked as "Copy if newer" then it will only overwrite the copy in the Debug folder if you make changes to the database structure.
Also, the changes you make while running the program are written to the copy of your DB in the ..\bin\Debug folder.
You can examine this if you add this DB to your Server Explorer window; but always remember to close the connection before testing your program otherwise your program might not be able to open the DB.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
I just had a newbie bump a 2 year old thread; admittedly to ask for help with a similar problem.
This is most often done by new users who are not yet aware of Daniweb rules.
However, unless I am mistaken, there is no way of starting a new thread when viewing an existing thread.
Since Google and other search engines lead new users to existing threads and not the forum start pages this seems like an omission.
Do you think that adding a "Start a New Thread" button (perhaps with the post and advanced buttons) might reduce such bumping by new users?
[Edit]
Just realised that there is the small link in the "Over 3 months" text that will start a new thread.
This is clearly not big enough.
Alternatively, hide the message window for very old threads with a button to open it if really necessary.
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Struct are value types and passed by value by default.
Classes are reference types and passed by reference.
This is the only fundamental difference between the two formats.
As far as I am aware there is no difference in the memory consumed by a class or struct with the same fields.
There is very little point in using structs for anything of any real size unless you are performing data manipulation on unmanaged memory.
The example you give is better done as a class as it contains arrays which are a reference type.
Consider the following types
[Serializable]
public struct TestStruct
{
// Default level values
public int Value;
public int[] ArrayData;
public TestStruct(int value, int[] arrayData)
{
Value = value;
ArrayData = arrayData;
}
}
[Serializable]
public class TestClass
{
// Default level values
public int Value = 3;
public int[] ArrayData = new int[10];
}
When used they perform differently.
private void button2_Click(object sender, System.EventArgs e)
{
// make two classes with same values
TestClass testClass = new TestClass();
TestStruct testStruct = new TestStruct(3, new int[10]);
// copy the class to a new variable
var newTestClass = testClass;
// change the value of a property on the new variable
newTestClass.Value = testClass.Value + 20;
// test if the values are the same
if (testClass.Value == newTestClass.Value)
MessageBox.Show("Class values MATCH");
else
MessageBox.Show("Class values DO NOT match");
// copy the struct to a new variable
var newTestStruct = testStruct;
// change the value of a property on the new variable
newTestStruct.Value = testStruct.Value + 20;
// test if the values are the same
if (testStruct.Value == newTestStruct.Value)
MessageBox.Show("Struct values MATCH");
else
MessageBox.Show("Struct values DO NOT match");
// now lets test the value of one of the array elements
// change the value of a the first element on each of the four variables
testClass.ArrayData[0] = 10;
newTestClass.ArrayData[0] = 20;
testStruct.ArrayData[0] = 30;
newTestStruct.ArrayData[0] = 40;
// display the values of these
var sb = new StringBuilder();
sb.AppendLine("Array test values");
sb.Append("Original class:");
sb.AppendLine(testClass.ArrayData[0].ToString());
sb.Append("New class:");
sb.AppendLine(newTestClass.ArrayData[0].ToString());
sb.Append("Original struct:");
sb.AppendLine(testStruct.ArrayData[0].ToString());
sb.Append("New struct:");
sb.AppendLine(newTestStruct.ArrayData[0].ToString());
MessageBox.Show(sb.ToString());
}
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
Use Select() instead of Focus().
Focus() sets the visible cues of focus, it does not change the active control.
In BTn_Play_Click() at line 30 you only get input from TBx_P1.Text.
You need to choose which input box to use.
Testing the TBx_P1.Enabled property should work here.
If you are using random player start (or otherwise) then you could try toggling the current user like this.
TBx_P1.Enabled = !TBx_P1.Enabled; // toggle Enabled for player 1
TBx_P2.Enabled = !TBx_P1.Enabled; // set player 2 to not player 1
if (TBx_P1.Enabled)
TBx_P1.Select(); // select player 1 if enabled
if (TBx_P2.Enabled)
TBx_P2.Select(); // select player 2 if enabled
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3
How does this look.
var buttons = new[] { button1, button2, button3, button4, button5 };
Array.ForEach(buttons, b => b.PerformClick());
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 188
Skill Endorsements: 3