|
KKW_acd wrote: righthand side of the line
You are correct. As the message says, you cannot initialize a field when it is first declared in a struct, all fields assume the default value for the type which in the case of an array is null. Initialization must be done in a constructor (however you cannot have a parameterless constructor for a struct either).
When to use a struct or a class can be complicated sometimes. I think your dtlst (horrible name by the way - why not DataList ?) should most likely be a class. You will then be able to initialize the field as you wish.
Also, public fields are normally bad practice, make them private and use a property (getter only unless a setter is needed) to expose the field.
Edit: There's still a few things about this that don't feel right, but to fit your code and usage, this is a quick example of something that works. This is not meant to be doing your homework for you, but rather to point you in the correct direction and give you something to compare your code too:
public struct Item
{
private string name;
private int index;
public Item(string name, int index)
{
this.name = name;
this.index = index;
}
public string Name { get { return name; } }
public int Index { get { return index; } }
}
public class DataList
{
private Item[] items = new Item[128];
public Item[] Items { get { return items; } }
}
DataList[] dataLists = new DataList[128];
int listIndex = 0;
int itemIndex = 0;
string itemText = "Random text";
string indexText = "1";
dataLists[listIndex] = new DataList();
dataLists[listIndex].Items[itemIndex] = new Item(itemText, int.Parse(indexText));
modified 15-Nov-12 13:19pm.
|
|
|
|
|
Dave,
Thankyou!
That is exactly what I needed!
Also, I'm flattered that you think this is homework! I wish I was as young. I'm an old bit-twiddler from the DOS and Microprocessor days. I even remember watching man's first step on the moon on an Admiral B&W tv! - Live!
Thanks again!
|
|
|
|
|
No problem.
KKW_acd wrote: I wish I was as young
Ah, sorry!
KKW_acd wrote: old bit-twiddler from the DOS and Microprocessor days
Then, once you get used to C# you will find this a lot of fun, and in many ways, a lot easier. Gone are the days where variables and function names need to be short and cryptic, we can be alot more verbose now e.g. A date and time combined is a DateTime not dtm . We have a powerful framework that has the vast majority of the dirty/hard work done for us. Allocating and freeing memory is taken care of (in most situations), threading, callbacks etc are a breeze compared to the old days. Many, many other things too.
It still of course requires the same skills and dedication/perseverance but the curve is somewhat shallower.
|
|
|
|
|
KKW_acd wrote: I even remember watching man's first step on the moon on an Admiral B&W tv! - Live! Me too, although a different TV model.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
In your dtlst structure you cannot initialise the instance variable ItemArray automatically, as struct s do not have default (parameterless) constructors. You would need to initialize the variable after you have created the struct (s), i.e after you create the DataList array.
It is explained more clearly here[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
The immediate error is what's in the message.
However, I suspect you didn't mean to create a struct here. A struct in C# is a value type, so wherever it is passed to a method, a copy is taken, and the initial version is not modifiable. However, the array within the struct will be modifiable and the array in the outside version of the struct will be updated! A struct containing references to reference types, like an array, is usually not what you meant to do.
I think you are trying to recreate the C++
typedef struct {
string FieldName;
int FieldIndex;
} ItmAray;
typedef struct {
ItmAray[128] ItemArray;
} DtLst;
DtLst[128] DataList;
But the arrays there are references: DtLst[100] is a reference to a DtLst, and passing it to a function will pass it by reference. In C# I think you want a class.
Also, fixed length arrays are generally not what you want in the modern world. I think what you actually want is
class Field {
string Name;
int Index;
}
class DataListItem {
List<Field> Fields;
}
List<DataListItem> DataList;
|
|
|
|
|
i want to automate a c# application with windchill can anyone guide me from where i should start??
|
|
|
|
|
"windchill" is a calculation so there is no automation for it.
On the other hand if you want to collect weather conditions from a weather station and persist those values and/or display them then that might fit the automation part. If so then you need to do the following
- Research how weather stations intereface (not a C# term) with computers.
- Decide which interfaces you want to implement.
- Investigage how the protocol of the select interfaces are used in C#. This would probably be TCP/IP and/or USB.
- Put the above together to write your application.
If that doesn't describe what you want then you will need to re-phrase your question.
|
|
|
|
|
i am sorry for the confusion actually Windchill PDMLink – A web-based master product data management repository that also helps teams manage critical processes such as change/configuration management, and detailed design. its a software application so i want an automation with it..
|
|
|
|
|
Still isn't clear.
Does that product offer an automation feature that you want to access?
Or do you want use the features of the system in some way via your application?
If the second then
1. Investigate the API(s) that the product exposes
2. Define exactly what it is that you want to do with that product (this is not code.)
3. Write a message layer that interacts with the API (from 1) in such a way that is provides sufficient functionality for 2 but does not necessarily implement 2.
4. Write a functional layer using 3 that implements the functionality defined in 2 via 3.
The distinction between 3 and 4 can be somewhat fuzzy even to the extent that it makes more sense for 3/4 to be one layer. However that depends on 2.
|
|
|
|
|
jschell
yes i want to do the second option and i am searching for API(s) and the purpose of this thread was just to get idea from someone who worked on it so he or she can guide me about API(s) and other features and loop holes.
anyhow thank you so much for replying if is there anyone you know who has some experience about windchill send kindly refer me
|
|
|
|
|
I setup a form (subform) inside another form (mainform)at runtime. While some methods are being executed, the data in this subform also gets updated. However, I can not do anything else in the mainform. I have also tried setting the subform up as a control but I have the same problem. Is there a way I can access the mainform while the subform is updating.
Any help will be greatly appreciated,
Thanks in advance,
Michael
|
|
|
|
|
I presume the process going on in the subform is reading from the database or some other long running process. This long running process needs to be separated onto another thread (backgroundworker thread is a good place to start.) This allow the UI on the main thread to respond.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
To add to Mycroft's answer, all long running operations should be done on a separate thread to the UI. The problem with that is you cannot update the UI from a different thread.
The BackgroundWorker[^] component is a perfect fit for this situation as it's ProgressChanged and RunWorkerCompleted events will be raised on your UI thread so that problem is solved, and the DoWork event is raised on the worker thread so you don't have to get involved any more than that.
If you need to pass data around then the various methods/event arguments have an object you can use, alternatively I made a generic version which you can find here[^].
|
|
|
|
|
I cannot work out how to get an integer value from a textbox from inside a datalist for a variable to insert into SQL.
Here is my code.
<pre lang="c#">int qty = int.parse(dlProducts.Controls[0].FindControl("txtProductQty"));</pre>
and this variable will be put into an insert Query.
into a textbox inside a datalist id="dlProducts"
<pre lang="HTML"><pre lang="HTML"></pre><asp:TextBox ID="txtPeight="22px" Width="15px"></asp:TextBox></pre>
-- modified 14-Nov-12 16:21pm.
|
|
|
|
|
Hi,
I can't understand what your trying to do?.
but this is what i think you r trying to do.. u have a datalist control who has a child control which has a value and u need to retrieve it.
you r going fine except that your trying to send an asp.net textbox control to be parsed as int..
TextBox t=(TextBox)dlProducts.Controls[0].FindControl('txtexamp1');
[Explicit casting required]
int qty=int.parse(t.Text);
u will have the value which u can input in Sql.
I hope this answer helps u.
<div class="signature">rajeshkasani05</div>
|
|
|
|
|
using int qty=int.parse(t.Text); produces a formatException.
|
|
|
|
|
hi,
The format Exception may be thrown because you are not receiving any value or the string from the t.Text may be "" (empty string).please try to debug and check the issue or place your code snippet and let me check it.
Regards,
rajeshkasani05
|
|
|
|
|
My code is in the first message. The user will only be entering integers not string into the text box.
|
|
|
|
|
Do not use Int32.Parse() when you do not know the contents of the input. Use the Int32.TryParse() Method[^], or put the parsing code within a try/catch block. You should also use your debugger to check the value that the code is actually trying to interpret; don't assume it's the value that you think is there.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I am getting an error in a C# 2008 application since I am trying to add the NLog open source tool to 2 different solution files.
I am completing the following task:
1. I add a reference to this dll in the references section of each proejct file.
2. I then place a 'using NLog' statment in each solution file.
No matter what I do, I can not remove 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
Can you show me code and/or tell me how to fix this problem?I am getting the following warning and error message for a C# 2008 application I am working on:
Warning 17 The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
using definition from 'c:\Program Files (x86)\NLog\.NET Framework 2.0\NLog.dll' sample
Error 21 The type or namespace name 'Nlog' could not be found (are you missing a using directive or an assembly reference?) C:\Sample.cs 15 7 sample
|
|
|
|
|
Problem description isn't clear.
VS Studio 2008 (not C#) open a solution (one solution) which then has multiple projects.
In there you add a dll a a reference.
Then when you compile the solution you get that error.
Presumably that is what you mean.
If so I suspect that something is wrong with the compile options for the project. You can examine that in the properties of the project. You might start by looking at the targeted version of .Net that each project is using.
|
|
|
|
|
Okay, so we've identified that you and the poster below are the same person. Stop this now. Post as one person, and one person only.
[Edit]The proof is in the wording - from the post below:
"I am getting the following warning and error message for a C# 2008 application I am working on:
Warning 17 The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
using definition from 'c:\Program Files (x86)\NLog\.NET Framework 2.0\NLog.dll' sample
Error 21 The type or namespace name 'Nlog' could not be found (are you missing a using directive or an assembly reference?) C:\Sample.cs 15 7 samplef
I am getting this error message since I am trying to add the NLog open source tool to the solution file for 3 different project files in this solution.
I am completing the following task:
1. I add a reference to this dll in the references section of each proejct file.
2. I then place a 'using NLog' statment in each proejct file.
Can you show me code and/or tell me how to fix this problem?"
From this post:
"I am getting an error in a C# 2008 application since I am trying to add the NLog open source tool to 2 different solution files.
I am completing the following task:
1. I add a reference to this dll in the references section of each proejct file.
2. I then place a 'using NLog' statment in each solution file.
No matter what I do, I can not remove 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
Can you show me code and/or tell me how to fix this problem?I am getting the following warning and error message for a C# 2008 application I am working on:
Warning 17 The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias;
using definition from 'c:\Program Files (x86)\NLog\.NET Framework 2.0\NLog.dll' sample
Error 21 The type or namespace name 'Nlog' could not be found (are you missing a using directive or an assembly reference?) C:\Sample.cs 15 7 sample"
modified 14-Nov-12 17:11pm.
|
|
|
|
|
Hadn't spotted that second post yet, but reading this one I thought of another post/user(?)...
Error 19[^]
Maybe we are dealing with 'unique' users and NLog really has a problem
|
|
|
|
|
Good catch - and rachel_m has displayed a tendency to being the same user as sc steinhayse as well. Linq[^] and Linq[^].
|
|
|
|