darkagn 315 Veteran Poster Featured Poster

This error usually means that the database was created in a later version of SQL server than the one you are running. If you are running straight 2008, upgrade to 2008 R2 or 2010 and see if that solves your problem.

darkagn 315 Veteran Poster Featured Poster

The text box has a string property called Text which is the entered text in the text box. For example, if you name your text box myText, you can do the following in your mouse click event:

private void MouseClick(object sender, EventArgs e)
{
   string text = myText.Text;
   if (String.IsNullOrEmpty(text)) // check to see we actually have some text
   {
      throw Exception.Create("Require text!");
   }
   else
   {
      // do something here with the string "text"
   }
}
darkagn 315 Veteran Poster Featured Poster

You can use a try-except block like so:

try
  begin
    Example(6);
    Example(8);
    Example(10);
    Example(15);
    Example(7);
    Example(1);
  end
except on E: Exception do
  raise Exception.Create(E.Message); // raised as a new exception so will include the line calling Example(15) as the error line
end;
darkagn 315 Veteran Poster Featured Poster

Each Control has a Parent attribute, so you could use something like the following Linq statement to get just the "top-most" controls.

var controls = this.Controls.Where(o => o.Parent.Equals(this));
darkagn 315 Veteran Poster Featured Poster

Reading #12:

Seek out your sacred space.

Let the smoke rise
And hear the prophecies of destiny.

:)

darkagn 315 Veteran Poster Featured Poster

Glad to hear you are enjoying Australia, almostbob!

Yes cyclones have been the bane of the banana here for the past few years. 5 years ago local bananas were like $1.20 for 1 kg, now they have dropped from over $11/kg to $6/kg here in South Australia in the past month, and people are saying how cheap they are!

darkagn 315 Veteran Poster Featured Poster

This comparison is a little out of date now, but it does give a good overview of the differences between MySQL(5.0) and MSSQL(2005).

darkagn 315 Veteran Poster Featured Poster

If you have 2 DateTime objects, you can subtract them to get a TimeSpan object. This TimeSpan object can be expressed in TotalMinutes.

MSDN documentation links:
DateTime.Subtraction operator
TimeSpan.TotalMinutes

darkagn 315 Veteran Poster Featured Poster

You can use the Type class, or alternatively you can call [object].GetType() on the return value of the call.

Example:

FindControl<HtmlControl> controllocator = new FindControl<HtmlControl>();
HtmlControl txtEntityName = controllocator.findControl(new HtmlControl());
if (txtEntityName.GetType() == typeof(HtmlEdit))
{
   HtmlEdit edit = (HtmlEdit)txtEntity;
}

The downside is that you need a really big if-statement if you have many extending classes.

I think there is a way to do this using reflection, but I haven't really done anything with that before. I think its System.Assembly.Reflection namespace that you want to use, sorry I can't provide an example of this method but Google might provide some.

Good luck :)

darkagn 315 Veteran Poster Featured Poster

Here is a solution for you (on another forum), it appears that this error code has to do with windows permissions.

darkagn 315 Veteran Poster Featured Poster

When you deal with generics, instances of the class take the type parameter and then it deals with that type. When you call controllocator.findControl(new HtmlEdit()) I assume you are creating an instance of Controller<HtmlEdit> . Since HtmlLongEdit class doesn't extend HtmlEdit, you can't use the same object to call findControl again on this second type. Here's one way to handle it:

Make your Controller class a base, abstract class and extend it like so:

internal abstract class AbstractController<T> where T : HtmlControl
{
  public abstract T locateControl(T t);
}

internal class Controller<HtmlControl> : AbstractController<T>
{
  public override HtmlControl locateControl(HtmlControl t)
  {
    t.SearchProperties.Clear();
    t.Find();
    return t;
  }
}

So now your generics class is taking objects of type HtmlControl. This should allow you to make the calls as you originally wanted since both the HtmlEdit and HtmlLongEdit classes extend HtmlControl.

darkagn 315 Veteran Poster Featured Poster

Hi BCJLJ and welcome to DaniWeb :)

So what have you got so far, and where are you having trouble? Unfortunately we can't help you without some showing of effort on your part. Have a try yourself, or at least try to write some sort of algorithm, and then re-post with your ideas and raise some specific questions.

Good luck,
darkagn

darkagn 315 Veteran Poster Featured Poster

