|
i have this code:
string a, b="test";
a=b.charAt(2);
but when i try to compile, i get this error:
'string' does not contain a defination for 'charAt'(CS0117)
what seems to be the problem?
|
|
|
|
|
The problem is that there is no charAt method on the string object (I think it's JavaScript having that method).
char a;
string b = "test";
a = b[2];
Should do the trick.
|
|
|
|
|
now i've this
string repRec,repAddr;
repRec=rec.ToString();
this.repAddr=repRec[2];
the compilation returns me an error of:
Cannot implicitly convert type 'char' to 'string'(CS0029)
|
|
|
|
|
You need to have a look at the basic types of C#. A char is a single character and it simply isn't the same type as a string. If you look at my sample code you would se that I was declaring a char - so not a string - to receive the value.
So this should work:
string repRec;<br />
char repAddr;<br />
<br />
repRec=rec.ToString();<br />
this.repAddr=repRec[2];
Notice that rec.ToString() is a bit scary - it is not strongly typed. I would recommend a real cast of possible (or access to string members - whatever), then you get an error if it does not make sense. You might be used to loose type checks from JavaScript and find the strict checks of C# annoying... just wait until you are used to them, then you will hate the loose typechecks as they give way too many errors.
|
|
|
|
|
It might help to read and understand the error message the compiler gives you - usually it's right.
With the error message and error number given it's really easy to find the error and its description on MSDN, for example, so you can understand what went wrong.
That's something you'll have to learn because it's a lot easier and faster than asking why a trivial error occurred on CP...
Regards,
mav
|
|
|
|
|
Hello, i use theese few lines of codes to open different windows, form different places, but it seems not so object oriented, could somebody tell me a nicer way to do it, that would be easier to maintain also?
public void openWindow(System.Windows.Forms.Form parentForm, String childForm, String layout)
{
switch (childForm)
{
case "frmAsiakkaat":
frmPink pink = new frmPink();
pink.MdiParent = parentForm;
pink.Show();
break;
case "frmKohteet":
frmGold gold = new frmGold();
gold.MdiParent = parentForm;
gold.Show();
break;
case "frmRaportit":
frmBlue blue = new frmBlue();
blue.MdiParent = parentForm;
blue.Show();
break;
case "frmTervetuloa":
frmGreen green = new frmGreen();
green.MdiParent = parentForm;
green.Show();
break;
}
}
R
John
|
|
|
|
|
|
Thx, that took care of a few lines of worthless code!
|
|
|
|
|
|
Hi im new at these forums, so this is my first post, i hope that some of you guys could help me out with this problem i have.
I'm building a drag n' drop program that will allow a user to drag n drop an item (like a button) from one control to another.
Currently i have a problem managing threads, or rather parsing data between them.
My problem is this. I need to sample the mouse's x and y coordinates for each control so that it will drop the item at the correct place in the control. The reason im using threading is that once i start dragging an object (button) the sampling of the x and y coordinates pauses. Thus i need to run it in another thread.
My problem is that i can't seem to get _GetLocalMouseCoordinates to run in a thread of its own, i get this error
C:\Documents and Settings\My Documents\Visual Studio Projects\DragNDrop\DragDrop.cs(359): Method 'DragNDrop.Form1._GetLocalMouseCoordinates(object, System.Windows.Forms.MouseEventArgs)' does not match delegate 'void System.Threading.ThreadStart()'
The code is below, i have only pasted the "vital" part though. I hope that someone cna help. Thanks alot in advance!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace DragNDrop
{
///
/// Summary description for Form1.
///
/// Huske/tænke liste
///
/// 1. Threading hvor hurtig opdaterings tid kan formen klare uden at choke?
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel pnlDrag;
private System.Windows.Forms.Panel pnlDrop;
private System.Windows.Forms.Label lblDrag;
private System.Windows.Forms.Label lblDrop;
private System.Windows.Forms.Button btnDrag;
private System.Windows.Forms.Button btnPush;
private System.Windows.Forms.StatusBar statusBarGlobal;
private System.Windows.Forms.StatusBar statusBarLocalDrop;
private System.Windows.Forms.StatusBar statusBarLocalDrag;
// My generated variables etc.
public int iXCoorDrag;
public int iYCoorDrag;
public int iXCoorDrop;
public int iYCoorDrop;
public int iXCoorGlobal;
public int iYCoorGlobal;
public Thread GlobalMouseThread;
public Thread LocalMouseThread;
public bool bStopthread;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public void pnlDrag_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// GetGlobalMouseCoordinates();
statusBarLocalDrag.Text = "DRAG - Local X: " + e.X.ToString() + " Y: " + e.Y.ToString();
iXCoorDrag = Convert.ToInt32(e.X.ToString());
iYCoorDrag = Convert.ToInt32(e.Y.ToString());
}
private void pnlDrop_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// GetGlobalMouseCoordinates();
statusBarLocalDrop.Text = "DROP - Local X: " + e.X.ToString() + " Y: " + e.Y.ToString();
iXCoorDrop = Convert.ToInt32(e.X.ToString());
iYCoorDrop = Convert.ToInt32(e.Y.ToString());
}
private void btnDrag_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// GetGlobalMouseCoordinates();
}
private void btnPush_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// GetGlobalMouseCoordinates();
}
private void btnDrag_Click(object sender, System.EventArgs e)
{
}
private void btnPush_Click(object sender, System.EventArgs e)
{
Button btnClick = new System.Windows.Forms.Button();
btnClick.Location = new System.Drawing.Point(0, 0);
btnClick.Name = "btnClick";
btnClick.TabIndex = 1;
btnClick.Width = 100;
btnClick.Height = 50;
btnClick.Text = "BUTTON CLICKED";
btnClick.Visible = true;
pnlDrop.Controls.Add(btnClick);
}
private void btnDrag_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right) return;
if (e.Button == MouseButtons.Middle) return;
}
private void btnDrag_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
btnDrag.Location = new System.Drawing.Point(iXCoorDrag, iYCoorDrag);
MessageBox.Show("Moved to: " + iXCoorDrag + ", " + iYCoorDrag);
}
private void pnlDrag_DragLeave(object sender, System.EventArgs e)
{
}
private void pnlDrop_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
MessageBox.Show("DRAG ENTER");
}
private void pnlDrop_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
}
private void GetGlobalMouseCoordinates()
{
statusBarGlobal.Text = "Global X: " + Form1.MousePosition.X.ToString() + " Y: " + Form1.MousePosition.Y.ToString();
iXCoorGlobal = Form1.MousePosition.X;
iYCoorGlobal = Form1.MousePosition.Y;
}
private void _GetGlobalMouseCoordinates()
{
bStopthread = true;
while(bStopthread)
{
GetGlobalMouseCoordinates();
Thread.Sleep(100);
}
}
private void _GetLocalMouseCoordinates(object sender, System.Windows.Forms.MouseEventArgs e)
{
bStopthread = true;
while(bStopthread)
{
statusBarLocalDrag.Text = "DRAG - Local X: " + e.X.ToString() + " Y: " + e.Y.ToString();
iXCoorDrag = Convert.ToInt32(e.X.ToString());
iYCoorDrag = Convert.ToInt32(e.Y.ToString());
Thread.Sleep(100);
}
}
public void Form1_Load(object sender, System.EventArgs e)
{
ThreadStart myGlobalStarter = new ThreadStart(this._GetGlobalMouseCoordinates);
GlobalMouseThread = new Thread(myGlobalStarter);
GlobalMouseThread.Start();
ThreadStart myLocalStarter = new ThreadStart(this._GetLocalMouseCoordinates);
LocalMouseThread = new Thread(myLocalStarter);
LocalMouseThread.Start();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
bStopthread = false;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
|
|
|
|
|
eclipsedk wrote:
C:\Documents and Settings\My Documents\Visual Studio Projects\DragNDrop\DragDrop.cs(359): Method 'DragNDrop.Form1._GetLocalMouseCoordinates(object, System.Windows.Forms.MouseEventArgs)' does not match delegate 'void System.Threading.ThreadStart()'
Ahhh, a more decriptive error there could not be. I can't judge the rightness of your overall algorithm, but the problem here is that you're trying to start a method that does not match the parameter list and return value specified by the ThreadStart delegate http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadstartclasstopic.asp[^].
You can only start methods using that delegate that return void and accept no parameters. _GetGlobalMouseCoordinates matches the delegate. _getLocalMouseCoordinates on the other hand, wants an object and a MouseEventArgs .
Share and enjoy.
Sean
|
|
|
|
|
Hi,
Does anyone know how to identify .NET dll from others (such as COM dll).
Thanks.
|
|
|
|
|
Check the imports section to see if the dll mscoree.dll is included?
|
|
|
|
|
Sorry, I don't really get it.
What I meant was, is there any attribute we can check using Reflection to determine if a dll is a .NET dll.
Thanks.
|
|
|
|
|
When reflection works on the dll, you can be sure it is a .NET dll.
|
|
|
|
|
|
I don't know if this is the "blessed" way of doing this, but I try to load the dll as a .Net assembly, and trap a BadImageFormatException . Non-.Net dlls cause this error to be raised.
System.Reflection.Assembly test = null;
try {
test = System.Reflection.Assembly.LoadFile(assemblyPath);
} catch (BadImageFormatException ex) {
App.WriteLog(assemblyPath + " is not a .Net assembly");
}
Share and enjoy.
Sean
|
|
|
|
|
How can we know that given dll is managed or unmanaged.
Thanks
Shivonkar
|
|
|
|
|
If LoadLibrary() fails, then it isn't unmanaged. That doesn't guarantee it is managed, though, it may just be junk -- so you could then try to follow up with System.Reflection.Assembly.LoadFile, or the like. Determining the whether it is .net 1.1 or 2.0, etc. might be interesting too.
Also, if you get verion info from the file, a .NET dll will have "Assembly Verion" whereas an unmanaged dll will not (well, probably -- there's nothing to prevent some perverse developer from adding such it to an unmanaged dll, I guess).
The other thing is to look up the binary format; I don't know if there is some magic number in the first few hundred bytes of a managed assembly to identify it as such...
Matt Gerrans
|
|
|
|
|
|
Hi
I need to know an unique id for a PDA, that I can send to a desktop app.
Is there a way to obtain a PDA's MAC address (if it has such) or another hardware unique id on the PDA?
I'm in the high-fidelity first class traveling set.
And I think I need a Lear jet.
|
|
|
|
|
hi... i have the same question too. have you already found the answer for this?
|
|
|
|
|
i wanna some one tell me more about how to make a flash design and use it inside the form of C# project i need it so much cuz i have to design visualization in my forms
but pleaz i wanna a full description cause till now i'm just bignner in .net envirnoment
i know i'll tired you but pleas replay soon
watting for ur replay
|
|
|
|
|
|
Hi
I have one big problem I have been facing this problem for the last three months since project has started
I have to enumerate all the inactive modem connectio names in list box on form load.
Can any one has idea about getting all modems name
thanks
|
|
|
|