|
How about doing a search on the internet for this information?
You could check out msdn for tutorials / quickstarts.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi,
i'm not sure how to describe my self (not sure what is the name of this issue)
i can write to console like this
Console.WriteLine("The answer of {0} + {1} is {2}",2,2,2+2);
how exactly this topic (of {0}... and the arguments) is called ?
any way, i was wondering if i can write something like this.
Dictionary <string,int> dic = new ...
string [] arr = {"hello","world"};
foreach (var str in arr)
{
dic.Add({0},str, str.Length);
}
I know that it's not the correct syntax, but i hope i was understandable enough... 
|
|
|
|
|
Uh, no, I have no idea what you want, but would String.Format help?
|
|
|
|
|
The method has to support Composite Formatting[^] to use that syntax.
You can build the string first, perhaps using StringBuilder, String.Format(), string operators, etc., before adding it to the dictionary.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If you want to write a function that accepts variable number of arguments like WriteLine does, you have to uses the params modifier.
http://msdn.microsoft.com/en-us/library/w5zay9db(v=VS.100).aspx[^]
In the format string {#} where # is a number refer to the the argument at that position starting at index 0 with the first argument after the format string.
Philippe Mori
|
|
|
|
|
Your sample doesn't really make any sense.
Why don't you just do it this way:
for (int i = 0; i < arr.Length; i++)
{
dic.Add(arr[i], arr.length);
}
One of the Console.WriteLine method overloads acts just like string.Format . You pass a format string, followed by an array of objects. The number inside the curly braces indicates the index into the specified object array. Just like all other arrays, this one is 0 based, and you can't specify a value < 0 or > the number of elements in the array (minus 1). You can specify the same array index over and over again:
WriteLine("{0}{0}{0}", "x", "y");
which would result in "xxx" being written
or even out of order:
WriteLine("{2}{1}{0}", "x", "y", "z");
which would result in "zyx" being written.
You can have more objects to format, but your indexes in the format string can never exceed the number of objects in the array.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
String.Format() does the trick, Console.WriteLine() internally uses String.Format() .
|
|
|
|
|
I'm unable to get ms access afterupdate event like functionality in c# textbox.
What I have done so far is:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyData.Equals(Keys.Enter))<br />
MoveToSpecificVocNo();<br />
}<br />
and Leave event
<br />
private void VocNoTextBox_Leave(object sender, EventArgs e)<br />
{<br />
MoveToSpecificVocNo();<br />
}<br />
But the problem is If I press enter and press tab to move to next field. The event is called twice. One for Enter key, another for Leave.
Is there any solution?
Regards
Asif Rehman
|
|
|
|
|
One way would be using a flag to indicate it had been run already.
At the form level:
private bool func_called = false;
In KeyDown you set it to true after calling the function:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData.Equals(Keys.Enter))
{
MoveToSpecificVocNo();
func_called = true;
}
}
And in Leave you reset it (if this is appropriate for what it does):
private void VocNoTextBox_Leave(object sender, EventArgs e)
{
if ( !func_called )
{
MoveToSpecificVocNo();
}
func_called = false;
}
Jack of all trades ~ Master of none.
|
|
|
|
|
Possibly a better way (depends on what MoveToSpecificVocNo() does) is to implement the SendKeys class:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData.Equals(Keys.Enter))
{
SendKeys.Send ( "\t" );
}
}
This will cause the focus to jump and trigger the Leave event.
Jack of all trades ~ Master of none.
|
|
|
|
|
Hi
This is a question in File Type forensic identification - how can I verify, via C#, an Excel file really is an Excel file, a Word file is word, a 7z/zip is genuinely a zip file, a csv is what it claims to be?
Thanks
dev
|
|
|
|
|
For each type of file, the validation would be different. Thus it cannot be done in a generic way.
Many file types do have a signature that could be checked (http://www.garykessler.net/library/file_sigs.html[^]).
Also so file format are based on other file format like an xlsx file is based on a zip file with some specific content.
Also for some file type some statistics could be used... or some patterns could be found in the file.
Generally, you won't really validate a file... You will try to open it using appropriate library and assumes the file is good if it can be opened and used.
Some file might also have a checksum to validate it or might contain information related to its length. A wave file for example would have the number of sample (or something like that) in it header. That information with other information like the number of channel and the bit depth would allows to validate that the length of the file match (maybe rounded up a bit) with that value.
Philippe Mori
|
|
|
|
|
Yeah, just open it in the appropriate app and let it tell you, it's the expert.
It's really not worth trying to guess.
|
|
|
|
|
Hi. I have a problem which i am stuck in badly.
Scenario:
I have a abstract class named "VisaOscilloscope" defining some abstract methods and properties, which some driver utility classes inherit and implement the actual external hardware driver functionality.e.g. i am giving a shorter version of the class below.
public abstract class VisaOscilloscope : Oscilloscope
{
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the location of the center of the range that the Vertical Range attribute specifies. The value is with respect to ground and is in volts")]
public abstract double VerticalOffset { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the absolute value of the full-scale input range for a channel. The units are volts")]
public abstract double VerticalRange { get; set; }
[Category("IviScopeProbeAutoSense Extension Group")]
[DefaultValueAttribute(false)]
[DescriptionAttribute("If this attribute is True, the driver configures the oscilloscope to sense the attenuation of the probe automatically. If this attribute is False, the driver disables the automatic probe sense and configures the oscilloscope to use the value of the Probe Attenuation attribute")]
public abstract bool ProbeAttenuationAuto { get; set; }
public abstract void init();
public abstract void activate();
public abstract void acquire();
public abstract float[] collect();
public abstract void close();
Now a utility class that has to inherit from this base class and implement the properties and methods by connecting to a pre-written driver. e.g.
class TK_TDS1012B : VisaOscilloscope
{
public override double VerticalOffset
{
get
{
return myTk.GetDouble(tktds1k2kProperties.VerticalOffset);
}
set
{
throw new NotImplementedException();
}
}
public override double VerticalRange
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override bool ProbeAttenuationAuto
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public override void init()
{
throw new NotImplementedException();
}
public override void activate()
{
throw new NotImplementedException();
}
public override void acquire()
{
throw new NotImplementedException();
}
public override float[] collect()
{
throw new NotImplementedException();
}
public override void close()
{
throw new NotImplementedException();
}
}
So the problem is i want to group some properties into a list as they can duplicated. e.g. Oscilloscope have some base properties valid for all channels like waveform acquisition, but some are specific to each channel and there can be many number of channels. like each channel has vertical range, attenuation etc.
So what i want is list of abstract properties in the base class which can be implemented in the inherited classes. I can only access the driver in the inherited classes as there are many different drivers to connect to and all are of visa type.
So what i can't figure out is how to add a list of properties to the base class of which everything is to be implemented and populated in the inherited classes.
Any help please I would be really thankful.
|
|
|
|
|
You need one abstration for an oscilloscope and another one for a channel. Then an oscilloscope would have an array (or a List<>, a Dictionary<>) of channels as one of its property.
Philippe Mori
|
|
|
|
|
 hi, thanks for the reply...
The problem is i need to implement the properties related to the channels in the inherited utility class.
e.g. if i try your approach... which i already did...
i made another abstract class and moved all the channel related properties to that class. e.g.
public abstract class Channel
{
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(false)]
[DescriptionAttribute("If set to True, the oscilloscope acquires a waveform for the channel. If set to False, the oscilloscope does not acquire a waveform for the channel")]
public abstract bool ChannelEnabled { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(false)]
[DescriptionAttribute("Specifies whether channel is inverted or not")]
public abstract bool ChannelInverted { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Returns the physical repeated capability identifier defined by the specific driver for the channel that corresponds to the one-based index that the user specifies. If the driver defines a qualified channel name, this property returns the qualified name")]
public abstract double ChannelName { get; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the input impedance for the channel in Ohms. Common values are 50.0, 75.0, and 1,000,000.0")]
public abstract double InputImpedance { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the maximum frequency for the input signal you want the instrument to accommodate without attenuating it by more than 3dB")]
public abstract double MaximumInputFrequency { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the scaling factor by which the probe the end-user attaches to the channel attenuates the input. For example, for a 10:1 probe, the end-user sets this attribute to 10.0")]
public abstract double ProbeAttenuation { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies how the oscilloscope couples the input signal for the channel")]
public abstract VerticalCoupling VerticalCoupling { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the location of the center of the range that the Vertical Range attribute specifies. The value is with respect to ground and is in volts")]
public abstract double VerticalOffset { get; set; }
[Category("IviScopeBase Capability Group")]
[DefaultValueAttribute(0)]
[DescriptionAttribute("Specifies the absolute value of the full-scale input range for a channel. The units are volts")]
public abstract double VerticalRange { get; set; }
[Category("IviScopeProbeAutoSense Extension Group")]
[DefaultValueAttribute(false)]
[DescriptionAttribute("If this attribute is True, the driver configures the oscilloscope to sense the attenuation of the probe automatically. If this attribute is False, the driver disables the automatic probe sense and configures the oscilloscope to use the value of the Probe Attenuation attribute")]
public abstract bool ProbeAttenuationAuto { get; set; }
}
Then i added an abstract list of channels to the VisaOscilloscope class as mentioned before.e.g.
public abstract List<Channel> Channels { get; set; }
Then i implemented the list in the utility class inheriting from "VisaOscilloscope" like this:
public override List<Channel> Channels
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
Can you please clarify as i declared all the properties in channel class abstract as well they need to be implemented as well. So where they are implemented. if i compile the above code i get no compilation errors.
What my other classes outside this hierarchy intend to do is:
VisaOscilloscope myScope = new VisaOscilloscope();
myScope.channels[0].Enabled = true;
How do i implement the properties of the channel object, as i have implemented base abstract properties in Visaoscilloscope in the utility classes inheriting from visaOscilloscope.
Will be really thankful if u can answer this.
Thanks for the help so far...
|
|
|
|
|
Well the concrete channel class might have a reference to the containing scope if this is usefll for the implementation of the properties. This might be the case if the concrete oscilloscope class has functions like EnableChannel(int channelId, bool enabled).
One way would be that each oscilloscope fill its channel list with appropriate channels.
void InitChannels()
{
List<Channel> newChannels = new List<Channels>
int channelId = 1;
newChannels.Add(new AnalogChannel(this, channelId));
++channelId;
newChannels.Add(new AnalogChannel(this, channelId));
int digitalChannels = 16;
for (int i = 0; i != digitalChannels; ++i)
{
++channelId;
newChannels.Add(new DigitalChannel(this, channelId);
}
++channelId;
newChannels.Add(new ClockChannel(this, channelId);
++channelId;
newChannels.Add(new TriggerChannel(this, channelId);
Channels = newChannels;
}
Philippe Mori
|
|
|
|
|
Yes you are right again...
What i have done till now is initialize the channel list in the utility class inheriting from visaoscilloscope. While implementing the 'init' method i populate the list with channels and their respective properties by connecting to the respective oscilloscope driver and getting real-time value of that property for that particular channel and correspondingly update the list.
This only happens once i call the init method the first time. The problem which i am trying to figure out is they way i have implemented the base oscilloscope properties is that they are connected to the driver itself in the gettter setters, so they give me the current realtime value of the oscilloscope attribute when they are called from let say my GUI class. e.g.
if i ask a visaoscilloscope for its ID. which is a general property has to be implemented by each oscilloscope. So i do from my gui class.
assume this scope object points to a particular utility/driver/scope
visaoscilloscope myscope = new visaoscilloscope();
string ID = myscope.ID;
the id field which is abstract in visaoscilloscope is implemented in the inherited utility class (because there are different ways of getting an ID for each driver and i have to connect a driver class to it also)
so in the ID implementation, i just do this.
public override string ID
{
get { return myTk.GetString(tktds1k2kProperties.IdQueryResponse); }
}
Therefore it always gives me real-time response from oscilloscope. What i want is also realtime response for my channel properties. if i implement the current scenario u suggested the fields are only updated once i call the init method. which have to be called only once during the initialization phase.
If you understood my point i would be really thankful to hear a solution... if u want i can send u the classes... i know it is a simple enough problem. but this is something i have never tried and i am particularly new to this...
Really thankful for the help u have given my thus far...
|
|
|
|
|
For each property you might decided where it is best to have the actual implementation.
I'm not sure how your data get updated and how it used.
You can uses events if you need to know when data is changed. In pratice, it might be simpler to detect changes at the oscilloscope level as you would need to connect to a single event that would contain information on the change. Thus it might be simpler if the actual implementation is in the scope (except if channel are mainly used independtly --- that is one view per channel --- in that case, events could be on each channel). It is possible to have both also.
Assuming that a TkChannel can be used only with a TkOscilloscope, they can easily share information or talk together either though functions or events.
Philippe Mori
|
|
|
|
|
I think so its better if i give u the class implementations. a quick look will clarify u everything...
What i intend to do in a bigger picture is implement a experiment which uses two kinds of hardware an oscilloscope and an encryption board. i intend to measure power waves from the fpga board when an encryption is being done, collect its waveform and store it some where. this single step is called collecting a trace. i intend to do it almost a million times in a fast manner. and record a million waveforms acquired from oscilloscope somewhere.
The have made wrappers for the original oscilloscope driver written in c++ so they are compatible with c#. the drivers are all written, they specify to IVI standard and all the methods are implemented in a form of a class.
The class hierarchy i intend to implement for the experiment is:
IOscilloscope <---- Oscilloscope <----- Visa Oscilloscope <------ (TkTDS1012B , DSO1024)
The last classes e.g. tktds1012B connects to a driver class (e.g. tk1k2kDriver and connects to required methods it requires to get data from oscilloscope.
I am providing the links to these classes:
http://www.mediafire.com/?p3hzzcn2o45qucv
Kindly if u have some time, then have a look at it...
I just want a way to implement the properties for channel class they way i implement visaoscilloscope properties in inherited classes...
Thank you for your help thus far...
|
|
|
|
|
I haven't look at your code. I don't even think I have a program to open RAR file...
Typically, I would think that you would also have:
IChannel <----- Channel <---- VisaChannel <---- ....
If the creation of the channel is done by the concrete oscilloscope, you can provide the concrete oscilloscope to the channel and from there you can do whatever you want. Handle it there, handle in parent channel class or handle it in the oscilloscope class (ideally through IOscilloscope but if you need you can also uses concrete oscilloscope classes).
The exact implementation depedds a lot on how much the implementation of channels are similar between oscilloscopes and also how existing code is implemented. Assuming that there is one driver class object for one oscilloscope that give access to channel and scope functions, then it would probably make sense that each concrete channel class would simple call the appropriate function in the corresponding scope.
Assuming that your channel do have an ID, you might have an interface IOscilloscopeForChannels that would be implemented by the oscilloscope for use by channels.
interface IOscilloscopeForChannels
{
bool IsChannelEnabled(string channelId);
}
Then a property from the channel simply call that method in the oscilloscope providing any passed argument and adding its owns ID.
You would then be able to use a channel like this:
var oscilloscope1 = GetTheOscilloscope();
var channel3 = oscilloscope1.Channels["ch3"];
channel3.IsEnabled = true;
AddToView(channel3.CurrentValue);
channel3.IsEnable = false;
Philippe Mori
|
|
|
|
|
Thank you for your help. Really appreciated...
I will have a look at this approach and implement it.
Thanks again!!!
|
|
|
|
|
Hello,
I am trying to connect c# with MATLAB. I used the deploytool in MATLAB to get the dll file to be used in my c# application. I followed the steps by step example from
MATHWORKS tells for its connectivity with c#[^].
After building my c# project, when I run, it stops working and shows run time exception as follows:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'test.testclass' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT:0x8007000B)
at MathWorks.MATLAB.NET.Utility.MWMCR.mclInitializeApplication(String[] start
upOptions, Int32 startupOptionsCount)
at MathWorks.MATLAB.NET.Utility.MWMCR.InitializeApplication(String[] startupOptions)
at test.testclass..cctor()
--- End of inner exception stack trace ---
at test.testclass..ctor()
at mainApp_test.Program.Main(String[] args) in C:\Users\Abro\Documents\Visual
Studio 2008\Projects\mainApp_test\mainApp_test\Program.cs:line 44
Press any key to continue . . .
Can anyone help me solving this problem?
I am using MATLAB version 7.3, visual studio 8, windows 7 home premium, 64-bit operating system
my c# code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using test;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
namespace mainApp_test
{
class Program
{
static void Main(string[] args)
{
testclass obj = null;
double[] a = new double[1] { 10 };
double[] b = new double[1] { 33 };
MWNumericArray mwnA = new MWNumericArray(a);
MWNumericArray mwnB = new MWNumericArray(b);
MWArray[] result =null;
try
{
obj = new testclass();
result = obj.addMatlab(mwnA,mwnB);
MWNumericArray output = (MWNumericArray)result.ToArray();
Console.WriteLine(output);
}
catch(Exception)
{
throw;
}
}
}
}
|
|
|
|
|
You can start by going into your project Properties and, on the Build tab, the Platform Target has to be x86, not AnyCPU.
|
|
|
|
|
I tried to change the platform target but it has no option except Active(Any CPU)
what to do now?
|
|
|
|