Try pinging and/or telnet'ing from that other pc to yours and see if the pc can actually see you. If it can't, could be that a firewall or other network security measure is blocking it for some reason.

darkagn 315 Veteran Poster Featured Poster

I do have one program that I wrote for a past assignment with two-dimensional arrays. I have already turned it in and am willing to take whatever I get on it but I would like to have an explanation of what I've done wrong or what I am missing. I hope I'm not imposing when I ask if this is something you would be willing to take a look at as well?

Absolutely, please feel free to ask questions about whatever you need. That's what DaniWeb is all about! I have always said that the best way to learn is to make mistakes and find out what went wrong.

However it might be a good idea to start a new thread for your new topic.

darkagn 315 Veteran Poster Featured Poster

So far I've been doing fairly well but i seemed to do better in C++...*sigh*.

I feel completely the opposite, C++ confounds me!

I'm pretty sure the random number generator in C# uses the current system time in milliseconds to generate its next int. This means numbers generated in the same millisecond by the same instance of Random will be the same. One solution might be to Thread.Sleep(1); between each generation to ensure you get a tick between them.

Good luck and have fun!

darkagn 315 Veteran Poster Featured Poster

The first thing I notice looking at your code is that the "and-ed" if-statement should be before your "or-ed" if-statement, because and's will always be false if or's are. I'm not 100% sure, but I think the statements int index3 = new int(); should be replaced by simply int index3 = rand.Next(imageListFruit.Images.Count); like you have for index1. Also, are you sure you need to basically duplicate the code from the GamePlay method in the btnExit_Click method?

darkagn 315 Veteran Poster Featured Poster

You can create a two-way reference when you create the object B. Like so:

class A
{
   private B b;
   public A()
   {
      b = new B();
      b.SetA(this);
   }

   public void MethodA()
   {
      // do something
   }
}

class B
{
   private A a;
   public B()
   {
      a = null;
   }

   public void SetA(A a)
   {
      this.a = a;
   }

   public void MethodB()
   {
      // do something...

      // then call the MethodA
      if (a != null)
         a.MethodA();
      
   }
}

This should give you the general idea, however it is important to point out that such two-way references are prone to memory leaks. Therefore you should set B's reference to A back to null after you have finished using it. You can do this by setting the reference to null after the call to MethodA, or by implementing the IDisposable interface on both classes, or some other method...

darkagn 315 Veteran Poster Featured Poster

There is an error in your SQL query. I would suggest printing out your query string variable to see what is actually being inserted into your where clause with the values you are adding on the fly.

As an aside, a much safer approach to SQL is to use a parameterised query. Here is an example:

using (SqlConnection conn = new SqlConnection(connString))
{
  conn.Open();
  try
  {
    using (SqlCommand cmd = conn.CreateCommand())
    {
      cmd.CommandText = "SELECT * FROM Aircraft WHERE AircraftType = @Type";
      SqlParameter param = cmd.CreateParameter();
      param.ParameterName = "@Type";
      param.Value = aircraftType; // some value
      param.DataType = DbType.String; // some type
      using (SqlReader rdr = cmd.ExecuteReader())
      {
        while (rdr.Read())
        {
            // do something with the data
        }
      }
    }
  }
  catch (Exception e)
  {
     // do some error handling here
  }
  finally
  {
     conn.Close();
  }
}
darkagn 315 Veteran Poster Featured Poster

There are plenty of datetime functions in PHP that may be useful to you. Here is a list of many of them, date_add and date_parse could both be useful to you depending on how you want to do it.

darkagn 315 Veteran Poster Featured Poster

Its much easier to use decimals, however you can use "fractions" by simple addition and division. For your example, 1 1/2 = 1+(1/2) although this can also be written 1+1/2 since division takes precedence.

darkagn 315 Veteran Poster Featured Poster

You can use the TOP N function to retrieve the most recent if you order by shipdate. Like so:

SELECT TOP 1
vp.esn,
us.supplierid,
us.shipdate
FROM Table1 AS vp WITH (nolock)
LEFT OUTER JOIN TABLE2 AS us WITH (nolock)
ON vp.esn = us.esn COLLATE Chinese_Taiwan_Stroke_CI_AS
WHERE vp.ReceivingPO IS NOT NULL
AND vp.Receiveddate IS NOT NULL
AND vp.esn <> 'ESN' AND vp.ESN <> 'TLCSHK'
ORDER BY us.shipdate DESC -- desc will give most recent, asc will give oldest
darkagn 315 Veteran Poster Featured Poster

