VB.NET Console application - Trouble using Math.Log() - vb.net

I am more or less new to VB.NET and I am trying to program a simple console application for a basic finance and savings calculation program.
I am having trouble with the Math.Log() function and I hope someone can help me to point out my
mistake/mistakes.
This is the values I need to get working (the brackets shows the values ​​that actually should work but do not in my code):
Public Class basicSavingsPlaner
Private userTotalCost As Double (50,000.00)
Private userSaves As Double (3,451.47)
Private userAnnualRate As Decimal (0,08)
Private userMonths As Double (should be 10)
If I use my regular calculator (TI-82) I get the correct answer of userMonths which is 10, this is how I type it on my calculator (I switched the values from digits to the names of my Declarations):
(log(((userAnnualRate * userTotalCost)/userSaves)+1)/(log(1+userAnnual)) = 10.0029...
This is my attempt to recreate it for my VB.NET console application:
userMonths = ((Math.Log((userAnnualRate * userTotalCost) / userSaves) + 1) / (Math.Log(1 + userAnnualRate)))
In this case, userMonths's result is 14.9, which is wrong.
I would really appreciate if someone could help me, I have search here in this forum and on Google for days now.
// Televeinken

If you look closely at the statement from your TI-82 and compare it with your VB.Net code you will see that you have the statement grouped differently between the two. Try something like this(note the grouping of three brackets after the initial log statement instead of two):
userMonths = (Math.Log(((userAnnualRate * userTotalCost) / userSaves) + 1) / (Math.Log(1 + userAnnualRate)))
userMonths = 10.000008962349851

The problem is with the grouping expressions with brackets () that is you are executing different expressions with Math.Log and log.
if you change like this ((Log((userAnnualRate * userTotalCost) / userSaves) + 1) / (Log(1 + userAnnualRate)))
means it will also result in 14.9
OR you can make a change like
(Math.Log(((userAnnualRate * userTotalCost) / userSaves) + 1) / (Math.Log(1 + userAnnualRate)))
then both will result in 10.00

Related

Adding together 4 different Tablix data columns SSRS

I have been using
=Sum(Fields!Figure, "Dataset1")
+ Sum(Fields!Figure, "Dataset2")
Now this gives me a result in a text box.
However, i need to sum together the result from 4 different tablix datasets.
I have tried this below but as soon as i try to sum more that 2 datasets it errors.
=Sum(Fields!Figure, "Dataset1")
+ Sum(Fields!Figure, "Dataset2")
+ Sum(Fields!Figure, "Dataset3")
+ Sum(Fields!Figure, "Dataset4")
This gives me (#error). I am assuming i am missing some code somewhere but i have looked online and cant find anything anywhere.
Can anyone help?
Thanks
I'm fairly certain the field is ended with .value:
=SUM(Fields!TextBoxName.Value, "Dataset1")
+SUM(Fields!TextBoxName.Value, "Dataset2")
...

WP8 SQlite Select Query

I have following code.
string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Questions.sqlite");
SQLiteConnection dbConn = new SQLiteConnection(DB_PATH);
dbConn.CreateTable<QuestionModel>();
// Some code which insert the records in database from webservices.
List<QuestionModel> questionsList = dbConn.Table<QuestionModel>().ToList();
System.Diagnostics.Debug.WriteLine("List Count " + dbConn.Table<QuestionModel>().ToList().Count);
The List Count gives me 0 always. But When I use WP POWER TOOLS and get the Questions.sqlite file from emulator. It gives me records in SQLite table.
I also check the query in http://sqlitestudio.pl/ on the same Questions.sqlite but that gives me records as it should.
I tried other way to get the records as following code but none them were working.
String query = "Select * from QuestionModel;";
questionsList = dbConn.Query<QuestionModel>(query);
System.Diagnostics.Debug.WriteLine("List Count " + questionsList.Count);
With your analysis seems like only the row List<QuestionModel> questionsList = dbConn.Table<QuestionModel>().ToList(); is not working.
I helped someone in SQLiteDB on WP8 a couple of days ago, here is his question : SQLite WP8 StackOverflow
If you compare his code with your code, you are missing the Model bindind :
db.GetTableInfo("QuestionModel");
And
db.Table<QuestionModel>().ToList<QuestionModel>();
Not important but use your list variable to get count in debug write to not retrieve twice the list questionsList.Count
Hope it helps.

SRSS Report Builder SUM IIF from different datasets

I have two datasets in Report Builder 3.0 with a similar field and I want to put a SUM of the number occurrences of a particular value in that common field across both datasets.
I've got an expression I'm using for each individual dataset:
=SUM(IIF(Fields!caseorigin.Value = "mail",1,0))
and
=SUM(IIF(Fields!cliorigin.Value = "mail",1,0))
But I can't seem to work out a way to sum the values from both datasets. I've tried:
=SUM(IIF((Fields!caseorigin.Value, "caseDS") = "mail",1,0)) + SUM(IIF((Fields!cliorigin.Value, "cliDS") = "mail",1,0))
Is there any way to make this work, or an alternative method?
Just looks like a syntax error here; when specifying a scope it should like something like:
=Sum(Expression, Scope)
Applying this to your example:
=SUM(IIF(Fields!caseorigin.Value = "mail",1,0), "caseDS")
+ SUM(IIF(Fields!cliorigin.Value = "mail",1,0), "cliDS")
Should work for you.

how to sum two aggregate functions

I am building a report in visual Studio and have various calculations for things like total etc.
I am now trying to find the percentage of two totals but I am struggling as it won't allow me to use 2 aggregate functions in my one expression.
The functions I have are:
=Sum(Fields!Quantity.Value, "AccruedHours") + Sum(Fields!Quantity.Value, "Services")
AND
=Sum(Fields!Quantity.Value, "AccruedHours") + Sum(Fields!Quantity.Value, "Services")
They are the same function but act for 2 different totals so in order to find out the percentage I have to divide both these functions by each other see below:-
=Sum(Fields!Quantity.Value, "AccruedHours") + Sum(Fields!Quantity.Value, "Services")/=Sum(Fields! Quantity.Value, "AccruedHours") + Sum(Fields!Quantity.Value, "Services")
can anyone suggest a better way to do this?
Many thanks,
You can use Val function
Simply try this
=Val(Sum(Fields!Quantity.Value, "AccruedHours") + Sum(Fields!Quantity.Value, "Services"))/Val(Sum(Fields! Quantity.Value, "AccruedHours") + Sum(Fields!Quantity.Value, "Services"))
I managed to figure it out in the end.
The way I did it was using the below code to reference the exact text boxes rather than trying to do seperate aggregate functions. This way I just had to do a divide on the two totals.
See below code:-
=(ReportItems!textbox20.Value) /
(ReportItems!textbox22.Value)
Thanks anyway for the suggestions to the original question.

NHibernate SQL query issue with string parameter

I got a problem with this code:
string sql = "select distinct ruoli.c_tip_usr"
+ " from vneczx_ute_app_trn ruoli"
+ " join vnecyd_ent_prf ind"
+ " on ruoli.c_ent = ind.c_ent"
+ " where ruoli.c_app = :appCode"
+ " and ruoli.c_ute_mat = :matricola"
+ " and ind.t_des_ent = :indirizzo";
var ruoli = session.CreateSQLQuery(sql)
.SetString("appCode", Config.Configurator.Istance.ApplicationCode)
.SetString("matricola", user.Matricola)
.SetString("indirizzo", indirizzoCasella)
.List<string>();
This code is correctly executed, the query logged is correct, and the parameter passed correctly evaluated... but it doesn't return any result at all.
Copying the query from the debug console and executing it directly in an Oracle client application (SQL Developer), it gets 2 results (the results I expect to be right).
I found out that the problem is in the last parameter indirizzo, and should depend on the fact that it contains a special char # (indirizzo is an email address).
So I ended up using this solution:
string sql = "select distinct ruoli.c_tip_usr"
+ " from vneczx_ute_app_trn ruoli"
+ " join vnecyd_ent_prf ind"
+ " on ruoli.c_ent = ind.c_ent"
+ " where ruoli.c_app = :appCode"
+ " and ruoli.c_ute_mat = :matricola"
+ " and ind.t_des_ent = '" + indirizzoCasella + "'";
var ruoli = session.CreateSQLQuery(sql)
.SetString("appCode", Config.Configurator.Istance.ApplicationCode)
.SetString("matricola", user.Matricola)
.List<string>();
But it gives me thrills! Aren't the parameters in a query supposed to handle specifically this situation, and thus handle themselves situations with special char, and so on?
Why here a string concatenation works better that a parametric query?
Isn't there a way to force the NHibernate engine to escape some special char?
Update:
I found out how to solve this particular issue: usign the trim command on the field who raise the problem, the problem disappears.
So last line of my sql string now is:
+ " and trim(ind.t_des_ent) = :indirizzo";
I can't understand why it solves the problem thought. Not the field, nor the variable contains empty chars and copying th query on SQL Developer works in both way.
So we have some luck soving the problem, but we have no idea why now it works?
Any thoughts?
even I was facing the same issue, but your hint using TRIM for column saved my day. Since I was looking for a long time, but not able to figure it out.
Along with that, I was able solve my issue by doing the below changes as well:
We were using CHAR datatype some of the columns which used in the query where clause. This was causing the issue to fetch the data from NHibernate. We changed the data type of that column from CHAR to VARCHAR2 and even updated the data with actual size and removed the TRIM from Where clause, the TRICK WORKED!!!! :)
So, any one face this kind of issue, first check whether you are having any column with CHAR and then change to VARCHAR2.
But one more thing you have to remember is: if you are running your application from ASP.Net Development Server, close it and re-run your application. Since if the opening Asp.Net Development Server and if you make any changes to datatype that will NOT be refreshed in your oracle connection. So, better you close the ASP.Net Development server and then re run the application.
Hope my points will help somebody in future!!
Regards,
Sree Harshavardhana
You are not using parameters in a SQL query if you want SQL parameters use a SQL stored proc