|
Maybe you should use IlDecompiler and look at the IL generated from some of your nice 'fall through' c# code. I think you'll find it is liberally sprinkled with goto's. The closer you get to the machine, the more useful and sensible goto gets to be.
what is gosub other than a void method call? is goto really any different than
if(true)<br />
...<br />
else<br />
...
I would agree that if-else is preferable for clatity: the brace blocks are clearer than a lable, but the result is no different: code branches to a new location under some conditions.
In leppies example, if there were multiple try-catch blocks in the same function, a goto and a common cleanup code block would be preferable for maintainability to repeating the code in each catch block...
Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed.
Carl Sandburg
|
|
|
|
|
I was commenting on the code example provided. In the example, if an error is generated after the RESTART label, the code will loop indefinitely. That, to me, was a perfect example of why not to use the goto. It leads to bad code.
I'm not disputing whether IL contains goto calls. I am contending that at the time the IL is compiled, there are no nonsensical looping calls made if the developer has constrained him/herself to using the fall-through code style.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
turbochimp wrote:
This kind of coding reflects poor planning, not good practice.
I beg to differ. Show me more readable code, sure you wrap a while around it, or some other way. The fact is goto is clean and simple, and it gives you much better flow control that you can perform via a for/while/etc.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
Until you find a sub with about 20-30 of them in it, then it's just damn ugly and completely unreadable.
Much better flow control? I'd say much more "quick and dirty" flow control. Seriously, I haven't used a single Goto in the last 13 years...
Sure, if you get down to the IL that the compiler generates, yes, you'll find Goto's, or more acurately, Jump's, all over the place. This will happen in lower level languages, but in higher level languages, C# or VB.NET or whatever, using Goto's is an extinct practice, found only in the code of 1st year students.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am inclined to agree with you, since I can't recall needing to use a Goto in a very long time (other than in VB6 of course, where it is mandated by the crude error handling). Goto is rather the flow control of last resort, and will stay around in even high level languages for that last ditch "damn, now what?" situation that once in a very rare while crops up in even the best designed code...
Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed.
Carl Sandburg
|
|
|
|
|
Um...okay...
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi All,
i have got a problem by getting data from an oracle column. The column contains 250 binary values in a single column ( VARCHAR2(250) )!
Each tries to get the byte to a byte array or into a string where not successful!
Just with object I could read something, just one letter and at least its wrong I think.
Thats my Source Code, ...
public static void Main(string[] args)
{
string constr = "Provider=msdaora; Data Source=***; USER ID=***; Password=***";
OleDbConnection myConnection = new OleDbConnection(constr);
string qry = "SELECT * FROM ruest_teach WHERE RT_RK_MODELL_NR= 'W202 M753 13' AND RT_RK_ORGE_NR = 591";
OleDbCommand myCommand = new OleDbCommand(qry,myConnection);
myConnection.Open();
//*** SELECT Operation ausführen lassen
OleDbDataReader myReader = myCommand.ExecuteReader();
string b = "";
int a = 0;
object c = new object();
while (myReader.Read())
{
a = Convert.ToInt32(myReader.GetDouble(0));
b = myReader.GetString(1);
c = myReader.GetOrdinal("RT_TEACH_H");
}
Console.WriteLine(a + " , " + b + " , |" + c + "|");
}
Maybe someone here can help me with my problem. It is really important, because it is part of my examination to get a programmers license in germany.
regards,
eXi
|
|
|
|
|
Hi all,
I try to using c# and programming the CEMAPI(by using VC++) in pocket pc 2003 to retrieve
the emails from the pocket pc. But after several days trials, I still
can't get the receipent and the body of the emails(I can only retrieve
the subject of the emails). Do anyone have the same experience as me ? I
just wonder there are system bugs in the pocket pc MAPI.
Thanks
|
|
|
|
|
I want to get the path to the executable file of a service
(from another app) via the servicecontroller class.
This will enable me to find the config file of the service
and modify this from another app.
How do I do that?
|
|
|
|
|
Hai ,
Iam having following fields.
name
exp
dob
primary
sec skills
ph
email
passport
location
i wnt these things to be added to my db
i wnt add btn , del btn , update btn
sql server , c#
KINDLY SEND ME
chand
|
|
|
|
|
Yikes.
Try googling for "SQL", "ADO", "ODBC". In that order.
And stop shouting.
Cheers
Sid
|
|
|
|
|
|
I totally missed the fact that he might actually mean the "MS SQLServer"
I thought he was referring to "a SQL Server" (in general)
Cheers
Sid
|
|
|
|
|
You have been posting this (and similar) questions every few hours for the past few days, you have not recieved any meaningful replies - does this not tell you anything?
Here, let me give you some pointers.
1) It is understood that English may not be your first language, but if you understand it well enough to abbreviate almost every word then surely you can make an attempt to write the word in full. Dont worry about the odd spelling mistake as Im sure most people can work around them - but having to decipher txt-spk is just a pain in the butt.
2) Asking for fully written code just is not going happen, you must attempt these things yourself using articles/books/documentation, and when you hit a specific proplem then come and ask about that problem. Dont expect somebody to do this for you for free.
3) Please do not ask for answers to be mailed directly to you, this board and every other technical forum, is there for everybody to learn from.
|
|
|
|
|
Hi,
You can connect to the database and do all these operations using Connection, Command, DataReader, DataAdapter classes.
SqlConnection conn = new SqlConnection();
conn. ConnectionString = ""; //Set the connection parameters
SqlCommand cmd = new SqlCommand("");//pass SQl query
conn.Open(); // Open the connection
cmd.Connection = conn;
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);//execute the command
Read MSDN for more help.
Thanks
SGS
|
|
|
|
|
hi
How i can get a size of RAM and a speed of prossesor by C++ (borland) ?
|
|
|
|
|
|
Hi Guys,
I get the handle of my "windows service" by using
<br />
System.Diagnostics.Process proc = Process.GetCurrentProcess();<br />
log.WriteEntry(proc.Handle);<br />
I install a WH_CALLWNDPROC hook to capture any windows messages that my "windows service" might receive.
If use Sendmessage(proc.Handle,0x0308,IntPtr.Zero,IntPtr.Zero); to send a message to my service, the hook doesn't pick it up.
Does anyone know why this wouldn't work ????
|
|
|
|
|
Hi!.
SendMessage is sending messages to windows using their window handle.
You're fetching the process handle of your process.
These are two completely different things.
A process doesn't have to have one or more windows associated with it, so you can't just exchange different handles.
Regards,
mav
|
|
|
|
|
Thanks for the info.
So is there any way that i can send a windows message to a windows service.
|
|
|
|
|
Only if your service creates a window that windows messages can be sent to.
Usually a service isn't allowed to perform desktop operations, so creating a window from a service for communication isn't usually the best way.
I think you should consider a different way of IPC, depending on what you want to do.
Regards,
mav
|
|
|
|
|
The right solution for your problem will be some IPC(Inter Process Communication) methods. Preferably you could try Named Pipes. Try CreatePipe and stuff like that.
James
|
|
|
|
|
Hi,
I posted a thread yesterday about creating and printing documents with a template and text out of the database.
I was able to import an Office Object and to work with it. Setting the contents and I automatically get a 'save to' box.
Now I'm trying to use the open and printout function and here comes the problem: the required parameters are all of type ref object . When I create those objects and execute the function I get a 'Type Mismatch' error. Probably because the function tries to cast the objects to a certain type.
Does anyone know what the types are the function needs? Which parameters can be null? I found an example on MSDN, but, off course, this was VB and the function didn't have half as much parameters.
Here a sample of my code. (note, I don't know anything about automation and the object model, so I'm totally fishing here)
I need this for a demo, so nothing fancy is needed:
Get the data out of the database and print it (according to the correct template and with a number of copies).
<br />
foreach(DataRow row in ds.Tables[0].Rows){<br />
while(File.Exists(path + "file" + index + ".rtf")){<br />
index++;<br />
}
object ob1 = row["templatename"], ob2 = 0, ob3 = 0;<br />
object ob4 = 0, ob5 = "", ob6 = "";<br />
object ob7 = 0, ob8 = 0, ob9 = 0;<br />
object ob10 = "", ob11 = "", ob12 = 1;<br />
object ob13 = 0, ob14 = 0, ob15 = 0;<br />
object ob16 = 0;<br />
try{<br />
doc.Application.Documents.Open(ref ob1, ref ob2, ref ob3, ref ob4, ref ob5, ref ob6, ref ob7, ref ob8, ref ob9, ref ob10, ref ob11, ref ob12, ref ob13, ref ob14, ref ob15, ref ob16);<br />
}<br />
catch(Exception ex1){<br />
MessageBox.Show("Open error:\n\n" + ex1);<br />
}<br />
doc.Content.Text = row["contents"] + "";<br />
doc.Save();<br />
index++;<br />
}
object o1 = 0, o2 = 0, o3 = 0;<br />
object o4 = "", o5 = 1, o6 = 1;<br />
object o7 = 0, o8 = --index, o9 = 1;<br />
object o10 = 1, o11 = 0, o12 = 0;<br />
object o13 = 0, o14 = 0, o15 = 0;<br />
object o16 = 0, o17 = 0, o18 = 0;<br />
try{<br />
doc.PrintOut( ref o1, ref o2, ref o3, ref o4, ref o5, ref o6, ref o7, ref o8, ref o9, ref o10, ref o11, ref o12, ref o13, ref o14, ref o15, ref o16, ref o17, ref o18);<br />
}<br />
catch(Exception ex2){<br />
MessageBox.Show("PrintOut error:\n\n" + ex2);<br />
}<br />
<br />
object obj1 = false;<br />
object obj2 = null;<br />
object obj3 = null;<br />
doc.Application.Quit(ref obj1, ref obj2, ref obj3);<br />
I hope somebody can help me.
tnx.
(PS: somebody pointed me out to Crystal Reports, but I don't know that either )
No hurries, no worries.
|
|
|
|
|
I came across this article http://www.codeproject.com/csharp/ShellID3TagReader.asp[^] and so I tried doing exactly as shown but it's not working. When the folder.GetDetailsOf function returns it's blank but I know for a fact that there this mp3 has an ID3 tag. Furthermore when I add the extra columns in Windows Explorer to see the mp3 info it doesn't display anything. Can my Shell32 be broken somehow? Here's the code I have (even though it's the same in the article):
MP3File mp3File = new MP3File();<br />
string fileName = FilePath.Substring(FilePath.LastIndexOf("\\") + 1);<br />
string filePath = FilePath.Substring(0, FilePath.LastIndexOf("\\"));<br />
<br />
Shell32.Shell shell = new Shell32.ShellClass();<br />
Shell32.Folder folder = shell.NameSpace(filePath);<br />
Shell32.FolderItem folderItem = folder.ParseName(fileName);<br />
<br />
if(folderItem != null)<br />
{<br />
mp3File.FileName = fileName;<br />
mp3File.AlbumName = folder.GetDetailsOf(folderItem, 17);<br />
mp3File.ArtistName = folder.GetDetailsOf(folderItem, 16);<br />
mp3File.SongTitle = folder.GetDetailsOf(folderItem, 10);<br />
mp3File.TrackNumber = folder.GetDetailsOf(folderItem, 19);<br />
}<br />
<br />
folderItem = null;<br />
folder = null;<br />
shell = null;<br />
<br />
return mp3File;
I'm using XPpro SP2.
Please Help,
Rob Tomson
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
Can somebody comment this code? ı got this from somewhere but İ couldnt understand why used (-1)?Whats the trick??
<br />
<br />
if (Int32.Parse(myDataSet.Tables[0].Rows[Int32.Parse(((TextBox)myItem.FindControl("textCriteriaNumber")).Text) - 1]["CRITERIA_VALUE"].ToString())==1)<br />
<br />
((CheckBox)myItem.FindControl("cbCriteriaValue1")).Checked = true;<br />
<br />
|
|
|
|
|