For part A, they are wanting a function that uses the specific fields in your table, not passes them as parameters to the function. Your function will probably look something like this:

-- give the function a meaningful name, and return an appropriate data type
CREATE FUNCTION GetItemTotalPrice() RETURN MONEY
AS
DECLARE @TotalPrice MONEY
-- total price is defined as quantity x unitprice from the sales table
SELECT @TotalPrice = Quantity * UnitPrice FROM Sales
RETURN @TotalPrice

For B you will need to do a CREATE TABLE statement. Here is a link to the MSDN documentation for such a statement, there are also many many examples online. Have a try and repost if you need more help, along with your attempt.

darkagn 315 Veteran Poster Featured Poster
for (int i = 0; i < textBox3.Text.Length;i++ )
{
 
c = i+1 ;
 
 
if (textBox3.Text.Substring(i,c)==" ")
{
string word = null;
word = textBox3.Text.Substring(0, i);
arrayKeyword[index]=word;
index = index + 1;
}
}

Your for-loop here iterates from the start of the string textBox3.Text to the end of the string. During each iteration, you check the current character (at position i) and the one following it (at position c). So when i is the last character in the string, c is invalid because there is no character following position i. You need to change your loop like so:

for (i = 0; i < textBox3.Text.Length - 1; i++)

EDIT: Actually, substring takes a start position and a length of the string, so your call to substring should be:

if (textBox3.Text.Substring(i,1)==" ")
ddanbe commented: well explained. +14
darkagn 315 Veteran Poster Featured Poster

This is a static call to your function, which is fine if there is no calls to member variables or functions in the getAllRecords function (ie using $this). From a relatively early version of PHP (around PHP4 from memory) they introduced the static keyword which was supposed to be used to mark such functions as being able to be called in the manner you describe, but it was only intended as a guide and not enforced at runtime.

In general, non-static calls to functions go like this:

$myRecords = new getRecords();
$myRecords->getAllRecords();

That is, you instantiate an object of your class and then call the function that you need.

Hope this helps,
darkagn

darkagn 315 Veteran Poster Featured Poster

The line:

echo "</tr><td style='border-style:none; border-width:medium;'>";

is at fault I think. You close the row with the </tr> followed immediately with a <td> node. Are you able to view the source in the browser? I think you will find that you will have cells (<td>) outside of rows (<tr>) because of the line mentioned above, which will confuse the browser when it renders the table.

Also, you have some <p> tags that aren't closed, and your <img> tags aren't closed either.

darkagn 315 Veteran Poster Featured Poster

It is possible but very prone to error. This code shows how you can switch out a form in a panel in a button click event:

procedure TMainStockForm.StockTakeBtnClick(Sender: TObject);
begin
	LockWindowUpdate(Self.Handle);
        Panel1.Visible := true;
        try
	    StockTakeBtn.Down := true;
	    StockTakeForm.WindowState := wsMaximized;
	    StockTakeForm.ShowForm;
	    ShowWindow(StockTakeForm.Handle,SW_SHOWMAXIMIZED);
        finally
	    Panel1.Visible := false;
            LockWindowUpdate(0);
        end;
end;

Make sure your inner form (StockTakeForm in my example) does not rely on a ModalResult.

Having said this, I think it is a much better option to put all of your "inner form" code inside a page control and switch tabs. Two inner forms in a single form at the same time probably won't work, but you could just use panels or page controls for this too.

Anyway have a play with the example and see how you go. Good luck! :)

darkagn 315 Veteran Poster Featured Poster

Hi all,

I am getting an error in my application that reads:

Incorrect syntax near the keyword 'set'

It only occurs in a database at a particular venue and only when the offending query/queries are run locally. I have restored the database on my PC and the queries run without a hitch. I can remote into their server and run the queries, again no problem. When a local user runs the queries, they get the above error.

The first time I saw it, the exception was being caught during an insert statement that didn't include a SET command - weird. But now it is occurring in a different place - this time an update query that does include a SET statement.

I believe the problem lies in either user access or the SQL instance itself, as no other venue has reported the problem. However I have been unable to narrow the issue down any further. Has anyone seen such weird behaviour before?

BTW the SQL instance is SQL 2008 R2 version.

