JerryShaw 46 Posting Pro in Training

Don't know if this will help you but you can get the Time of a DateTime using the TimeSpan

DateTime data = new DateTime(2007, 11, 10, 13, 15, 0);
            TimeSpan time = data.TimeOfDay;
            //  time.ToString() returns "13:15:00"
JerryShaw 46 Posting Pro in Training

the for construct can be looked at like a while construct. Maybe this will help you understand it
x=2;
num = 100;
while ( x < num )
{
// do something with x
x = x + 1;
}

Hope that helps.
The modulus returns the remainder of the division. 33/32 = 1.03125 (remainder is .03125)

JerryShaw 46 Posting Pro in Training

Barefoot
Unfortunately, you are dealing with fileIO and things will get slow. What you can try IMO is saving the information into an xml file, or SQL database. Then the next time you run the program it will load from the data store.

Another thing to try is parcing the directories out, and launch a thread for each directory to gather the information.

If this were my website project, I would have a seperate app running in the taskbar that would monitor changes to the directories, and automatically update my SQL database when a change occurs. Then when the web page is requested, it would get the data from the SQL database and completely avoid the FileIO.

JMO
Jerry

JerryShaw 46 Posting Pro in Training

Simon,

See if this helps:

object nextItem = operatorStack.Peek();
if( nextItem != null && nextItem.ToString() == "*" )
	{
		//lowerPrecedence = true;
		strPostfix += operatorStack.Pop();
	}if(operatorStack.Peek() = '*')
	{
		//lowerPrecedence = true;
		strPostfix += operatorStack.Pop();
	}

Sorry, The funny part was in using an assignment operator instead of an evaluator operator.
Peek returns the first index from the internal array. The array holds objects. You have to cast objects to the correct type for an evaluation statement.

JerryShaw 46 Posting Pro in Training

Funny,

Just use == instead of =

JerryShaw 46 Posting Pro in Training

Try changing your code to this:

OleDbCommand myOleDbCommand_MemCount = myOleDbConnection.CreateCommand();
myOleDbCommand_MemCount.CommandText = "Select COUNT(emp) [B]as empCount[/B] FROM temp_table)";
 
OleDbDataReader myOleDbDataReader_MemCount = myOleDbCommand_MemCount.ExecuteReader();
if ( myOleDbDataReader_MemCount.Read() )
{
 
Console.WriteLine("Number of Members: " +   
       myOleDbDataReader_MemCount["empCount"].ToString() );
 
  int Count = (int)myOleDbDataReader_MemCountl["empCount"];
Console.WriteLine(Count); 
 
  myOleDbDataReader_MemCount.Close(); 
}

You can also just use the 0 index since you know you are only going to return one column from the aggregate SQL statement.

JerryShaw 46 Posting Pro in Training

I too am from the Delphi world. Have you tried using Delphi to access this database ?
As a test, can you see if you can access the database through code.

private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=SHAWHP\\SQLEXPRESS;Initial Catalog=SoftwareInventory;Integrated Security=True";
conn.Open();
conn.Close();
}

Finally, what does your connection string look like ?
In the above sample code, replace the SHAWHP\\SQLEXPRESS
with your own server, and the SoftwareInventory catalog with your
own and see if that works.

JerryShaw 46 Posting Pro in Training

There are a few things for you to look at.
Where the databases created using the "sa" administrator account ? IOW, who is the owner of the database, and was the Login account you are using to log in to the server have permission to use the new DB.

The error you are getting is strictly an SQL error. Has nothing to do with C#. Post the code you are using to attach the database, assign permissions, and then connect, and someone will help.

JerryShaw 46 Posting Pro in Training

I have attached a project that does what you want.
Parameters are passed on the command line. So if you set a File Association with your application, and double click it in the explorer, it will launch you application and pass the filename as a parameter.

The example project determines if your program is already running. If it is, then it will take its command line parameter and send a message to the first instance. Then closes itself. The first instance will receive the message and you can handle the file from that point on.

--Jerry

JerryShaw 46 Posting Pro in Training

Create a public static class in your main namespace, and you will have access to it from all objects / forms that use that namespace. You can store state-full information in static vars and collections within that class.

JerryShaw 46 Posting Pro in Training

Once the DataReader is closed, it is a null object. You need to reinitialize it as a new DataReader.
stat = new SqlDataReader();

