Ok, so to start off, this is my first time working with C#, and the top it off I am attempting to work with it in a report editor for MYOBs AEPM software, which doesn't exactly give me a lot of info or flexibility. What I have been able to work out is that it uses some version of Data Dynamics Active Reports, but not sure which one. I also cannot seem to figure out what naming they have used for much of the report. Anyway, back to the main issue.
I am needing to add some calculations to the report that the visual editor wont allow me to do(it is restricted to Count, Sum, Min, Max, Avg, Var, so not really helpful). Now the calculations are pretty simple(One is a total x .7, and the other being the result of the first x 74 but this value might be changed in the future). Figured the best way would be to just have 2 text boxes with a value in each of them of "0", and then just once the main report is pretty much done run the calculations and replace the values of the two text boxes. So I made the text boxes in the appropriate section and labelled them CalcTotal1 and CalcTotal2.
Now in the editor it allows me to select the object and an event to trigger it, so selected ReportFooter as the object and AfterPrint as the event. I then just put in a line to chance the CalcTotal1 value and tried to generate the report resulting in the following error:
Error Message: Report Script Compile Error on line 8 Error = The name 'CalcTotal1' does not exist in the current context
public void ReportFooter_AfterPrint()
{
CalcTotal1.Text = "Hello";
}
I have tried looking at the documentation for Active Reports but I am not having much luck, so any ideas would be incredibly welcome.
just add "this" word in the code like
this.CalcTotal1.Test = "Hello";
http://helpcentral.componentone.com/nethelp/AR8Help/AR8_HelpOnlineEN/Scripts.html provides some more tips.
The MYOB AE PM feature referred to is called Smart Reports.
I was able to replicate the error and consequently resolved the problem by using the following syntax:
((TextBox)rpt.Sections["Detail"].Controls["TextBox2"]).Text= "$2000.00";
eg:
public void Detail_AfterPrint()
{
((TextBox)rpt.Sections["Detail"].Controls["TextBox2"]).Text= "$2000.00";
}
Related
For starters I'm very very new to writing code! :)
What I have so far...
So far I've used Xamarin.Forms to create a user interface for a sort of specialized calculator. I'm using a Grid Layout containing: a first column of Labels, a second column of Entries (that I have named in Xaml), and a third column of Steppers (so I can change the entries by typing or using the stepper). These 3 views on each row repeat for several rows with different label text on each row and at the bottom of the Grid Layout I have an Entry for the output.
The problem...
Basically, I want to buy a certain product at different weights and prices...among other criteria....and I want to quickly figure out how much money I'll make at a future possible sale price. Simply put... I'm trying to add/subtract/multiply/divide using Xamarin.Forms Entries. I've looked everywhere and can't seem find anyone giving an example of how to do this. I've tried different methods and usually end with an error of not being able to convert the Xamarin.Forms entry to a string...So I'm back to zero. Can I get an example of a Method where I would be able to add/subtract/multiply/divide 2 Xamarin.Forms Entry views together in the C# code behind? This seems very simple to me...what am I missing??? Is there a thread/article/video somewhere that I haven't found that covers this?? And like I said, I'm very new so the answer is probably very simple.
Thanks in advance!
Steven
Entries deal with strings, not numeric values, so you need to convert them before doing calculations.
var amount = Decimal.Parse(EntryA.Text);
var price = Decimal.Parse(EntryB.Text);
var total = amount * price;
// you can use a format string as an argument to ToString()
// to control the output - ie, how many decimals, commas, etc
LabelTotal.Text = total.ToString();
In a real app you will want to validate the input in case the user enters text instead of a value number (the Parse method will throw an exception if the input is bad);
How can I get the first visible (top) and last visible (bottom) lines number for Scintilla component in C#? For example, if I scroll the text and I am able to see lines 5-41 (no folding, it is the number of lines which are shown by the component at the moment; the rest, you have to scroll to them), how do I get those numbers programatically?
If you ever want to find out how to do something with Scintilla, your first stop should always be the core Scintilla Documentation. It is comprehensive, and usually kept fully up to date.
The correct way to do what you want is to use the SCI_GETFIRSTVISIBLELINE message to get the first line, and then use the SCI_LINESONSCREEN message to calculate the last line.
There are probably Scintilla.NET wrapper methods for those messages. But the Scintilla.NET documentation seems very poor, and doesn't provide a complete description of its API - although I suppose you could always use the SendMessageDirect method (which is documented) to send the messages directly if you can't guess what the wrapper method is called.
For ScintillaNET 2 it would be:
scintilla.Lines.FirstVisibleIndex
scintilla.Lines.VisibleCount
In ScintillaNET 3 names were refactored to be more like core scintilla:
scintilla.FirstVisibleLine
scintilla.LinesOnScreen
I am not sure as how to put this up. Actually the code is right. 99% of the time, the print-out shows correct values but, now and then it prints some other value. If i again try to print the same page, the correct value is restored.
What can be the reason for this and how can i determine it for this error. Because whenever i try to run the application in VS on my development PC everything seems correct. Can this happen or has happened to someone else not just in WPF but windows or web application.
EDIT
After doing ~50 test entries, i was able to produce the error once and the noticeable thing i discovered following : (rather than writing code i am trying to explain in general)
A = 100
B = 9
C = A+B // but sometime C gets the value of 1000 treating B as 900
Actual code
VatOnAmount = ((decimal)record.Element("Amount") +
(decimal)record.Element("Invoice").Element("CommissionAmount"))
It sounds like you have an issue where you data binding / element values may not be updated at the time the property is called to get the value. You may want to put some trace statements in your code to output values to see. Also - do you get the same issues if you step through via the debugger? Sometimes that changes race condition issues such as this.
oes anyone know a way to plot how a watched variable changes over time in Visual Studio 2010? I.e. if you had the following code
double someVariable;
for ( int i = 0; i < 20; i++)
{
someVariable = Math.Pi() * i;
}
and you watched 'someVariable' in the ide you could step through the code and watch how it grows with each step. I would like to be able to run through the loop and plot what that variable did with out having to manually step through it. I am doing a lot of math and sometimes watching how variables change is really useful and insightful.
More info:
I have a bunch of slightly different solvers and depending on the problem I am troubleshooting I would like to watch different variables to see where the problems are occurring. I currently put log these variables to a log file but it slows down the solver significantly and I have to spend a decent amount of time changing debug code to track down problems. I am looking for a slicker way to do this that is IDE centric. Sort of a Visualizer on steroids.
How about using Tracepoints? In VS 2008 (it's somewhat different in VS 2010) you just add a normal breakpoint, then right-click on it, then select "When Hit...".
In the subsequent dialog box, check "Print a message" and enter something like
someVariable = {someVariable}
This will just output its value to the output window in the IDE.
Screenshot:
Easy way? None.
But you can code it yourself..
Use property.
In setter put code, that will log change in some collection. Possibly save time too.
Use some plotting control to plot this collection
Edit:
If you dont want to create property, you can create some kind of generic class, that will have this property and has some kind of internal logging logic.
Use Perfmon and publish that value to a counter that perfmon can read. Perfmon does all the plotting etc. You just need to publish to perfmon. Unfrotunately it is not very well documented and is not trivial. (well, at least it wasn't trivial for unmanaged c++ when I was looking into it)
I did this a while back and used some classes published in an old MSJ article. (ca 1998 or so)
I will try to find some online docs.
See this question for some links
This may also be useful
If you find a solution or this works for you please let us know.
Hopefully someone will come up with a better answer, but here is what I did in a similar situation...
I output the values, in CSV format, to the console. From there, I would copy and paste into Excel, and let Excel do some graphing for me. It worked quite well, but was a complete hassle during a caffeine-driven development session.
Can't you just define and array and write someVariable to array[i] inside the loop? Then you could reference it after you're done.
double[] x = new double[20];
double someVariable;
for ( int i = 0; i < 20; i++)
{
someVariable = Math.Pi() * i;
x[i] = someVariable;
}
I've found SpPerfChart very easy to use and helpful. Simply add the user control and input your changing data to it. You'll get a graphical plot of whatever number you input realtime.
I'm messing around with some windows functions using p/invoke. Occasionally, I get an error code that is not ERROR_SUCCESS (such an odd name).
Is there a way to look these up within the program? Forexample, if I get error 1017. Can I tell the user
The system has attempted to load or
restore a file into the registry, but
the specified file is not in a
registry file format.
(ERROR_NOT_REGISTRY_FILE: 0x3F9)
Instead of
Error Code: 1017
I'm not sure if there's a niifty .NET wrapper, but you could call the FormatMessage API using P/Invoke.
See this answer for how it would normally be called from native code. Though the question refers to grabbing error codes from HRESULTs, the answer also applies for retreiving codes from the regular OS error codes coming from GetLastError/GetLastWin32Error).
EDIT: Thanks Malfist for pointing me to pinvoke.net, which includes alternative, managed API:
using System.ComponentModel;
string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
Console.WriteLine(errorMessage);
You could take the defines from winerror.h at Rensselaer Polytechnic Institute, and put them into an Enum:
public enum Win32ErrorCode : long
{
ERROR_SUCCESS = 0L,
NO_ERROR = 0L,
ERROR_INVALID_FUNCTION = 1L,
ERROR_FILE_NOT_FOUND = 2L,
ERROR_PATH_NOT_FOUND = 3L,
ERROR_TOO_MANY_OPEN_FILES = 4L,
ERROR_ACCESS_DENIED = 5L,
etc.
}
Then if your error code is in a variable error_code you would use :
Enum.GetName(typeof(Win32ErrorCode), error_code);
I landed on this page while in search of a managed alternative to calling FormatMessage through P/Invoke.
As others have said, there is no way to get those capitalized, underscored names, short of looking them up in winerror.h, which I have seen reproduced online in various places where I landed in the course of searching for information about resolving specific status codes. A quick Google search, for winerror.h, itself, uncovered a page, at Rensselaer Polytechnic Instutute, where someone has helpfully extracted the #define statements from it.
Looking at it gave me an idea; I think there may be a way to get there, working from the source code of winerror.h, which I have, as part of the Windows Platform SDK that ships with every recent version of Microsoft Visual Studio.
Right now, I am in the middle of sorting out a pressing issue in the .NET assembly that brought me to this page. Then, I'll see what I can cobble together; this kind of challenge is right up my alley, and somebody threw down a gauntlet.
Yes there's a function that does that but I don't remember what it is. In the mean time, you can use the error lookup tool (Tools->Error Lookup) to see what a particular code means from within Visual Studio.