Thanks in advance for your thoughts and suggestions. I am completely stumped by this one!

darkagn 315 Veteran Poster Featured Poster

Resources are global, external data objects that can be used by the application from any point. Here is the MSDN description of application resources, their purpose and how to use them.

In answer to your third question, you can change what type of resources you wish to view/add/delete by changing the combo box that reads Strings when you open the resx file for the first time.

darkagn 315 Veteran Poster Featured Poster

A basic algorithm would be something like:

int temp = inputValue;
string roman = String.Empty;
while (temp > 999)
{
  roman += "M";
  temp -= 1000;
}
while (temp > 899)
{
   roman += "CM";
   temp -= 100;
}
while (temp > 499)
{
   roman += "D";
   temp -= 500;
}
while (temp > 399)
{
   roman += "CD";
   temp -= 100;
}
while (temp > 99)
{
   roman += "C";
   temp -= 100;
}
while (temp > 89)
{
   roman += "XC";
   temp -= 10;
}
// and so on...

There are probably more efficient ways of doing it, but it gives you a general idea.

darkagn 315 Veteran Poster Featured Poster

Hi all,

I am having an issue with regard to libeay32.dll as outlined in this thread. I am getting the error when attempting to connect via HTTPS using the following code:

function THttpClient.Login(const UserName, Password, URL: String): Boolean;
var
  Client: TIdHTTP;
  Params: TStrings;
begin
  Client := TIdHTTP.Create(Nil);
  Client.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(Nil);
  Params := TStringList.Create as TStrings;
  try
    Params.Add(Format('username=%s', [UserName]));
    Params.Add(Format('password=%s', [Password]));
    Response := Client.Post(URL, Params);
    Result := Client.ResponseCode = 200;
  finally
    Client.Free;
    Params.Free;
  end;
end;

As you can see I am using Indy components for the HTTP client and SSL IOHandler. We have the latest version of Indy installed from their SVN repository. My problem seems to be that I can't find a compatible libeay32.dll and ssleay32.dll for OpenSSL for this version of Indy on my Win7 x64 machine, although a colleague can run the code using OpenSSL 0.9.8i (fairly old version) on his WinXP x86 machine.

Does anyone have any thoughts as to how I might be able to fix my issue?

darkagn 315 Veteran Poster Featured Poster

Thanks caperjack, I posted here thinking it might be an issue with my Win7 x64 install given that it is a windows DLL that is giving me grief. I will try posting there too and see if anyone else has had the same problem.

darkagn 315 Veteran Poster Featured Poster

Hi all,

I am writing a currently writing a program that needs to connect to a website via HTTPS. I am receiving the following error when I attempt to connect:

The procedure entry point ASN1_const_check_infinite_end could not be located in the dynamic link library libeay32.dll

followed by:

Could not load SSL library.

I have tried several different versions of libeay32.dll (and corresponding versions of ssleay32.dll) downloaded from http://indy.fulgan.com/SSL/ including the latest (1.0.0d), but to no avail. I have tried placing them in the same directory as my exe (which according to these rules means that they should be loaded from there), but I also tried overwriting the versions in the Windows folder too. A colleague uses version 0.9.8i with no errors, but he is on a 32-bit WinXP OS while mine is a 64-bit Win7 OS and the 64-bit build of that version hasn't worked on my PC either.

Does anyone have any ideas how to fix the error?

Thanks in advance for your suggestions.

darkagn 315 Veteran Poster Featured Poster

> You know you are a geek when ....
You can relate to each of the characters in The Big Bang Theory or The IT Crowd... and these are the only TV shows you watch.

skilly commented: 1 bad apple... +0
darkagn 315 Veteran Poster Featured Poster

I haven't done it before but my guess would be writing an event handler for the tab control's DrawItem event that styles the tab the way you want. Anyone know of a better way?

darkagn 315 Veteran Poster Featured Poster

Hi Bernie and welcome to DaniWeb :)

That code looks fine, can you move the creation of your variant array outside the function and step into the Locate to see exactly where the error occurs?

VarArray := VarArrayOf([sPhone, sTitle, sAddLine2]);
bFound := tblComp.Locate('CompPhone;Title;AddLine2', VarArray, []); // <- step in here using debugger
darkagn 315 Veteran Poster Featured Poster

Wouldn't it just be:

myPictureBox.Image = null;

?

darkagn 315 Veteran Poster Featured Poster