JerryShaw 46 Posting Pro in Training

You need to convert the Hex back into an int then convert the into to a char.

string sHex = "41"; // same as 'A'
byte newByte = byte.Parse(sHex, System.Globalization.NumberStyles.HexNumber);
// newByte now = "65"
int i = Convert.ToInt32(newByte.ToString()); // i now = 65
Char schar = Convert.ToChar(i);
// schar = 'A'

Hope someone else comes up with a better solution.

JerryShaw 46 Posting Pro in Training

Sounds like another student homework assignment. We get lots of those up here.
Anyway, study the modulus operator, and you will discover the answer.

JerryShaw 46 Posting Pro in Training

Are you speaking of the Header cells, or a data cell ?

I havn't tried it on tried it on the header, however I am pretty sure it can be done.
If you are speaking of data cells, you can use the
CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

CellFormatting event to set the e.Value to an image.

//Jerry

JerryShaw 46 Posting Pro in Training

ChaseVoid,

Yea, we know it can't be done (atleast not that way). I was just trying to get into the poster's head to see what his thoughts were. After programming for 24 years, I'd never see someone ask that question.

Now that I see where his head is at, he could do something like this (however totally inefficient)

private string[] foo()
{
  string[] result = {"one","two","three"};
  return result;
}
 
mytextBox.Text = foo()[1];
myotherbox.Text = foo()[2];

or to follow his thoughts a little closer:

private string[] MyStrings = {"One","Two"};
private string foo(int index)
{
    return MyStrings[index];
}

Anyway, I think BlackLocist got the idea.


//Jerry

JerryShaw 46 Posting Pro in Training

Blacklocist,
Just out of curiousity,

What would one expect the syntax to be for a function that returned more than one value ?

string x = foo(); // which might return 2 strings
What would someone expect x to be after the call ? the first string ? the second ?
Then, how would you use x ? string c = x.part[0]; ???

What language have you used that would support such a thing, and can you provide an example..

just curious..

JerryShaw 46 Posting Pro in Training

It is true that a method can only return one value, however that value can be an array of values.

private object[] getSomeData()
{
   object[] mydata = {256, "Here's you daddy"};
  return mydata;
}
 
// to use the method
object[] somedata = getSomeData();
MessageBox.Show(string.Format("The number is {0}, the string is {1}", (int)somedata[0], (string)somedata[1]) );

You can also pass into a method some reference variables for the method to set.

--Jerry

blacklocist commented: Thx For The Info +2
JerryShaw 46 Posting Pro in Training

It sounds like maybe you have a couple things backwards.
Your Main Application should not be the login screen. Instead, create a Winform application, and add the Login WinForm to it. Then when the main application loads (Load Event) , create the Login form and show it modal, and get the result from the Login form's DialogResult.

Login lg = newLogin();
if (lg.ShowDialog() != DialogResult.OK)
  Close();
 
... Do your main Application stuff ...

You can do your vierification tasks inside your Login form or in the main form. If they hit the cancel button or exit any other way than the Accept button, set the Login form's DialogResult to Cancel. If they Click your accept button, then (optionally do checks) set the DialogResult to Ok to get back to the main application.
Let the Main form continue if the DialogResult is Ok, otherwise Close the main application.

--Jerry

JerryShaw 46 Posting Pro in Training

I assume what you want to do is trap the Page Down key and use it for navigating the datagridview. The problem in your code is that you are not telling the datagridview that you have aleady handle the key press.

Let it know that you have taken care of the key press by setting the Handled property to true.

If using KeyPress then assign the KeyPressEventArgs e ... e.Handled = true;
if using KeyDown then assign the KeyEventArgs e ... e.handled = true;

This prevents the event from going into the internal key event handler of the DataGridView.

JerryShaw 46 Posting Pro in Training

First check to see if SQL client tools are installed on the machine (I use the registry), then use teh instructions on the SQL Install DVD or visit MSN for instructions on how to automate an installation of the SQL Express Edition.

J

JerryShaw 46 Posting Pro in Training

Selecting the UDP protocol is very similar to selecting Tcp, Echo, Ftp, etc etc. You will find plenty of examples of using UDP in the book.
Example:

Socket sock = new Socket(AddressFamily.Internetwork, SocketType.Dgram, ProtocolType.Udp);

J

JerryShaw 46 Posting Pro in Training

..having trouble with creating a list of arrays in a Class ..

