|
waheed awan wrote: is it possible to do the same task programatically if then how to do it
Yes. Simply start a new process via the System.Diagnostics.Process class. You can pass arguments to the Process's StartInfo property. Then call .Start() on the process to fire it off.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hello,
my question would be too complicated if I used the real code, so I'll use a trivial substitutional example instead:
Let's have three separate objects - windows forms, invoked within one application: Form1, Form2, Form3. Form1 owns a method named AddOne() that adds number one to Form1's private field int Result and displays the result by assigning it to Form1's label1.Text property.
Forms Form2 and Form3 have both one button that, upon clicking, invokes Form1's method AddOne() and performs the above mentioned action in Form1.
Now how do the methods that are called upon the button click on either Form2 or Form3 access Form1's non-static AddOne() method?
Thanks for help,
Michal
|
|
|
|
|
you have to pass Form1 iteself onto the other forms through the constructors that create the other 2 forms.
Example:
Form1.css
Form2 frm2 = new Form2(Form1);
Form2.css
//Constructor
static void Form2(Form form1)
{
Form frm1 = form1;
InitializeComponents();
}
Then you can access the fields and methods in Form one by referencing them like so:
frm1.AddOne();
My code may not be exact because Ive never passed a form object but im sure that this would be a good starting point.
|
|
|
|
|
I'm not sure how safe it is, but this is what I'd do:
Pass in Form1 into Form2's and Form3's constructors, like this:
class bla : Form
{
private Form FORM1;
[...]
public bla(Form form1)
{
FORM1 = form1;
[...]
}
[...]
private someMethod()
{
FORM1.AddOne();
}
[...]
}
Since this is OOP we're talking about, you're just passing in the address of Form1 into the constructors. You just have to remember to instantiate Form1 before Form2 and Form3.
I've been known to do this, passing a form to different controls so that they can call the form's instance methods.
Like I said, I don't know how safe it is providing a form instance to the other constructors, but it should work (and I've never had any problems with that method).
Something else you could do is create a static member like this:
public static Form1 theForm;
And, when you instantiate Form1, set the static variable to the instance, like this:
Form1 f = new Form1();
thisClass.theForm = f;
Hope this helps!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Thanks much both!
Passing the object itself to the other object to be able to invoke the first object's non-static method does really work.
Anyway, I was thinking about something more universal, like subscribing the AddOne() method as a client of the events of button clicks on the other forms. Would such a subscription be feasible between instantiated classes WITHOUT passing the entire object as a reference?
Something like this:
using System;
namespace ObjectCommunication
{
public delegate void MyEventHandler(string EventParams);
public class EntryClass
{
public event MyEventHandler MyEvent;
static void Main()
{
EntryClass MyEntryClass = new EntryClass();
EventDemoClass MyEventDemoClass = new EventDemoClass();
MyEntryClass.DoWork();
}
private void DoWork()
{
MyEvent += new MyEventHandler(EventClientMethod_1);
MyEvent += new MyEventHandler(EventClientMethod_2);
MyEvent("_event_parameters_");
}
private void EventClientMethod_1(string EventParams)
{
Console.WriteLine("MyEvent client 1 triggered with these params: " + EventParams);
}
private void EventClientMethod_2(string EventParams)
{
Console.WriteLine("MyEvent client 2 triggered with these params: " + EventParams);
}
}
public class EventDemoClass
{
public void EventClientMethod_3(string EventParams)
{
this.DoSomething(EventParams);
}
private void DoSomething(string Params)
{
Console.WriteLine("MyEvent client 3 triggered with these params: " + Params);
}
}
}
Here we would like to subscribe the EventClientMethod_3 method to MyEvent event in EntryClass. That would be more secure than passing the entire object as a reference in a constructor I think.
Thanks,
Michal
-- modified at 19:11 Monday 28th August, 2006
|
|
|
|
|
michal.kreslik wrote: That would be more secure than passing the entire object as a reference in a constructor I think.
Often times if you need some information from an object, but not the whole object, you use interfaces. Not only does this prevent access to the whole object, but it also abstracts away underlying implementation, which is really good for things like unit testing.
interface IObjectWithFoo
{
int Foo { get; }
}
class FooForm : Form, IObjectWithFoo
{
public int Foo
{
get { return bar; }
}
}
class Consumer : Form
{
public Consumer(IObjectWithFoo instance)
{
int val = instance.Foo;
}
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Dear Friends,
Please email me some good final year project suggession. I know most of you have already design your final project. Please send me some good market oriented Project.
My email address is ali_fastian@yahoo.com
Please send me any suggession freely b/c it's very important 4 me. I am waiting for your replies....
Rgds,
aLi
|
|
|
|
|
You could write a little crawler that continually browses programming forums looking for email addresses.
When the crawler finds an address, it sends a message stating that it is a bad idea to post your email address openly in a forum because it attracts spam.
That's my suggestion.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
ali! this is your professor from university. i have a doubt you could make good student. i have a doubt you could make good person. now for shame you post your project on teh Cpian when i sexplicitly told you no! now you get dungeon blackened grade for your schooling on final project. you make me with your cheatings on the Cpians you monkey turd.
Sincelery yours, Computer Information conSciences Professor and grader, Sharada Ulhas
|
|
|
|
|
Dear Sir
I am not ask you to send me some codes
I only ask some suggession, what project i should select as a final year project.
Rgds,
aLi
|
|
|
|
|
Hi guys,
I want to extract some specific image metada from an .jpg file. I explored through the codeproject and msdn as well as google but found nothing (I mean not exactly nothing but only codeparts and info which are not I want).
Lets me explain in more detailed : I edit some image information from Photoshop (right-click on the image window header > file info > description tab).. After editing whenever I load an the image I want to see the description, title, author, keywords etc..
With the PropertyItem I can only view the description, author and creation time (other info doesn't worth for me).
So my question is how can I read AND write specific metada pieces ?
.:: Something is Wrong ::.
|
|
|
|
|
This might help: Retrieve detailed information of a File[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
hi,
I have an text file grouped into records that I need to be parsed into a object. The record is like :
H10000<cr> ( H from header of the record )
I1,name,age,sex (Information1)
C1,text... (Comment 1 for Information1)
....
Cn,text... (Comment n for Information1)
I2,name,age,sex (Information2)
C1,text... (Comment1 for Information2)
....
Cn,text... (Commentn for Information2)
...
In,name,age,sex (Information n)
C1,text... (Comment1 for Information n)
....
Cn,text... (Commentn for Information n)
E1 (End message)
There is a class for each Tag (H,I,C,E) and a Record class that is the superclass for the classes(H,I,C,E) . I need to parse this file and store the informations from the records into a object using generics. For the informations I must use a list. I also need the reverse operation : from object to write to file.
I realize that the code must be written by myself but I would appreciate some general help about how to create the object from file
thanks
|
|
|
|
|
Well seeing as it appears to be a CSV file you can read in the whole file line by line and split it to get various parameters.
while (stream.Peek() != -1)
{
string[] cells = stream.ReadLine().Split(',');
} Hope that gets you started.
As of how to accomplish this, have you ever tried Google?
|
|
|
|
|
Serialization
only two letters away from being an asset
|
|
|
|
|
If you could rewrite the file using xml tags .NET has some nice built in support for reading and writing that would do exactly what you want, shoot me an email and i'll send you some examples(mine are too long to post here, but only because i load a lot of data from the files, and do the same for writing them). Another, probably not very good way is to open the file into a stream reader and use the ReadLine() method to grab each line and put it into a string, then fall through a switch on the first character so you know what kind of object to use, and writing may be a bit more difficult it'd depend on how you deal with the data in your program...personally i'd prefer a foreach and then use a switch on the object type, as its simple, and easy to fix, but it doesnt work everywhere...if you'd like examples shoot me an email.
|
|
|
|
|
SomeGuyThatIsMe wrote: If you could rewrite the file using xml tags
Of course he can't change the school assignment.
---
b { font-weight: normal; }
|
|
|
|
|
why not? i always did. I didnt see anything about a school assignment, but i'm mostly blind, so i prolly missed it, and just assumed that it was for work of some kind...but the stream reader method should work, fairly easily, even if it is a bit slow.
|
|
|
|
|
I must select the "not very good way" and to open the file into a stream and use ReadLine() to grab each line and put it into a string, then fall through a switch on the first character so I know what kind of object to use
This part I know how to do it ... The don't know part is how to use the fields and C# classes to create this single object I need. Some one sent me some code in VB.NET that I think it seems like i need, only that I need it in C#. If you have something similar please send at least some explanations.
The VB code :
Private Sub ParseFile(ByVal filename As String)
Dim headers As New HeaderCollection
Dim reader As IO.StreamReader
While reader.Peek <> -1
Dim line As String = reader.ReadLine
Select Case line.Substring(0, 1)
Case "H"
headers.Add(line)
Case "I"
headers.LastItem.InformationList.Add(line)
Case "C"
headers.LastItem.InformationList.LastItem.Comments.Add(line)
Case "E"
headers.LastItem.Footer = line
End Select
End While
End Sub
Private Sub WriteFile(ByVal filename As String, ByVal headers As HeaderCollection)
Dim writer As IO.StreamWriter = New IO.StreamWriter(filename, True)
For Each h As Header In headers
writer.WriteLine(h.Text)
For Each i As Information In h.InformationList
writer.WriteLine(i.Text)
For Each c As Comment In i.Comments
writer.WriteLine(c.Text)
Next
Next
writer.WriteLine(h.Footer)
Next
writer.Flush()
writer.Close()
End Sub
Public Class Header
Private _informtions As New InformationCollection
Public Text As String
Public Footer As String
Public Property InformationList() As InformationCollection
Get
Return _informtions
End Get
Set(ByVal Value As InformationCollection)
_informtions = Value
End Set
End Property
End Class
Public Class Information
Private _comments As New CommentCollection
Public Text As String
Public Property Comments() As CommentCollection
Get
Return _comments
End Get
Set(ByVal Value As CommentCollection)
_comments = Value
End Set
End Property
End Class
Public Class Comment
Public Text As String
End Class
Public Class HeaderCollection
Inherits CollectionBase
Public Overloads Sub Add(ByVal Text As String)
Dim h As New Header
h.Text = Text
List.Add(h)
End Sub
Default Public Property Item(ByVal index As Integer) As Header
Set(ByVal Value As Header)
Me.List(index) = Value
End Set
Get
Return DirectCast(Me.List(index), Header)
End Get
End Property
Public ReadOnly Property LastItem() As Header
Get
Return DirectCast(Me.List(Me.List.Count - 1), Header)
End Get
End Property
End Class
Public Class InformationCollection
Inherits CollectionBase
Public Sub Add(ByVal Text As String)
Dim i As New Information
i.Text = Text
List.Add(i)
End Sub
Default Public Property Item(ByVal index As Integer) As Information
Set(ByVal Value As Information)
Me.List(index) = Value
End Set
Get
Return DirectCast(Me.List(index), Information)
End Get
End Property
Public ReadOnly Property LastItem() As Information
Get
Return DirectCast(Me.List(Me.List.Count - 1), Information)
End Get
End Property
End Class
Public Class CommentCollection
Inherits CollectionBase
Public Overloads Sub Add(ByVal Text As String)
Dim c As New Comment
c.Text = Text
List.Add(c)
End Sub
Default Public Property Item(ByVal index As Integer) As Comment
Set(ByVal Value As Comment)
Me.List(index) = Value
End Set
Get
Return DirectCast(Me.List(index), Comment)
End Get
End Property
End Class
Thanks
|
|
|
|
|
ick, i hate VB, mostly because the vast majority of examples you find for it never bother with strict typing, which if you're going to translate to c# is very necessary.
ok i'm going to assume that all this needs to do is read the file, then write that same data to a different file, i havnt messed with generics, but i would either make the "superclass" have properties of the other types, or make the other types like header or comment inherit the superclass, but i havnt messed w/ generics so there's prolly some slick, cool way to do this that i'm not aware of.
but to read the file in c# (you get to declare the varibles cuz i'm too lazy to type that), i'm also going to assume that the super class has properties of the type of the other classes so i can get to them like record.header.*something a header has or does*
while(!endOfFile){//endOfFile is a bool initialized to false
line = reader.ReadLine();//line is a string, guess what reader is
firstChar = line.SubString(0,1);//pretty easy so far right?
switch(firstChar){
Case 'H':
record.Header.value = line;/*record is an instance of the superclass, value is the property you want the header stored in, if you want the first letter gone you'll have to remove it with a line = line.Remove statement*/
break;
Case 'I':
//do whatever you need to do to save the information in the record object
break;
/*keep going until you've added everything for a certian record..if you can have mulitple comments the comments property of the record class may need to be an array or you'll have to figure out some other way to handle it*/
}//end switch
recordList.Add(record);/*adds the record object to an ArrayList of record objects..or you could use a normal array if you know how many records you'll have*/
}//end while dotn forget on case 'E' you have to set end of file to true so the loop ends
to write the file you'll just need a StreamWriter then just use a foreach loop to get your stuff back
foreach(Record r in RecordList){
writer.write(r.header.value.ToString());//so on and so forth, you'll have to so something speical for the comment part if you can have more than one...if you used an array or array list you can just loop through the comments like you are the records in record list
}//end foreach
and tada you're done...i think, i'm not gaurenting that this code will work( i wrote it on this site not in visual stuio and i havnt tried it, but the methodology does work i've used that several times before. if you need anymore help or have any questions shoot me an email to dalaji@excite.com(its my spam account so put CodeProject help or something like that in the subject so i dont delete you)
|
|
|
|
|
My biggest problems aren't the parser but the classes , the fields and propreties of those classes. At the moment I have the following classes :
Record ( which is the superclass )
- MessageHeaderRecord ( the superclass for the next classes ) :
- InfosRecord ( the class for the I tag
representing the informations from text )
- CommentRecord
- OrderRecord
- ResultsRecord
- TerminatorRecord
For each of this classes I have a corresponding class (MessageHeaderRecordFields ,...) in which I created the fields to put the infos from the file.
So far so good ...
MessageHeaderRecord beeing the superclass for the rest of classes I put inside of it a generic List :
private List<informationrecord> m_Infos = new List<informationrecord>()
internal List<informationrecord> Infos
{
get
{
return m_Infos;
}
}
and the constructor is
internal MessageHeaderRecord()
{
RecordType = RecordType.MessageHeaderRecord;
m_Fields = new MessageHeaderRecordFields(); //
}
I did this because I want to access the objects as follows :
Message MyMessage = new Message();
MyMessage.Infos[3].Fields.SequenceNumber = "1";
MyMessage.Infos[3].Fields.InfoName.LastName = "John";
// Create a new info
int nInfoIndex = MyMessage.AddNewInformation(); (*1)
// Set the info specific data such as name, age, etc. for the info we just addded
MyMessage.Infos[nInfoIndex].Fields.InfoName.LastName = "John";
// Add an order record for this patient
int nOrderIndex = MyMessage.Infos[nInfoIndex].AddNewOrder(); (*2)
// Set the order specific information for the new order
MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].Fields.OrderID = "11";
// Add a comment to this order
MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].AddNewComment(); (*3)
// Set the text for the new comment
MyMessage.Infos[nInfoIndex].Orders [nOrderIndex].Commment.Fields.CommentText = "I am a comment.";
// Add a Result to this order
nResultIndex = MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].AddNewResult();
// Set the new result's data
MyMessage.Infos[nPatientIndex].Orders[nOrderIndex].Results[nResultIndex].Fields.SequenceNumber = "333"; (*4)
So my problems redefined would be
(*1) - In which class to put the AddNewInformation() method
(*2) - In which class to put the Orders List and where to put the AddNewOrder() method
(*3) - In which class to put the Comment List and where to put the AddNewComment() method
(*4) - Same with Results List and AddNewResults() method
Please help me again with this issues because I really cant figure them out.
Thank you in advance
|
|
|
|
|
*1 you'd have to put the AddNewInformation method into the class that MyMessage instantiates(sp?) so since MyMessage is of type Message AddNewInformation would have to be in the Message class, or in the class that Message inherites. the same with the others...if you want to add a record to orders, then orders must implement that function, if you're sure you want to access the objects like this.
it looks like you want to access the rest of the properties like they're in a predefined array...if you want your Add** methods to work like the ArrayList.Add() method you dont need the [], just call the add function, using a predefined array isnt a very good idea unless you always know the number of the elements you'll need..and setting the array to be overly large is just a bad habit to get in. you could just have the comment, info, orders, etc.. classes store info about themselves and then have Record contain arrayList properties for each that way you can still use [] to specify records, and they'll be dynamically sized...and you could either put the Add*** methods in Record and just have them add new instances of the respective class to the list. also if you have the Add*** methods take a parameter or two you could save yourself soem typing at least w/ the coments, and set the text for the comment when you add it. this may be possible with the other add methods but i'd have to see your code. if this didnt help you could send me an email w/ some of your class definitions, thats about the only way.
Oh, if i'm wrong about something feel free to correct me, i'm mostly self taught and generally have a different way of looking at and explaining things, than most other programmers i've talked to, sometimes my way works better sometimes its way worse.
HTH
John
|
|
|
|
|
Ive been trying to figure this problem out. I have a status strip with a progress bar in it. I want to use that pb to increase as the file is copying. Someone suggested I have an event that occurs every few bytes or so to increase the pb. I have looked and looked for a way to do this only to return to not have anything. Any help or a link that can do this would be greatly appreciated. Thanks.
|
|
|
|
|
try to use the Refresh() method for your progress bar after each PerformStep()
regards..
.:: Something is Wrong ::.
|
|
|
|
|
With BCL classes you're out of luck here.
The built-in classes don't give you any progress update while copying.
You can either write your own file copy routine that's firing an event from time to time or p/invoke CopyFileEx .
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|