JerryShaw 46 Posting Pro in Training

Where is your Fraction Class ?

JerryShaw 46 Posting Pro in Training

Hello Aminit,

Just a thought... have you considered using a binary value to represent each group ?
Set the Tag value for each checkbox with a hex value. Have a method OR the hex values for each checkbox (method will iterate through all checkboxes in a group) resulting in a single value for each group.

Hint: if you have each checkbox group contained in a panel or groupbox it makes it easier to iterate all checkboxes in that container rather than filter on all checkboxes on the form.


Once you have a single binary value for each checkbox group. You can (AND) the value with the other group(s) to see which combinations are checked as a single value.

If you have some known conditions (like that one which creates an error message), then you can AND that condition (as a binary value) to the checkbox group binary values.

Its just a matter of math.

If this sounds confusing, consider it this way. If you can represent Group A as a single value, then you can use simple boolean operators to compare against specific conditions you want to check.


// Jerry

JerryShaw 46 Posting Pro in Training

If the matrix values are contained inside of a string, then just create a method that receives a string.

private void foo(string value)
{
// parse the value into its parts.
}


// Jerry

JerryShaw 46 Posting Pro in Training

Okay, I just took care of your problem. Sent you an email with the details.
I believe you can mark this as solved.

Jerry

JerryShaw 46 Posting Pro in Training

Ramon,

Tell ya what I will offer. Send me a backup of your database (zip'ed) along with your project source code, and I will test it here. Either I will be successful, meaning that your Server is at fault, or I will discover the problem in your source, and tell you what needs to be fixed.
If you don't want to post your database here, then you can send it to Shawjh@meadowcrk.com or post it somewhere so I can download it.

Regards,
Jerry

JerryShaw 46 Posting Pro in Training

Do you have access to that database through the SQL management studio ?

JerryShaw 46 Posting Pro in Training

I have adjusted the connection string to your criteria (below).
Make sure that your Sql server is alive. You should (in task manager process) have the following processes running: (as a minium)
sqlserver.exe
sqlwriter.exe
sqlbrowser.exe
If not, then go to windows services, and set the SqlServer.exe to run, it should cause the others to fire up.
You should also have the Sql Server Management program installed. This will allow you to confirm the server is runing, create tables, etc. If it can connect to the server, then the connection string is the issue.

SqlConnection conn = new SqlConnection("Data Source=vista-sp1;Initial Catalog=Dorpshuis;Integrated Security=SSPI);
JerryShaw 46 Posting Pro in Training

Please mark as Solved
Thanks

JerryShaw 46 Posting Pro in Training

That SQL message can occur for a number of reasons. It is a generic message. You have to look at the innermessage and sometimes the innermessage.innermessage to see the real reason.

The connection string I sent uses windows authentication, and is pointing to my server. Make sure you are passing the name of your server, and catalog (aka database) in your own connection string.

If the message takes 30 seconds to appear, it is because you connection string is pointing to the wrong server/database. If it comes back immediately, it means that it sees the server, but either your database name is wrong, the authentication type is wrong, or the credentials are wrong.

Tell me the name of your server, database name, authentication mode, and credentials, and I will send you the correct connection string.

// Jerry

JerryShaw 46 Posting Pro in Training

Basically, it is just a matter of first, make sure the sender is a button type, then cast sender as a button, then you have the originating button at your disposal.

Looking for something like this ?

private void button1_Click(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                Button btn = (Button)sender;
                MessageBox.Show(btn.Name + " pressed");

                btn.Text = "MeHo";
                if (btn == button2) // something special if it was from button2
                    btn.Text += "-2";
            }
        }

//Jerry

JerryShaw 46 Posting Pro in Training

Instead of mangling the SQL statement (embedding CRLF), just iterate through the rows and columns, and populate the text box.
Here is a simple example:

private void toolStripButton1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=SHAWHP;Initial Catalog=SalonWiz;Integrated Security=True");
            conn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter adapter = new SqlDataAdapter(
                          "SELECT top 10 * from Employee",conn);
            adapter.Fill(ds);
            foreach(DataRow row in ds.Tables[0].Rows)
            {
                for(int i=0;i< ds.Tables[0].Columns.Count;i++)
                    textBox1.Text += row[i].ToString()+Environment.NewLine;

                textBox1.Text += Environment.NewLine;
            }
        }

// Jerry

JerryShaw 46 Posting Pro in Training

The code below returns the 6 parts you were looking for.
The seps var is now a string array instead of char array.
Using the string array in Spit with the remove emptry entries option.

string str = "while if for, public class do.";
            string[] seps = { " ", ".", "," };
            string[] parts = str.Split(seps,StringSplitOptions.RemoveEmptyEntries);
            string c = "";
            foreach(string z in parts)
                c += z+Environment.NewLine;
            MessageBox.Show(c,string.Format("{0} elements",parts.Length));

If this works for you (as it does for me), pleaase mark this thread as solved.
Thanks,
Jerry

JerryShaw 46 Posting Pro in Training

It appears that it does it correctly because the space after the comma is also a token.
You can either add a new sep ", " (with a space) or break the string into multipe Splits, and combine them later.

JerryShaw 46 Posting Pro in Training

Each time you use the ReadLine method, it will move the poistion marker in the stream to the next line. so you can keep using the same method to populate the other text boxes.