Exactly what is the problem you having... You don't know how to make arrays, or is it something else ?

J

JerryShaw 46 Posting Pro in Training
JerryShaw 46 Posting Pro in Training

Do a Google search on c# Server Socket, and/or get the book "TCP/IP Sockets in C#" by David B Makofske, Michael Donahoo and Kenneth Calvert. This book goes into threading the server and client with lots of examples.

JerryShaw 46 Posting Pro in Training

#3, you can't stop it from sending the a minimize command (without some Windows API calls), however if you want it to do more things before it minimizes, you can use the Deactivated Event handler or the SizeChanged event (http://www.thescripts.com/forum/thread275452.html). If you want to stop the minimize action, then you have to trap the message and do what you want... this calls for importing some WinAPI stuff, which like hollystyles said, is too much to go into this thread.
You also might want to look into a Notify component to trap the minimize event.

JerryShaw 46 Posting Pro in Training
JerryShaw 46 Posting Pro in Training

If I understand you right, you have some text controls on the form, and you want to iterate through each to look at their text value.

Since all of them are already in the controls array, you can just iterate through them. You can rely on the name, or set the Tag value of those you want to search (from the designer IDE).

Your first line of TextBox curText = new TextBox() should really be set to null, unless you are really trying to create a new control on the form.

As a sample, I created a new project, dropped three TextBox controls and a button. In the second control I set the Text property to "Hello World" then used this code in the button handler:

foreach (Control ctrl in this.Controls)
{
if (ctrl is TextBox)
{
if (ctrl.Text == "Hello World")
{
MessageBox.Show(ctrl.Name + " has this value.");
break;
}
}
}

The results showed that TextBox2 contains the text I am looking for.

Hope this helps,
Jerry

JerryShaw 46 Posting Pro in Training

You might save yourself some time by using Greatis. I am not affiliated with them, but my company uses their product.

http://www.greatis.com/dotnet/formdes/

JerryShaw 46 Posting Pro in Training

I am also a convert from Delphi (started with D1, ended with D2005).

There are many ideas out there on how to centralize your data. The idea of a Data Module is not as foreign to C# as you might think. After all, a TDataModule is nothing more than a Class with functions, procedures, Properties and the ability to include public DataSets, public TADOConnection, etc. A TDataModule in Delphi is developed by the programmer with a specific task in mind. Lets say the data components allow for accessing payroll information. In Delphi you typically try to encapulate the data access and attributes of the payroll system within your TDataModule.

A C# class is all of that and more. You can create a new class for your application, and think of it just like a TDataModule. Add your public variables or components just like in Delphi. For instance, you can instanciate an SqlConnection in the same way you instanciate a TAdoConnection.

It takes some getting used to, and some things take more code than in Delphi, but I find that c# is more powerful, and getting a forward only dataset is much faster in dot-Net than ADO or BDE in Delphi.

BTW: I still work with Delphi everyday in support of our legacy product. I am also working on the new development projects in C#.

//Jerry

JerryShaw 46 Posting Pro in Training

Are you asking how to use a checkbox to determine which formula to apply ? Or... are you asking someone to code your tangent and hyperbolic tangent methods ?

JerryShaw 46 Posting Pro in Training

This works in VS2005, and should work in 2003

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = (e.CloseReason == CloseReason.UserClosing && MessageBox.Show("Are you Sure ?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes);
}
JerryShaw 46 Posting Pro in Training
JerryShaw 46 Posting Pro in Training

Namespace declarations do not impact the resulting application.
They are used by the pre compiler to locate code addressing during the compile phase. You could preface every object and type in your source code with its namespace, and all you are doing is beating up yourself.

The c# compiler examines each object and type in your source code as it compiles. It searches the namespaces you have declared. IOW, declaring the Namespace's at the top of the code allows you to write code without prepending the correct namespace for each and every object and type.

If you need lets say the name of the PC, and did not add System.Net in your uses section, then doing it this way:
string MyPCname = System.Net.Dns.GetHostName();
would do the same thing as adding System.Net to the using section and just write string MyPCname = Dns.GetHostName(). Just because you add System.Net to the using section does not mean that every method in that name space is included in your compiled application. In either case, the compiler either searched your using section, or used your direct implementation to find the address of Dns.GetHostName().

Using the direct call (inluding the namespace) just saved the pre compiler a search step.... Not you. The resulting application performance is not affected using either method of declaration.

JerryShaw 46 Posting Pro in Training

There seems to be a lot of gaps in your question, but I will take a stab at it. You have a load Game button and you need player 1 and Player 2 to login. I assume both login on the same form while it is open. Once both players are selected, then you want to instantiate the game and have those players pictures appear on the main screen (the Game).

First, do not instantiate TicTacToe until you have both players assigned with names and images on this login screen. So disable the loadgame button until both players are set. Then when you instantiate TicTacToe from the loadgame event handler, provide 4 parameters (both player names and images) instead of just two.

Does that make sense ?

JerryShaw 46 Posting Pro in Training
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
Control c = GetNextControl((Control)sender, true);
if (c != null)
c.Focus();
}

