|
I think what you want here is a way to "compose" a Func that you can use later
public struct TestStruct
{
int X;
int Y;
public TestStruct(int x, int y)
{
X = x;
Y = y;
}
}
private Func<int, int, TestStruct> TestFunc = (x, y) =>
{
return new TestStruct(x * 4, y * 5);
};
private TestStruct testStruct1;
testStruct1 = TestFunc(100, 200);
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
I use Interop.RSIOPC.dll to connect via "OPC" a c# code with the PLC. I browse between the tags in the PLC memory and to do that I am using some functions. Browsing is mainly "moveDown(branch name)" or "MoveUp()". This is working. But if I need to jump staright to a branch I have to use MoveTo(ref System.Array). The array is created typeof string. At runtime MoveTo returns with a generic error and after many test my guess is that problem is related to the fact that I am using managed objects while the dll operated unmanaged.
Many thanks in advance for any help.
Regards
Roberto
I add here some more details:
my c# code :
System.Array branches;
branches = System.Array.CreateInstance(typeof(string),1);
branches.Initialize();
branches.SetValue("SLC_MODBUS_BASIC", 0); //name of the branch I need to move to
MyOpcBrowserName.MoveTo(ref branches); //pass the System.Array by ref as requested by the dll
This generate the unmanaged exception "Error HRESULT E_FAIL has been returned from a call to a COM component."
Error code -2147467259
Source "Interop.RsiOPCAuto" " at RsiOPCAuto.OPCBrowser.MoveTo(Array& Branches)\r\n at ... my code..
Here below the code from OPC foundation
OPCBrowser.cpp
// (c) Copyright 1998 The OPC Foundation
.
.
.
#include "stdafx.h"
#include "OPCBrowser.h"
.
.
.
// OPCBrowser::MoveTo method
STDMETHODIMP COPCBrowserImpl::MoveTo( SAFEARRAY ** ppBranches )
{
if(*ppBranches == NULL)
return E_INVALIDARG;
// Clear out the list
ClearNames();
HRESULT hr = S_OK;
LONG lBound=0;
LONG uBound=0;
// ServerHandles
hr = SafeArrayGetLBound(*ppBranches, 1, &lBound);
if( FAILED(hr) )
return hr;
hr = SafeArrayGetUBound(*ppBranches, 1, &uBound);
if( FAILED(hr) )
return hr;
hr = MoveToRoot();
if( FAILED(hr) )
return hr;
for( LONG index=lBound; index<=uBound; index++ )
{
BSTR Branch;
hr = SafeArrayGetElement(*ppBranches, &index, &Branch);
if( FAILED(hr) )
return hr;
if(*Branch != 0 )
{
hr = m_pOPCBrowser->ChangeBrowsePosition( OPC_BROWSE_DOWN, Branch );
SysFreeString( Branch );
if( FAILED(hr) )
return hr;
}
}
return hr;
}
Thank you in any case
Roberto 
modified 22-Dec-15 4:25am.
|
|
|
|
|
Hello can someone help me with some exercises? The questions are rather long so i cant post them here.
If someone is patient enough to check my code please leave a message
|
|
|
|
|
whats is the question here?
modified 20-Sep-20 21:01pm.
|
|
|
|
|
if someone is willing to check my code and help me solve my exercises please contact me via skype name:[DELETED].yo or mail me at [DELETED]@hotmail.com.
[edit]Email and Skype removed - OriginalGriff[/edit]
modified 21-Dec-15 1:54am.
|
|
|
|
|
Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
This is not likely to happen - you are basically asking us to mark you homework before you submit it, which is a long job with little benefit to anyone, and one we can't necessarily do: we don't know what criteria your tutor will be using to "judge" the code as we have no idea what your course it, or how far into it you are.
If you have specific questions then feel free to ask them (probably here: Qutick Answers[^]), or if you have more general discussions about the language then this forum is good. But reading you homework and judging it? Not really our "thing" - what if everyone on your course made the same request? Or everyone doing homework?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
As you can see from the other responses here, no one is going to do homework for you.
However, everyone can post specific technical questions related to code they are working on; I'd recommend you post those on the C# QA forum.
In your questions be sure to:
0. summarize the problem briefly at the start of the post
1. tag your question appropriately: WinForms ... etc.
2. show carefully selected code that will help us understand what you are doing, and format the code using CP's format facilities.
3. describe any error messages: where did the error occur, etc.
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
This command is not working. It gives the error stated in the subject. Anyone knows how to solve it? Thanks.
SqlCommand Command = new SqlCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values ('" + grid_lic.CurrentRow.Cells[1].Value + "', " + grid_lic.CurrentRow.Cells[2].Value + "," + grid_lic.CurrentRow.Cells[3].Value + ",'" + grid_lic.CurrentRow.Cells[4].Value + "','" + grid_lic.CurrentRow.Cells[5].Value + "','" + grid_lic.CurrentRow.Cells[6].Value + "')", connection);
Command.CommandType = CommandType.Text;
Command.ExecuteNonQuery();
|
|
|
|
|
First you opened your code up to SQL Injection attacks, risking the destruction of your database.
Second, your problem is easily solvable by using parameterized queries and the SqlParameter class.
Google for "C# sql parameterized queries" and you'll find everything you need.
|
|
|
|
|
Actually I had tried another code before which also gave an error:
Additional information: Incorrect syntax near '2015'.
Unclosed quotation mark after the character string ',')'.
The code was this:
SqlCommand Command = new SqlCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (" + NIF + "', " + loja + "," + bloqueador + ",'" + DataFim + "','" + lastupdate + "','" + Nome + "')", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", grid_lic.CurrentRow.Cells[3].Value);
COmmand.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
Command.ExecuteNonQuery();
|
|
|
|
|
That's not how you put together a parameterized SQL string. I don't know where you got that from, but it's definitely not in any documentation.
I suggest you go back and lookup more stuff to read. This is what the string should look like:
"INSERT INTO lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome)
VALUES (@NIF, @Loja, @Bloqueador, @DataFim, @lastupdate, @Nome)"
line breaks are there to make it readable on the site.
|
|
|
|
|
Dave is correct that is not the correct way to build a parameterized query in C#. However, if you want to know where your SQL statement was getting broken.
values (" + NIF + "', " + loja + "," + bloqueador + ",'" + DataFim + "','" + lastupdate + "','" + Nome + "')
When this query is parsed it will become
values(NIF',Loja,bloqueador,'DataFim','latupdate','Nome')
Can you spot the error?
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
You replied to the wrong person. I got the notice you replied, the OP didn't.
|
|
|
|
|
I am building EPOS system (takeaway order software) with C# and everything went as I planed and I almost done programming it.
The application works where customers provide their Postcode when they want to order something and based on their postcode I should get a list of street names and when I select the street name I get a list of house numbers, then select the number to deliver the food to.
I noticed that all nowadays takeaways use this address finder which included in their EPOS which works with no need for internet connection.
Now the problem is: know do I build / include this address finder in my EPOS system? I do not want to use online address search in my EPOS. Do I have to use another special application to like address finder?
I am really stuck at this point and I can not go further programming my POS till I solve this address finder issue. Please help me with any peace of information you know in how to solve this issue. Thank you
|
|
|
|
|
Almost certainly, you want an online API - Google can help: Postcode to address API[^] as the databases tend to be pretty big, and companies tend to change for them (the UK database for example, is £2 per postcode area, per user, per year).
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: is £2 per postcode area, per user, per year Crikey that can add up quickly. What I found was the bastards keep changing the postcode boundaries so last years data is invalid.
Doesn't a postcode cover just a few houses in the UK?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
What is your concern? Cost?
How much is a "valid" address worth?
Is this app for yourself? (You can get free access to address finder APIs / data while in development) Would a user of your app be prepared to pay a few cents for a valid address?
I've developed address finders for call centers and shipping companies. It's part of providing a better service.
|
|
|
|
|
Hi Gerry and thank you for your reply. yes this app for myself, my EPOS will be free for some time and then will be sold for very cheap because my app is new. Therefore I might cost too much to buy an address finder app. I can not find any address database in the internet. Can you please guide me how can I access this address finder APIs / data? or do I have to develop address finder as you did? please help me. Thank you
|
|
|
|
|
|
Thank you Gerry for this information but as I understood from your explanation that I have to use online services ( PAF database and PCA Predict web services) to search for the address (list of street names and and house numbers) by its Postcode. Am I right?
I asked you this because I don't want to use online service as my EPOS will not have internet connection.
In the UK, most of EPOS don't use online services to locate addresses. Yesterday I check one computer which contains EPOS which can do address lookup but there is no address database in this PC and on the same time this PC has not internet connection But it has MS MapPoint and it has some Postcode APIs. So how this PC find the full address? does it use MapPoint to find address ?
Please help me I am confused, I would appreciate it if you answer my questions? Thank you
|
|
|
|
|
naouf10 wrote: as my EPOS will not have internet connection
How could that possibly work?
There might be a nomenclature problem but it seems that you want to create a order server where someone orders food to be picked up and/or delivered. If the person is at the shop there is no need for the person's address. If the person is not at the shop then both they and the shop must have internet access.
But other than that, for now, make them type the address in. Get everything else working and then add that.
|
|
|
|
|
Customers can phone in to make an order and their order will be saved and printed out and delivered to their home so this EPOS does not have internet access.
So that is why I am wondering how this EPOS can find the address from the postcode although there is no internet access nor address database in the PC? but this PC has Ms MaPPoint and some C# APIs.
Do you have any idea how possibly the PC can find the address? Thank you
|
|
|
|
|
naouf10 wrote: how this EPOS can find the address from the postcode although there is no internet access nor address database in the PC?
Simple then - it cannot.
The data must come from somewhere.
|
|
|
|
|
hi
cant run my C# program after installation - only if i Run as administrator.
in my setup i set the
InstallAllUsers = True
i change the app.manifest file to
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
allso i try to remove this app.manifest file and i try to change to
requestedExecutionLevel level="asInvoker" uiAccess="false" - and same problem
and after the install, when i try to run the program - The software is not running
only if i click on the exe file and run as administrator.
thanks
modified 19-Dec-15 6:13am.
|
|
|
|