|
Let sp be StartPoint and ep be EndPoint...
1. Calculate the current length
float len = sqrt(exp(sp.X - ep.X, 2) + exp(sp.Y - ep.Y, 2));
2. Calculate the ratio of the new length to the old length
float rat = newLen / len;
3. Using the rule that scaling a triangle maintains length ratios...
Point resultEp = new Point(rat * (ep.X - sp.X) + sp.X, rat * (ep.Y - sp.Y) + sp.Y);
then the line from sp to resultEp will have length newLen.
Jeff
|
|
|
|
|
OK - this is a maths problem not a programming one. Anyway, you shouldn't look at applying just a distance - you really need to apply a direction, i.e. treat it as a vector, because the new point will depend on the direction as well as the distance.
|
|
|
|
|
|
i want to create a small application that gives a txt file from user and send it to a fax number!
how can i use FaxModem to do it?
is there any function,dll,component...??
Imposible is Imposible...
|
|
|
|
|
A quick google search reveals some good hits, include this CP article[^].
|
|
|
|
|
Hi,
I am currently designing a project, which requires dynamic plugins to be added to the main application, which get loaded during runtime.
However, I am not sure about the correct way to implement this. Is reflection the right way to go about this? Does anyone know a good example or site where I can find further info on dynamic plugin handling in c# code?
Thanks...
|
|
|
|
|
|
Thanks,
that's actually what I was looking for
Just for anyone else checking further on this, there is also an excellent article at msdn: http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
and it comes with an example, which loads the plugins dynamically.
|
|
|
|
|
You're welcome
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
Hi every body,i'm C# beginner
i want to know the specification of avi file format.
i had searched for it and i had got some results from many sites but not useful "For me" i cann't
know the order(offset) of data fields in the avi files.
i want a simple specification like this specification
http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/[^]
|
|
|
|
|
Does AVI even have a specific format? I thought it depended on the codec that was used.
For example, you can have an AVI file that is divx, but if you don't have the divx codec on your machine, you can't view it.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
I have written the code belowin anticipation of verifying, assigning and lastly insert the Value into a DB table. The ver ification work as inteded but if I can all it in the Insert Method or in the Submit click event it does not work. if the field contains data it saves it to the DB but no everification is done. The Validation itself works fine but when called in the insert method it does not validate and the inserts execut without validating the values. Any assistance will be greatlly apprciated.
private bool isUserIDEmpty()
{
return(txtUserID.Text.Length==0);
}
private bool isFNameEmpty()
{
return(txtFName.Text.Length==0);
}
private bool isMidNameEmpty()
{
return(txtMidInitial.Text.Length==0);
}
private bool isLNameEmpty()
{
return(this.txtLName.Text.Length==0);
}
private bool isSSNEmpty()
{
return(this.txtSSN.Text.Length == 0);
}
internal void ValidateAndAssignValues()
{
Queue messages = new Queue();
Control focusControl = null;
if(!isUserIDEmpty())
{
EmpID = this.txtUserID.Text;
}
else
{
messages.Enqueue("Please Enter a User ID");
focusControl = this.txtUserID;
}
if (!isFNameEmpty())
{
FName = this.txtFName.Text;
}
else
{
messages.Enqueue("Please Enter a First Name.");
if(focusControl == null)
focusControl = this.txtFName;
}
if(!isSSNEmpty())
{
if(isSSNNineDigits()!= true)
{
messages.Enqueue("You have not enter nine characters");
if (focusControl == null)
focusControl = this.txtSSN;
}
else
{
try
{
SSN = int.Parse(this.txtSSN.Text);
}
catch
{
messages.Enqueue("Please Enter a valid SSN. Please ensure that you have entered numbers only.");
if (focusControl == null)
focusControl = this.txtSSN;
}
}
}
if (messages.Count > 0)
{
StringBuilder sb = new StringBuilder();
bool first = true;
foreach (string message in messages)
{
if (first)
first = false;
else
sb.Append('\n');
sb.Append(message);
}
lblError.Visible = true;
lblError.Text = sb.ToString();
}
else
{
lblError.Visible = false;
lblError.Text = "";
}
if (focusControl != null)
focusControl.Focus();
}
internal void InsertIntoDatabase()
{
ValidateAndAssignValues()
try
{
SqlCommand cmd = newSqlCommand ("SP_InsertEmployeeRecord",conDatabase);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Emp_Login_ID",EmpID ));
cmd.Parameters.Add(new SqlParameter("@Emp_SSN", SSN));
cmd.Parameters.Add(new SqlParameter("@Emp_First_Name", FName));
cmd.Parameters.Add(new SqlParameter("@Emp_Middle_Name", MidName));
cmd.Parameters.Add(new SqlParameter("@Emp_Last_Name", LName));
cmd.Parameters.Add(new SqlParameter("@Emp_Birth_Date", DOB));
cmd.Parameters.Add(new SqlParameter("@Emp_Hire_Date", HireDate));
cmd.Parameters.Add(new SqlParameter("@Emp_Position", Position));
cmd.Parameters.Add(new SqlParameter("@Emp_Sex", Sex));
conDatabase.Open();
cmd.ExecuteNonQuery();
}
catch(Exception G)
{
this.lblError.Text = (G.Message);
this.lblError.Visible=true;
}
conDatabase.Close();
this.lblError.Visible=true;
this.lblError.Text = "You record have been saved";
}
-- modified at 15:38 Monday 19th November, 2007
Skan
If you knew it would not compile why didn't you tell me?!?!?!
|
|
|
|
|
First of all, your code is really difficult to read. You should post it using PRE tags. Also consider indenting your code, as it is difficult to follow the flow.
The method ValidateAndAssignValues() does not return a value. How does the method InsertIntoDatabase know whether the validation was successful or not? From what I can see, the database insert will occur regardless of the result of the validation. Your validation method could return a bool value that indicates whether validation was successful or not. Your calling code would then need to check this value and use it to determine whether to proceed with adding the record.
One more thing, some of your error messages have spelling mistakes in them. You should consider checking your spelling before releasing your application to your users.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
If you notice I wrote a bool isFieldEmpty() for every field since I need to ensure that the field has a value. If a field does not have a value then an error message is displeyd with the error message on submit. The ValidateAssign() does two thing throws the error message and assigne that value id the boolean is false. How I am not sure why these Values are not being passed to the Insert method. I am not sure hwo to crrect this. Help? Anyone?
Skan
If you knew it would not compile why didn't you tell me?!?!?!
|
|
|
|
|
Skanless wrote: I wrote a bool isFieldEmpty() for every field since I need to ensure that the field has a value. If a field does not have a value then an error message is displeyd with the error message on submit.
Yes, but you don't raise any exceptions if invalid data is found. The Insert still gets executed regardless of whether the validation was successful. If you don't want the Insert to be executed if the validation fails, you need to either raise an exception within the validation code or modify the calling code to check whether the validation was successful before proceeding with the Insert.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
You are totally right and that's what I thought was happening but was not sure how to validate a "Void" method since nothing is ever returned. What is the best practice and how would you re-write this code to evaluate if all values have been assigned?
Skan
If you knew it would not compile why didn't you tell me?!?!?!
|
|
|
|
|
hi everyone!
i use FileSystemWatcher to watch a directory for incoming files. this works fine except if the file is written to the directory (e.g. copied by hand or the system) the very moment the program wants to access it via the FileSystemWatcher routines or events. so it is locked by the copy handler of windows.
is there a chance to find out if the file is ready to be accessed (e.g. read), because otherwise a file.ioexception will be thrown. meaning, i would have to delay the access to this file, until it is ready for access.
i had the idea of skipping the file until the next event takes place, but what if this causes the same problem, then this won't work.
do you have any ideas or is there an event like "file accessible" or is there a chance to find out if no other handler "posesses" the file?
thanks.
stephan.
|
|
|
|
|
|
so as far as i already read it is not too easy to just realize this within some minutes. it might be a trial and error until you find an acceptable solution for your own problem, right?
i will try myself by tomorrow.
but if someone already has a short solution "on the fly" please add it to my posting. i guess this might help everyone a lot. (some solutions might also be found in the links in the last posting by Giorgi Dalakishvili).
thanks.
stephan.
|
|
|
|
|
i just found a simple solution but i am not very happy with it. i coded a function private bool IsAccessible(string Path) which checks, if the file is accessible or not. if it is the access trying to open the file is closed again, it returns true and the other operations continue. if it is not accessible, then the io-exception is caught and it returns false.
when this function is called it is combined with a sleep(1000), meaning it tries to access the file, if it is accessible then it continues without waiting, if it is not, it waits for 1 sec. well you could reduce the amount of time for waiting to a fair value depending of the estimated time until the file should be ready. but after 1 sec most files are copied and ready for access
|
|
|
|
|
Hi Stephan,
Before accessing a file for your processing, try opening a file with a WRITE access on it. If the file open fails with denied WRITE access, then another thread (Windows) might be using it.
U can use this logic for any case (Files being copied, New file being created by another thread, etc.)
Hope this helps...
Regards,
Krista
|
|
|
|
|
Not sure why i don't seem to get this but i would like to write some records to a .txt file. At the end of all records, would like to keep a number which signifies the count. So if there are 5 records, the last line in the file will have "5".
If i have to add 10 more. I read the last line, add 10 to the number to total 15. etc.
I have been using StreamReader and Writer to do this, but i find that there is a limitation
I really want to be able to:
Open the file
Check the last line to see a number count
Append more data to file, update the number count.
Close the file.
if (!FileExists(ReportFile))
{
File.Create(ReportFile);
}
StreamReader stream = new StreamReader(ReportFile);
//How would i get to the end of the file and only read a line that says:
Count:100
where the statement "Count:" is constant, but the number will vary as we add
records?
Then i write the records:
StreamWriter filewrite = new StreamWriter(ReportFile, true);
filewrite.WriteLine(Rec);
filewrite.Close;
File
|
|
|
|
|
Wouldn't it be easier to write the record count in a header row at the start of the file? Then you wouldn't have to read to the end of the file to retrieve this information.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I actually do that:
StreamReader stream = new StreamReader(QueryReportFile);
buf = stream.ReadLine();//Read in th efirst line which is the count
int count = (int)buf;
count++;
stream.Close
My question here is that after i read the count and add to it, i have to update the first line with the new count. Do i have to create another StreamWriter just for that line, then execute below. How can i do this with one StreamWriter??
StreamWriter filewrite = new StreamWriter(ReportFile,true);
filewrite.WriteLine(RQ);
filewrite.Close();
|
|
|
|
|
i have a login page wid login check up loop as
if (userType.Equals("Administrator"))
{
Response.Redirect("successPage.aspx");
}
else if (!userType.Equals("Administrator"))
{
errMessage.Text = " Login Incorrect!! " ;
}
login works well with correct details as needed ..but if i enter wrong details.. it displays nothing.. i want to display text above... how to do this ??
|
|
|
|