This works fine.

JerryShaw 46 Posting Pro in Training

Look at
http://msdn2.microsoft.com/en-us/library/system.windows.forms.keypresseventargs.keychar.aspx
then after e.Handled = true; set focus to the next control / textbox.

JerryShaw 46 Posting Pro in Training

Not a smart idea, and an easy way to get into a legal jam if the forced logout causes loss of data in another application.
But, if you inisit on this insanity, you could register your application to restart in the registry, then call the Win API call to force Logout which will bring up the login screen (THAT IS IF... The PC is setup to require a login). The force Logout will close all other user processes and applicaitons on its way down.

Be careful what you wish for.

JerryShaw 46 Posting Pro in Training

You need only one loop and the use of the modulus operator.

private void btnGo_Click(object sender, EventArgs e)
{
 
txtresult.Clear(); // TextBox to display results (multiline)
int result = Convert.ToInt32( txtNum.Text ); // textbox to hold value to examine
while (result != 1)
{
if (result % 2 == 0) // it is even
{
result = result / 2;
}
else // it is odd
{
result = result * 3 + 1;
}
// Display Results
txtresult.Text = txtresult.Text + result.ToString() + System.Environment.NewLine;
}
MessageBox.Show("Completed");
}
Killer_Typo commented: we dont do peoples homework here. -1
JerryShaw 46 Posting Pro in Training

covertx,

The str value you are passing to the delegate needs to be done a little differently.

Invoke is an eventhandler type. That means it takes Sender and Params as the second argument. just like all other event handlers in c#. Params is an object array (like args).

In your case you only need one parameter passed, but as far as the engine is concerned, it still has to be a list of params as an object array. So Try this.

this.Invoke(new AddnewText(AddTextToTextBox), new object[] {str});

BTW, The Delegate you defined will cast the object array into the parameter slots in the delegatel... So you do not need to do any additional casting... It will come back into the target method already cast (back to string in your case).

-- Jerry

JerryShaw 46 Posting Pro in Training

Another way of trapping the Enter key is by using the form's KeyPreview property set to true. Then on the Form's onKeyPress event do this:

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var
  i:integer;
  tbOrder:Integer;
  nextComponent: TComponent;
 
  function getControlForNextTabOrder: TComponent;
  var iThisTab:Integer;
      n:Integer;
  begin
    result := nil;
    iThistab := ActiveControl.TabOrder;
    for n := 0 to ComponentCount -1 do
      if TWinControl(Components[n]).TabOrder = iThisTab +1 then
      begin
        result := Components[n];
        break;
      end;
  end;
begin
 if Key = #13 then
 begin
   nextComponent := getControlForNextTabOrder();
   if (nextComponent <> nil) then
   begin
     ActiveControl := TWinControl(nextComponent);
     Key := #0; // prevent Key from propogating any further
   end;
 end;
end;

Be aware that TButtons and such will not throw this event handler. So the focus can not move to the next control when this type of component has focus. Memo boxes will get focus, but you have to use Shift+Enter for new lines in the memo. You can obviously curcumvent some of this behavior in the onKeyPress event, by examining the currently ActiveControl type or name.

This example obeys the TabOrder, and prevents you from writing a KeyPress event handler for each control that you want this behaviour.

--Jerry

JerryShaw 46 Posting Pro in Training

Scru (me again:)
I suggest reading Inside C# by Tom Archer and Andrew Whitechapel from Microsoft Press.

Also another good book is Programming C# with Visual Studio .net 2005 by Jeffery Suddeth.

I purchased mine through Amazon.com
I have a large library of C# books, but these two are my recommendations for getting started. Based on the questions you have been asking... these should really help.

