|
Aside from the fact that your two examples are using conditions that are the opposite of each other , I agree with Christian that a regular for loop would be the obvious choise:
for (int x = 0; x < some_number; x++) {
...dostuff
}
---
Year happy = new Year(2007);
|
|
|
|
|
Hi,
I wanna know how we can read an Excel file and then write it into a table in Access Database.
After that, we export our data into an Excel file.
Please help me, thanks so much
|
|
|
|
|
You want to read an Excel file to import into Access to then export it back into Excel? What would be the point?
only two letters away from being an asset
|
|
|
|
|
that's right. But i want my program can do that when i click a button. If u know how, share for me, please
|
|
|
|
|
I have to traverse object graphs from a text files that look similar to this simplified example:
ClassA.Method(ClassB.Method(),null,1.7F).Property
I am passed ClassA and ClassB as objects, so have all I need, but...
Without traversing recursively, I don't think I can easily use reflection and guarantee the right members are used. Am I correct in this assumption?
If so, should I consider a runtime compile and invocation of the code snippets instead?
Hope someone can help!
Thanks, MikeS
|
|
|
|
|
|
Thanks for that - I did look at C-Script, which is where the compile thoughts originated.
I guess I wanted feedback on the limitations/simplicity of reflection a text 'dot notaio'n path, compared to the flexibility of compiling the text as code (losing casting etc).
much as I'd love to play with compilation, I've decided to go with reflection and live with it's limitations. I'll keep my restricted syntax as 'valid' c# script/code so I can move to compilation.
The reasons are:
1. To acesss data from the object model in a stuctured way so XSLT can transform it.
2. To hide some complexity from users, so they define business data paths rather than code.
3. To keep the option of using a basic reflection UI to build the references.
4. To ensure reusable features are part of the object model, not in script files.
There is one part I'm thinking of making very un-like c# code for data output reasons: Iterate through collections and invoke the next member in the dot notation path on each item. Given this requirement, I'm investigating if I could use HQL in the file instead...
I'd appreciate any other comments!
Ta, MikeS
|
|
|
|
|
Hey, I'm trying to open notepad from my own application when i click a button.
I already posted this, but the answer i got had a few problems, and there were no other answers. Thanks for the help[^] Luc Pattyn;), but I didn't get it. Well, actually, I think it was my fault it didn't work. (as in i screwed up when modifying it to be used on button_click).
I'd figured I would need a reference, and it says I do ("the type or namespace 'Process' could not be found.( are you missing a using directive or an assembly reference?)") this error occured twice. Any help on correctly doing this or what reference I am missing would be greatly appreciated.
Thanks!
|
|
|
|
|
Hello again,
the Process class is defined in namespace System.Diagnostics
you can verify this in the MSDN help;
it shows "System.Diagnostics.Process" in the section on Inheritance Hierarchy
(at the top of the manual page when using Visual Studio 2003, at the bottom when VS 2005).
This means:
1) you must provide a using statement at the beginning of every source file that wants
to use the Process class, like so:
using System;
using System.Diagnostics;
2) you MAY have to add a reference; you dont if the Intellisense showed the right
stuff while you were typing the using statement (popup list at every period with
the required item in it).
If it does not show, then you must add a reference (right click your project's name
in the Solutions panel).
For System.Diagnostics it is automatic though.
Once you took care of these issues, the Process constructor, methods and other class
members should have full Intellisense support inside Visual Studio, and you are
ready to (iterate on) edit, build and run. Same holds true for every other class
you want to use (of course the most basic ones are always accessible, such as String).
Hope this helps you on the right track.
Luc Pattyn
|
|
|
|
|
OK. Now it doesn't have a problem with the Process being unidentified. But when i run the code the program has a problem with the proc.Start(); part of the code. This happens after i click the source button. It says "Win32Exception was unhandled" and then below that "Access is denied". Thanks for the help!
(And what is a Win32Exception?)
|
|
|
|
|
Hi,
Win32Exception is "The exception that is thrown for a Win32 error code...", see MSDN help
(e.g. inside Visual Studio).
It means something deep down went wrong, a HRESULT error code was generated and rather
than a regular Exception with speciifc meaning, a general Win32Exception was generated
(with a field containing the HRESULT value, in this case, since access violation,
is will end on hex 0005).
In general, it means you try to access something you are not entitled to.
One possible scenario is you want to open a file that is already open somewhere,
or you want to open a file you are not allowed to open at all (someone elses file,
a system file, ...).
I fail to see what the connection is with your Process.Start() stuff, either
it launches Notepad or it doesnt. Anything from there is Notepad's matter
(e.g. if file does not exist or cannot be read, it should tell you).
What makes you say the problem is with Process.Start() ? Did you catch an exception
and got a reference to that specific line ? or did you single-step the code just till
there ? or what.
If it is and you need more help, one would have to see the source code...
Luc Pattyn
|
|
|
|
|
ok. here is the source:
Process openSource = new Process();<br />
openSource.StartInfo.FileName = @"C:\WINDOWS\system32\notepad.exe";<br />
openSource.StartInfo.Arguments = webBrowsing.DocumentText;<br />
openSource.StartInfo.UseShellExecute = true;<br />
openSource.Start();
when i click the button a window pops up saying what i said about the Win32Exception and it hightlights the "openSource.Start();" part of the code.
thanks for the info and help.
|
|
|
|
|
OK, I suggest you make your program show the value and some content of
webBrowsing.DocumentText right before you create the new Process(),
something like:
string fileSpec=webBrowsing.DocumentText;
log("fileSpec="+fileSpec);
try {
using (StreamReader sr=File.OpenText(fileSpec)) {
for (int i=0; i<3; i++) {
string s=sr.ReadLine();
log(s);
}
}
} catch (Exception exc) {
log(exc.Message);
throw;
}
Process openSource=...
in the above replace log() by whatever function can show you a string;
this could be Console.WriteLine()
this will tell us:
- whether the file spec is a valid windows file spec
- whether the file exists
- whether it is really readable
Good luck !
Luc Pattyn
|
|
|
|
|
I'm coming up against cases where the order of events - or even whether events ever fire - depends on whether my app is running "in debugger" (ie, F5 in Visual Studio), or running in it's release version.
So, some of my code needs to be aware of which environment I'm in. Does .NET / VS offer a nice structured way of doing this, or do I need to start messing with process names, etc?
Thanks!
|
|
|
|
|
the #if DEBUG precompiler statement will tell you?
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Not quite, as far as I can tell, you get:
- no VSHOST when running under .NET 1.1
- no VSHOST when running under .NET 2.0 but outside Visual Studio 2005
- VSHOST when running under .NET 2.0 inside Visual Studio 2005, whether Debug or Release
So I would check the exe's fullname, available as the first string from
Environment.GetCommandLineArgs().
Luc Pattyn
|
|
|
|
|
Thanks, Luc. It seems sad that I have to do this. I thought the Project Properties, Build Page "Define DEBUG" checkbox would do the right thing, but apparently it does not...
|
|
|
|
|
Do I detect a little sarcasm, there?
Perhaps you could explain how to use it. It doesn't seem to get set automatically when under the VS host.
When I open the Project Properties dialog and click the "Define DEBUG" checkbox on the BUILD page, then DEBUG is defined as true for both RELEASE and when running under VS. But if I turn that checkbox off, then it's not defined in either.
A little help, perhaps?
|
|
|
|
|
I'm building application with multi document interface through use of standard tab control (so it's not MDI).
It's only for learning purpose anyway. I want to build kind of modern web browser so I use built in WebBrowser control.
Question is how to access certain controls in each tab through common interface on top of screen, basically to have same functionality like in FireFox when it comes to tabs (Commands apply only to selected tab and his controls, most of them anyway).
I had hard time (I'm still learning so this is probably trivial) to add controls to newly created tab. I figured I'll just add controls in same event but now I have problem once that is done how to access them since event repeat on each button click all controls have same name, only difference is they sit in different tab.
So how to access say WebBrowser Control in current tab... or do I need to do something difernet??
It's C# Express 2005 BTW...
|
|
|
|
|
TrooperIronMan wrote: So how to access say WebBrowser Control in current tab
MyTabControl.SelectedTab.Controls["MyControlName"].Text = "Blah Blah";
Same goes for any control in the currently selected tab. This is one way. Another is to make a custom TabPage with known controls collection, and instantiate this TabPage and add it to the TabControl each time the user opens a new Browsing tab.
Regards
|
|
|
|
|
OK 1st idea work nice with TextBox control, but it doesn't give me to use Navigate method of WebBrowser control at all.
I like second idea also, (sure it's better if it can be done in designer since I can set property much easier than in editor, but I would like some more help about practical realization.
Keep in mind I'm not very experienced with this, so sorry if some question look trivial
|
|
|
|
|
OK I figured out workaround for 1st method, for now (create new WebB. control then assign it control with right index)
But I still need explanation on other questions.
Thanks
|
|
|
|
|
If you need to access certain methods/properties of the control you can cast it:
((WebBrowser)MyTabControl.SelectedPage.Controls["MyControlName"]).Navigate("http://Google.com");
TrooperIronMan wrote: But I still need explanation on other questions.
What other question? Sorry if I missed them.
Regards
|
|
|
|
|
Question was how to instantiate some tab.
So I have one that is like template and I want all others to be copy "but with different data in their controls... so for example if there is WebBrowser each one will have different web page etc.
|
|
|
|
|
You'd have to create a UserControl project, inherit it from TabPage control, and put all the controls you'd want programatically. Sorry you can't use the designer to make that template TabPage.
Another way is to make the template TabPage as the first in the TabControl, but hidden. You can use this code snippet to copy your template page into a new one:
TabPage NewPage = new TabPage();
Control[] TempArray = new Control[MyTemplateTabPage.Controls.Count];
MyTemplateTabPage.Controls.CopyTo(TempArray, 0);
MyNewTabPage.Controls.AddRange(TempArray);
((WebBrowser)MyNewTabPage.Controls["MyBrowser"]).Navigate(SomeUrl);
I hope this helps.
Regards
|
|
|
|