Declare the variables value1 and value2 before the if-statements.

int value1 = 0;
int value2 = 0;
if (checkbox1.checked) // you don't need to say == true here
  value1 = 1000000;
if (checkbox2.checked)
  value2 = -392014;
int value3 = value1 + value2;
myFunction(value3);

//...

public void myFunction(int value3)
{
  // do something...
}

PS please use code tags, it makes posts much easier to read.

darkagn 315 Veteran Poster Featured Poster

Ok, drop a BackgroundWorker component onto your form, rename it bgWorker, and use this code as an example:

private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // do some long-winded process here
            // this is executed in a separate thread
            int maxOps = 1000000;
            for (int i = 0; i < maxOps; i++)
            {
                rtbText.AppendText(i.ToString() + "\r\n");
                // report progress as a percentage complete
                bgWorker.ReportProgress(100 * i / maxOps);
            }
        }

        private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // update the progress bar
            pbProgress.Value = e.ProgressPercentage;
        }

        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // return to "normal" mode of operation
            this.Cursor = Cursors.Default;
            btnGo.Enabled = true;
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            // give the appearance of something happening
            this.Cursor = Cursors.WaitCursor;
            btnGo.Enabled = false;
            // call RunWorkerAsync to start the background thread
            bgWorker.RunWorkerAsync();
        }

I think this solution is much cleaner, and all of the thread handling is taken care of for you.

EDIT: In my example, btnGo is a button, pbProgress is the progress bar, rtbText is a rich text box, and bgWorker is the background worker.

darkagn 315 Veteran Poster Featured Poster

Check out the BackgroundWorker class. Basically you put all your execution handling into its DoWork event handler, then call RunWorkerAsync on the instance to set it to run. You can use the ProgressChanged event handler to report the progress back to your GUI thread, and the RunWorkerComplete event handler is fired when the worker finishes its work. There are heaps of online examples of this process.

darkagn 315 Veteran Poster Featured Poster

So every time the cell is formatted you are making k calls to the database. I think you need to think about what the cell format should do - it shouldn't retrieve the data but format it in a user-friendly way. By the time the cell format event is fired the data should already have been retrieved.

darkagn 315 Veteran Poster Featured Poster
for (int k = 0; k <= dtgdisplaytest.RowCount - 1; k++)
{
//here checking pending test
string TestDisp = dtgdisplaytest[0, k].Value.ToString();
string str_sel = "select test_no from testmark where test_no='" + TestDisp + "' and submission='Pause'";

This section of your code will run k SQL queries on the database, is this really want you want to do? You can use a while (dr.Read()) instead of if to iterate through a set of results from a single query. SQL queries are slow in comparison to memory reads, so try to limit them as much as possible.

Also, where are you calling this code?

darkagn 315 Veteran Poster Featured Poster

Sorry I can't see anything wrong with your code, that's exactly how I would do it. I'm surprised that the compiler lets you get away with using the variable name var though, I thought var was a reserved word in C#. Have you tried stepping through your code and viewing the node attributes each time to make sure that the kv.Value is correct?

darkagn 315 Veteran Poster Featured Poster

Can you post your code of where you attach the Map attribute to the Variant node in your application?

darkagn 315 Veteran Poster Featured Poster

Check your opening { and closing } throughout your file. The sample you provided closes the class very early in your code...

darkagn 315 Veteran Poster Featured Poster

FileMode.CreateNew throws an exception if the file exists. You can use FileMode.Create if you are happy to overwrite an existing file.

darkagn 315 Veteran Poster Featured Poster

You can use a FileStream for this:

string filepath = "C:\\test.html";
using (FileStream output = new FileStream(filepath, FileMode.Create))
{
  provider.Export(document, output);
}
darkagn 315 Veteran Poster Featured Poster

Not sure what you mean by the first one, but for 2, it is easier and more accurate to use an identity field in the database.

darkagn 315 Veteran Poster Featured Poster

Check out the FileInfo class. This gives access to creation, access and modified dates. Not sure about tags and the like, possibly the FileInfo.GetAttributes method might return these (and SetAttributes to modify them?)

darkagn 315 Veteran Poster Featured Poster

MATLAB is another popular mathematical scripting language.

darkagn 315 Veteran Poster Featured Poster

DelphiBasics is a great starting point. Two very basic tutorials, lots of sample code and descriptions of many commonly used units will give you a start.