|
I will be passing foo to a "func(txtStr)" and need to get back a string called validFoo.
Thanks for the great reply, I forgot that I could do a IndexOf inside a substring!
|
|
|
|
|
Even worse, I also need to get the part of foo before '_', trying to do this;
string [] parts = foo.Split(new char[]{'_'});<br />
string theTable = homeTbl + parts[1];
But keep getting a "Index was outside the bounds of the array"
You are only as good as your last project.
|
|
|
|
|
DEWright_CA wrote:
ut keep getting a "Index was outside the bounds of the array"
You should check your array first, to make sure you have as many values as you hoped. Even better, use regular expressions for this sort of stuff.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
DEWright_CA wrote:
string [] parts = foo.Split(new char[]{'_'});
string theTable = homeTbl + parts[1];
You must check size of array before you acces it's second item.
like:
string [] parts = foo.Split(new char[]{'_'});
if( parts.Lenght > 1 )
{
string theTable = homeTbl + parts[1];
}
else
{
}
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
I'm writing a program in C# and in the process I need to capture a window handle. Typically I can do this using the title, however, in this case the title is long and complicated with strnage characters and... lets just say that using the title won't do. So I need another method. I've got a few Ideas, but so far none have worked. So if anyone can direct me to a good method using a mouseclick or any other clever means, I would greatly appreciate it.
jake
|
|
|
|
|
So what's wrong with getting the title of the window and just searching that string for a part of the title your looking for?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there a method to search for a window using part of the title? In other words if the name of the window was "123 MyWindow 23%^ iii" is there some method like GetWindow that will allow me to find a window using "MyWindow" as the only parameter?
jake
|
|
|
|
|
Don't think so.
But you could do an EnumWindows/GetWindowText (the WinAPI way) and do a substring-search by yourself.
You could also search for a certain window class, if the window in question has a specific one
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Using the Win32 functions EnumWindows and GetWindowText, you can get the title of every window in the system, even invisible ones.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Just use the win API FindWindow function and pass the window's Class and pass the title as null.
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
You find the class of a windows by using spy++. We would call a window with the class of "alexEggRules" as follows:
IntPtr handle=FindWindow("alexEggRules", null);
/\ |_ E X E GG
|
|
|
|
|
I have developed a Windows application that uses the serial port with a modem to call out to a few devices and download some information which is then logged in a database. This is done at a predetermined time for each device, on a daily basis. It can also be invoked from the GUI by the user.
I have now reached the point where I have to include more modems and make the app multi-user. I would like to have some direction as to how this could be done. I have thought about Windows service or web service with a service control panel as the GUI or even better a browser....I have never worked with multi-threading, and also how do I know how many modems I have installed and which ones are in use at a particular time?
Thanks in advance
Chris
|
|
|
|
|
I would look at TAPI, and if the native API is too daunting, there are several third party libraries that make TAPI easier.
The reason I suggest TAPI is because serial ports and modems aren't the same thing anymore. A lot of "modems" are software simulations which don't behave like you would expect with regards to communicating over a typical COM port. I learned this the hard way!
A TAPI interface will do a lot of the background work for you, and you can also test whether devices are available or in use.
I've used this library[^] for C++ development. I'm sure there's C# equivalents out there too.
As to making your application multi-user, you'll have to explain that a bit more.
Marc
My website
Latest Articles:
Undo/Redo Buffer
Memento Design Pattern
|
|
|
|
|
Thanks for your hint, I will look into TAPI.
As far as the multi-user part is concerned, I would like to have many users perform the downloads simultaneously (so for instance if two users requested collection of information at the same time the application would pick two ports and call, and display the appropriate results to each user).
|
|
|
|
|
I'm replying to this post again since your other reply was done as "anonymous".
Regarding:
As far as the multi-user part is concerned, I would like to have many users perform the downloads simultaneously (so for instance if two users requested collection of information at the same time the application would pick two ports and call, and display the appropriate results to each user).
If you implement this as a GUI in a browser, the ASP.NET application is running in its own thread and its own context, so really all you will need to do is find a free modem and dial out (there is a potential of two threads trying to connect to the modem at the same time, so you'll have to implement some smart resource locking). The biggest problem I see is that when the user hits "Get Data" on the browser, he may be sitting there for a long time before the page refreshes. I'm not an ASP.NET expert so I don't really have a good suggestion for how to handle that.
Also, same with web services--they should run in their own context. Make sure whatever TAPI package you get can run in threads, or if you work with the native TAPI interface, you'll have to make sure your code is thread safe.
Marc
My website
Latest Articles:
Undo/Redo Buffer
Memento Design Pattern
|
|
|
|
|
Hello,
I'm getting random SEHException s through my code, and the Message says taht an external component raised an exception. None of my code is present in the stack trace.
Any ideas on how to start debugging it??
[EDIT: This is the stack trace:
System.Runtime.InteropServices.SEHException
Mensaje: Un componente externo inició una excepción. <-- "an external component raised an exception"
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
It seems it's sending a message, but how can I know to which window and which message?]
More information will be coming soon (when I get it!)
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi
In my winform application I have multiple buttons. Of those buttons, I want one to behave as Enter key by default and other as Escape key.
Tried to search for it, but couldn't find a good solution. Please suggest how can I acheive this?
Thanks in advance.
Pankaj
|
|
|
|
|
Hi,
1. Select the form where you have placed the buttons and Properties.
2. Seek for Misc. category
3. Choose AcceptButton property then bind it to the desired button.
4. Choose CancelButton property then bind it to the desired button.
Hope it helps.
Uri
|
|
|
|
|
hi,
Just change the DialogResult Property of a Button.
Suupose that You want to work a button as Cancel ,then change the DialogResult to "Cancel".
regards,
pubudu.
|
|
|
|
|
I think Uri's answer makes more sense. Thanks guys.
|
|
|
|
|
Hi,
I am implemeting Windows application in C#.
I want to store all the databases names ,Tables names and column names of local host.
I have implemented but in servaral connection i want to implement in only one connection.
I was using ArrayList but its becoming more complex can anyone tell me using Jagged array.
How it should be done using jagged array
regards
sanjeev
|
|
|
|
|
Look at the classes of System.Collection and System.Collection.Specialized namespaces. I normally use HashTable and store objects by name then retrieve them by name as well and cast to the type of the class that was stored. When I need to access objects by index then I use SortedList. And to store name value pair of strings you can use NameValuePairCollection.
|
|
|
|
|
Hi can you pls integrate this
program to retrive all databases of local host
----------------------------------
private void button3_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
String strServerName, strUserName, strPassword;
SqlConnection sqlServerConnectionObject = new SqlConnection();
SqlDataReader sqlDataReaderObject;
SqlCommand sqlCmdObject;
strServerName = "localhost";
strUserName = "sa";
strPassword = "san";
sqlServerConnectionObject.ConnectionString = "Persist Security Info=False;database=master;server=" + strServerName + ";User ID=" + strUserName + ";Password=" + strPassword;
sqlServerConnectionObject.Open();
sqlCmdObject = new SqlCommand("Select * from sysdatabases",sqlServerConnectionObject);
sqlDataReaderObject = sqlCmdObject.ExecuteReader();
while (sqlDataReaderObject.Read() == true)
{
String strDatabaseName = sqlDataReaderObject.GetString(0);
listBox1.Items.Add(strDatabaseName);
}
}
--------------------------
program to retrive all tables of local host
----------------------------------------------
private void button4_Click(object sender, System.EventArgs e)
{
listBox2.Items.Clear();
string strDatabase=listBox1.SelectedItem.ToString();
MessageBox.Show(strDatabase);
String strServerName, strUserName, strPassword;
SqlConnection sqlServerConnectionObject = new SqlConnection();
SqlDataReader sqlDataReaderObject;
SqlCommand sqlCmdObject;
strServerName = "localhost";
strUserName = "sa";
strPassword = "san";
sqlServerConnectionObject.ConnectionString = "Persist Security Info=False;database=" + strDatabase + ";server=" + strServerName + ";User ID=" + strUserName + ";Password=" + strPassword;
sqlServerConnectionObject.Open();
sqlCmdObject = new SqlCommand("Select * from sysobjects where type='u'",sqlServerConnectionObject);
sqlDataReaderObject = sqlCmdObject.ExecuteReader();
while (sqlDataReaderObject.Read() == true)
{
String strDatabaseName = sqlDataReaderObject.GetString(0);
listBox2.Items.Add(strDatabaseName);
}
sqlCmdObject.Dispose();
sqlServerConnectionObject.Close();
sqlServerConnectionObject.Dispose();
}
-----------------------------------------------------
Program to retrive all coulmsn of tables of local host
------------------------------------------------------------
private void button5_Click(object sender, System.EventArgs e)
{
//listBox1.Items="";
MessageBox.Show(listBox2.SelectedItem.ToString());
listBox3.Items.Clear();
SqlConnection conn = new SqlConnection("Integrated Security=yes;Initial Catalog=" + listBox1.SelectedItem.ToString() + ";Data Source=(local)");
conn.Open();
SqlCommand command = new SqlCommand("select * from " + listBox2.SelectedItem.ToString() , conn);
SqlDataAdapter adapter=new SqlDataAdapter(command);
DataSet dataset=new DataSet();
adapter.Fill(dataset, listBox2.SelectedItem.ToString() );
string s1=dataset.Tables[ listBox2.SelectedItem.ToString() ].Columns.ToString();
int j=1;
foreach(DataColumn column in dataset.Tables[ listBox2.SelectedItem.ToString() ].Columns)
{
listBox3.Items.Add(column.Caption);
j=j+1;
}
dataset.Clear();
command.Dispose();
conn.Close();
conn.Dispose();
/*
int i1=listBox1.Items.Count;
MessageBox.Show("item Count=" + i1);
for(int i=0;i<i1;i++)
{
MessageBox.Show(listBox1.Items[i].ToString());
}
*/
}
---------------------------------------------------------------
Basically my requirement is that when the windows forms open dev1 farm is selcted and its crossponding
all the databases and tables names and columns names are stored in farm-config.xml file
I tried its getting hanged in loop I want to implement in single loop
Can you make this program i have to submit today i think Jaaged Array i will have to use
I was trying to do in ArrayList
Suppose
in my computer there are two databases A and B
A databases has two tables A1 and A2
B databases has two tables B1 and B2
A1 table has Two columns A3 and A4
A2 table has Two columns A5 and A6
B1 table has Two columns B3 and B4
B2 table has Two columns B5 and B6
See how will structure come when all the tables names,databases names and columns names are stored
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="dev1">
<connection address="192.168.1.12" user="root" selectedConnection="1" password="daask">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="A" sourceType="amacs">
<tables state="0" name="A1">
<columns state="0" name="A3" />
<columns state="0" name="A4" />
</tables>
<tables state="0" name="A2">
<columns state="0" name="A5" />
<columns state="0" name="A6" />
</tables>
</database>
<database state="0" name="B" sourceType="amacs">
<tables state="0" name="B1">
<columns state="0" name="B3" />
<columns state="0" name="B4" />
</tables>
<tables state="0" name="B2">
<columns state="0" name="B5" />
<columns state="0" name="B6" />
</tables>
</database>
</farm>
<farm name="dev2">
<connection address="192.168.1.13" user="root" selectedConnection="1" password="">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-11" starttime="11:41:12" enddate="2005-05-11" endtime="12:11:31" />
<state>1</state>
</connection>
</farm>
</farm-config>
</root>
I have given the code for separete only thing you have integrate when farm=dev1 seleceted
all the databases name and tables names and columsn names are stored in tp xml file
I am getting too confused in loop
regards
sanjeev
|
|
|
|
|
hi,
Are u sure that Column name part is working?
"SqlCommand command = new SqlCommand("select * from " + listBox2.SelectedItem.ToString() , conn);
"
I think this SQL Stattement is wrong.
To find Columns use following Query:
"select Column_Name from INFORMATION_SCHEMA.columns where Table_name='"+listBox2.SelectedItem.ToString()+"'"
|
|
|
|
|
Hi
EVerything is correct in my code This code retives after particluar selection from listbox.
I have to dynamically retrive all databases and tables names and columns names of local host
in single connection. These all names will be storeed into xml file
i think i will have to use jagged array.
How can i store all the adatabaes names ,tables names and columdn names in jagged array so that i can store into xml file
can someone integrate all the sql statement in single SqlConnection statement
using Jagged array or something better from the view of Optimization
regards
sanjeev
|
|
|
|
|
Use the code in:
button3_Click
To create a method:
StringCollection GetDatabaseNames() This method should return all the database names.
Use the code in:
button4_Clic
To create a method:
StringCollection GetTableNames(string dbName) This method should return all tables for a specific database name.
Use the code in:
button5_Click
To create a method:
StringCollection GetColumnNames(string dbName, string tableName) This method should return all columns for a specific database/tablename combination.
I won't go into xml details but following is a pseudo-code of what your code should look like:
StringCollection databases, tables, columns;<br />
databases = GetDatabaseNames();<br />
foreach (string dbName in databases){<br />
tables = GetTableNames(dbName)<br />
foreach (string tableName in tables){<br />
columns = GetColumnNames(dbName, tableName)<br />
foreach (string columnName in columns){<br />
<your code to store in xml><br />
}<br />
}<br />
}
|
|
|
|