textBox1.Text = streamreader1.ReadLine();
textBox2.Text = streamreader1.ReadLine();
textBox3.Text = streamreader1.ReadLine();
// and so on.

JerryShaw 46 Posting Pro in Training

I tried answering this morning, but the network connection failed. Sorry for being late :)

The Insert statement does not allow a Where clause.
I will assume that your Employee table has a column named "EmployeeName" or some place to put the name value. It would not make sense to place a task against an employee without also telling the database which employee the task is assigned.

I have revised the proc for you below.

Regards,
Jerry

create PROCEDURE [dbo].[AssignAndStore] 
	@name varchar(50),
@TaskAssigned nvarchar(50),
@TimeAssigned nvarchar(50)
AS
BEGIN
 
insert into Employee(EmployeeName,TaskAssigned,TimeAssigned)
values (@name,@TaskAssigned,@TimeAssigned)

END
JerryShaw 46 Posting Pro in Training

I tried them out in 2008, and the directory browser's path does not react correctly. You can add some text boxes to your form that are populated with the new path from this component as you select or even double click around on the dir component... It fails 90% of the time to update it own Path property.
I would look for an alternative solution.

// Jerry

JerryShaw 46 Posting Pro in Training

AMINIT,

If your project requires that you "must" use the System.Timer.Timer class, then you can set the timer's SynchronizingObject property to the form or component to take care of that cross-threading error. That will also eleveate the issue of invoking delegates.

From MSDN:::

If you use the Timer with a user interface element, such as a form
or control, assign the form or control that contains the Timer to 
the SynchronizingObject property, so that the event is marshaled to 
the user interface thread.

:::

This type of timer runs in its own thread. If you drop a timer component onto your form, then it will automatically set the SynchronizingObject property for you.

BTW: Since _rockbaer opened the topic of using threaded techniques, I re-wrote your project (inluding the save controls to text methods you requested) using a thread and no timers. The code length was chopped to less than 50% of what you currently have. If you are interested, and ready to delve into threads, I can send you the updated project. It will also show you how you can use the DateTime and TimeSpan classes instead of all those time decoding methods.

//Jerry

JerryShaw 46 Posting Pro in Training

Rockbaer,

Obviously you misread. The Timer class he is using will issue a cross-thread error because it is running in its own thread (nature of that timer class). That is why in your code response, you are using a delegate where he is not. Your delegate allows the code to work with components in the main thread.

The TimerClock class does not have a readonly attribute, so you are wrong in that appraisal.
The use of this TimerClock class IS the problem if the coder does not go through the process of creating delegates, and invoke the delegate when touching main thread non-thread safe components, as is quite evident in the cross thread error he received.

All that being said, introducing threading techniques at his level is not the right approach. Using a simple timer gets the job done. In fact, you built on his example code allowing the timer to control other objects in the main class, and then making two delegate calls to account for the non-thread safe textbox. IOW you are just perpetuating the use of an errant design, and probably doing more harm to his learning experience. If you want to give him a lesson in using threads, then provide him with a total re-write of the project, and explain the delegate and invoke techniques so he knows why and how they should be used.

If I were to write this program, I wouldn't be using a timer at all. I …

JerryShaw 46 Posting Pro in Training

AMINIT,

This looks like the same program you sent to me earlier this week that I fixed for you.
Did you not get the zip file I sent back ?
The problem is the way you declare the out of class timer. The way it is defined, means it will run in its own thread. Threads can not adjust non-thread safe components in other threads (like this main thread).

private System.Timers.Timer timerClock = new System.Timers.Timer();

Above is the line that is causing your error.
Comment out that line, drag a timer component onto the form, and re-wire it to use the onTick event instead of the onTimer event (different args).

If you need me to re-post the program for you let me know. Otherwise please mark this post as solved.

Thanks,
Jerry

JerryShaw 46 Posting Pro in Training

The reason is that the compiler can see that there is the possibility that the condiotnal statement could be false, and therefore it can fall through to the next case statement.. which is illigal. So to fix the problem, always be sure that the case either returns, or does a break; as the last statement in each case statement.

JerryShaw 46 Posting Pro in Training

First, your ASP is the one connecting to the database using the credendials of the web site setup. (Windows authentication mode).

You are to validating the information from the login screen against the database. Just keep in mind that SQL sees the web service as the one logged in not the credentials or person supplied in the query. IOW, the user is not logged in as the user. You connection string is using windows authentication, meaning it takes the web service credentials as the logged in user.

Does that help ?

JerryShaw 46 Posting Pro in Training

ConfusedMuchMor,
as scru mentioned a field aka property, variable or parameter that holds a value or collection of values. You can assign values to and get values from these types of objects.

A method on the otherhand is a piece of executable code. It may return nothing (void) or return a value. Typically you will use a method to cause something to happen such as populate some component on your form, or carry out any number of tasks.

To understand some of these basics, you should grab one of the many wonderful programming books. All programming languages have the basic concepts of storing data in some variable, and calling methods (also called functions and procedures in different languages).

//Jerry

JerryShaw 46 Posting Pro in Training

I didn't find this error when I compiled it.
I optimized it a bit, and set the voice default (which you did not.. which might have something to do with it.

Anyway, I have attached my version of your project for your review.

Jerry

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

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

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

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

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,

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

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
int iMoney = cbCombo.indexof("money");
if (iMoney > -1 )
{  cbCombo.SelectedIndex = iMoney; }