DaniWeb is a great place for beginners. It helped me get started. That is why I am paying back by answering some questions.

The next level up (IMO) is Code Project which has fantastic example code, with some really good authors, then at the top of the scale (again IMO) Experts Exchange for when you have a real technical problem to solve.(requires a subscription). I have found that typing c# and some topic on the google search line I get some really good hits. Most of the time, I end up in either MSDN or CodeProject.

--Jerry

JerryShaw 46 Posting Pro in Training

Scru,

I think what you are after is Serialization (known as pickling in python).

Take a look at this website:
http://blog.kowalczyk.info/kb/serialization-in-c%23.html

-- Jerry

JerryShaw 46 Posting Pro in Training

I am not familiar with the Express version IDE. But if you can see the Resources item under your project in the Solution Explorer, then you should be able to add any kind of resource that you want. Whatever resides in the resources item, is compiled into your program.

Look in your InitializeComponent() method, and you will see how
System.ComponentModel.ComponentResourceManager is used to pull resources out of the reources section of your compiled program.

I tell my programmers that there is always at least five ways to do anything. The most efficient code (fastest to execute) and easiest to maintain should be your first pick.

Since you are presently using a file IO process to exchange the button image, may I propose a faster method ?

Since you are not yet familiar with resources I won't go into that technique. What you can do is let the compiler do some of the work for you. Add two buttons, give button1 the normal image (what you display when the cursor is not in your real button canvas area), and button2 with the image of when the cursor is in the canvas area. Make both buttons invisble. When the user enters or leaves your real button, you can assign the correct image from one of these hidden buttons instead of going to the Disk. The idea is to reduce the file IO of reading a file from disk (the slowest operation for a PC).

That method …

JerryShaw 46 Posting Pro in Training

Since you want to have an image on the button, why not assign it in the IDE ?

If you are using something other than the VS IDE, and that IDE that does not allow you to assign the image, then you can place the image into the resource section, and load it from there on startup.

This way, you do not rely on a image file being in a specific place. It also reduces the number of files you need to supply with your product, and guarantees that the image will be available at runtime.

--Jerry

JerryShaw 46 Posting Pro in Training

I think you need to post some code so we can see what you are doing... like how you are instanciating InertItem.

--Jerry

JerryShaw 46 Posting Pro in Training

You can't have SET IDENTITY_INSERT for more than one table at a time per database. This is a Microsoft SQL rule.

Second, if you have related two tables through a foreign key constraint, and both are using an Identity Column as their primary key... and the contraint is between these two table...you have bigger problems.
Primary Keys that use an Identity column should only be used on Prime tables in a relational model.

--Jerry

JerryShaw 46 Posting Pro in Training

One more thing.... If you must use a relative path, preface it with Application.StartupPath

-- Jerry

JerryShaw 46 Posting Pro in Training

Sorry you are having problems adapting to a new language. I find c# one of the easier ones to learn.

Your file spec is looking for current dir\images\playbtn_down.jpg
But just what is the current directory ? Is in on the C drive ? D ?

You really can't tell from this file path specification. When using paths, you should never assume that your application environment is sitting on the same directory or even drive that it started. IOW, do not use relative paths. Retry your example using the fully qualified path: example: "C:\\Images\\Playbtn_down.jpg".

--Jerry

JerryShaw 46 Posting Pro in Training

What you need is a place in your MyProgram.cs class to store the command line arguments received in the constructor (Main).
Something like public string SelectedFile;

In the Main constructor, do this:

public static void Main(string[] args)       
{   string SelectedFile;            
     if (args.Length > 0)            
     {
        SelectedFile = Convert.ToString(args[0]);                       
        MessageBox.Show(SelectedFile); // Just to confirm it.               
     }
 
     MyProgram app = new MyProgram();
     app.SelectedFile = SelectedFile;
     Application.EnableVisualStyles();             
     Application.SetCompatibleTextRenderingDefault(false);              
     Application.Run(app);           
}

Then in your ...form_Load event, see if the value is null, or has a value. Take it from there.

scru commented: this helped me back when I didn't have rep power, and it helped me today again +3
kdcorp87 commented: joss +1
JerryShaw 46 Posting Pro in Training

I am referring to a Windows Application.
The Namespace is System.Windows.Forms.WebBrowser

Are you running this from a Windows Form ?

J