Scalar Valued Function - Return Datediff As Decimal / Percent

Jan 4, 2011

I am currently writing a scalar valued function and I'm having a few issue with the returned result. I have narrowed the problem down to a calculation that convert the difference between two dates as a percentage/decimal. No matter what I try the return value is always a whole number
set @earnedpremium = (@premium * @pretripearnings) + ((@premium - (@premium * @pretripearnings)) * cast((datediff(day, @outdate, @experiencedate) / datediff(day, @outdate, @returndate))as decimal(5,2)))
The cast section needs to return the percentage, I know the rest is working fine through some elimination and testing.

View 1 Replies


ADVERTISEMENT

Function With A Percent Chance To Return True?

Aug 31, 2010

I'm trying to build a function where I can pass in a percentage and it would have that percentage to return a true value. However I'm completely drawing a blank on how to make on such function.

View 3 Replies

Datatable Getdata Performance - In-line Table Valued Function In SSMS Takes About 6 Seconds To Return 11088 Records?

Mar 25, 2011

An in-line table valued function in SSMS takes about 6 seconds to return 11088 records. The same function in VB .Net 4.0 using TableAdapters.InputTableAdapter.GetData (Created with data set designer) takes about 15 minutes complete.Both are executed from the same workstation.Why does this discrepancy exist?

Workstation:

Windows XP SP3, 2GB

VS2010 Ultimate

.Net 4.0 Framework

Server:

SQL Server 2008

View 3 Replies

Return The Count From Scalar Query?

Apr 1, 2009

When I type in cntrows. I get all my table variables except the one I want which is TotalComments. How do I return the Count from my scalar query? I have a Table Adapter named :

[Code]...

View 1 Replies

Passing The Result Of An Array-Valued Function From A Fortran95?

May 25, 2011

I am interested in developing a multi-language program that will have a main .NET GUI but will perform calculations by calling procedures from a Fortran95 dynamic link library file. Right now I am just playing around with a very simple project in order to get the interoperability between the .NET framework and a Fortran95 (*.dll) file working correctly. So far, I've been able to pass the Fortran95 (*.dll) file an array from VB, sum all the elements of the array using an intrinsic Fortran function, and pass the scalar result back to the .NET framework with no problem. However, if I try passing Fortran the exact same array, construct the transpose of that array using another intrinsic Fortran function, and try passing the transposed array back to the .NET framework I keep throwing an exception. I am not a programming wiz, but it appears that when Fortran stores an array in memory, the .NET framework doesn't know how to read that. I am looking for some guidance on how to pass an array from the Fortran95 (*.dll) file back to the .NET framework.

View 9 Replies

How To Deal With Execute Scalar Command That Return Null

Jan 10, 2012

I want to retrieve total value from sales table in sqlcommand object. Below is my sample code.I will get error if there was no data in the tabel that matched my query saying that null could not be converted into decimal.

I would not get error if there was data that matched my query and returned the total value in tmpSales variable.My question is what is the best way to deal with this situation?

Dim CmdTmp As System.Data.SqlClient.SqlCommand

Dim tmpSales As Decimal

CmdSales = New System.Data.SqlClient.SqlCommand("SELECT SUM(Total) FROM Sales WHERE Date>= '1 Jan 2011' And Date<= '30 Jan 2011", ConDB)tmpSales = CmdSales.ExecuteScalar

View 2 Replies

Sql Server - Call A Table Valued Function From Visual Basic.Net And How To Store The Result?

Nov 4, 2011

In my VB.net code i have:

cmd.CommandText = "SELECT * FROM [strfg].[dbo].[Myfunc] (@MyParam)"
Dim myparam As New SqlParameter("@MyParam", a)
cmd.Parameters.Add(myparam)

The function (runnig on SQL server) returns a table with four columns, one row.How do I call this function from Visual Basic? cmd.ExecuteScalar() is obviously not correct. In c++ I use a recordset. What is the equivalent in vb? Does anyone have a short example?

View 2 Replies

How To Call Scalar Value Function

Apr 20, 2011

I have one scalar value function defined in sql database.It accespts 2 parameters and return an integer.Can anyone please help how to call UDF from vb.net using oledeb?

View 1 Replies

.net - Datediff And Dateadd Function?

Feb 22, 2011

If DateDiff(DateInterval.Day, moDoBooking.m_CurrentDay, moDoBooking.m_BaseDay) _
> DateDiff(DateInterval.Day, DateAdd(DateInterval.Day, _
Convert.ToDouble(moDoBooking.oBooking.oFacility.ADAYS), moDoBooking.m_BaseDay), _
moDoBooking.m_BaseDay) Then

This condition won't satisfy with these values:

moDobooking.m_CurrentDay = 2/3/2011
moDobooking.m_BaseDay = 22/02/2011
moDoBooking.oBooking.oFacility.ADAYS = 1

You might say this is dead-easy but honestly it's late here and my head is not working at all! Could AnyOne tell me why is that?

View 2 Replies

Get Month By Using 'DateDiff' Function?

Jun 22, 2010

I have five text boxes & one button there in my form. I have written this code to get user`s current age. But problem is that I have to get user`s age with months.

My code to get age :

Private Sub Command1_Click()
BDate = Text1.Text & "-" & Text2.Text & "-" & Text3.Text
CurDate = Now

[Code].....

View 1 Replies

Datediff Function Not Getting The Expected Result

Jul 11, 2011

I am using the following code in my project. I want to find the number of days by given the last date and now.[code] for example, when BorrowDate is "01/Jul/2011" then the result is 7 days which it should be 10 to now.

View 1 Replies

Specifying Monday As The First Day Of Week In The DateDiff Function?

Dec 21, 2011

I had some trouble specifying Monday as the first day of week in the DateDiff function.

The following syntax does not work: Dim myWeekNumber as Int32 = DateDiff("ww",date1,date2,2)

Compiler Error Message: BC30519: Overload resolution failed because no accessible 'DateDiff' can be called without a narrowing conversion

However, using the enumeration value (FirstDayOfWeek.Monday) instead of the value (2) does work. I wonder why.

View 2 Replies

The DateDiff Function Doesnt Work At All?

Apr 10, 2011

I tested every example I found but it doens't work in vb 2010 express... Do I need to install anything moor to make it work?

View 2 Replies

Datediff Function - Show The Difference As 1 Year

Apr 15, 2012

One of the problems with datediff function is that even if the two dates are 31-12-2011 and 01-01-2012,it will show the difference as 1 year.How to overcome this problem?

View 17 Replies

DateDiff Function Gives Odd Results For Negative Days?

Jun 9, 2009

DateDiff for the interval Day gives expected results for days past until present, but if the first date is further in time than the second date, it gives the difference +1. Is there something I'm doing wrong? For example, if I put in today for both, the difference is 0. If I put in yesterday and today, I get 1. This is all expected, but if I put in tomorrow and today, I get 0, and two days from now and today give -1. Why is the function giving altered results if the date is negative?

Here is the specific code.

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
TextBox1.Text = DateDiff(DateInterval.Day, DateTimePicker1.Value, Date.Now)
End Sub

View 4 Replies

Where To Place DateDiff Function To Effect On All Records

Jan 18, 2011

I have a project, a database with employee information (name, town, birthday, HireDate, etc). I have add custom TextBox (on fly), and on that TextBox a

TexBox1.text = DateDiff("d", HireDateDateTimePicker.value, Now)
.
Which is calculating how many days worker is working in company from HireDate,and Now.I have put code on event TextBox1_TextChanged. But, this means that I need to move cursor in TextBox1 to apply changes. I have also try with MouseMove. It works, but if I would have a huge database, then application will all the time reading script on MouseMove, and by that will slow down entire program.

View 2 Replies

IsDecimal - Return A Boolean On Whether A Value Is A Decimal Or Not??

Oct 3, 2008

Is there an easy way to return a Boolean on whether a value is a decimal or not?

[Code]...

View 4 Replies

Return Decimal Number By Using UBound?

May 6, 2011

want to return decimal number but because of "UBound" its keep displaying as integer how can i display decimal numbers?Public Class frmPrintbooks

Private Sub frmPrintbooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For x = 0.0 To UBound(Form1.printBookName)
lstPrintbooks.Items.Add(Form1.printBookName(x) & " " & String.Format("{0:C}", Form1.printBookPrice(x)))
Next x
End Sub

[Code]...

View 14 Replies

Return A Value That Is Set In A Radio Button And Add It To What Decimal A User Inputs Into A Text Box?

May 1, 2010

I am wondering how do i Return a value that is set in a Radio Button and Add it to what Decimal a User inputs into a Text box?

Public Class Form1
Private Sub txtbasic_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbasic.TextChanged
End Sub

[code]....

i have 2 Error and 1 Warning Function 'OverTime Doesn't Return a value on all code paths.

1 Expression is not an array or a method, and cannot have an argument list

2 Expression is not an array or a method, and cannot have an argument list

View 4 Replies

Return An (Anonymous Type With A Function) From A Function?

Mar 3, 2011

Just so it's known, this question is mostly academic, even though I tried to use the concept in a real-world solution. I realize the example is contrived, but I believe the concept is valid.I want to write some fluent code like this:

[code]...

I realize that I can't force an anonymous type into a specific type (like implementing an interface or some other class), and I don't want the overhead of defining a specific class just to match my desired fluent name with the actual method name. So I was able to make the code work like this:

copy(my_first_file).to.Invoke(my_second_file)So there is no IntelliSense or type awareness there, and I have to include the Invoke in order to have the method run. How can I get more type safety and exclude the Invoke method, under these constraints: Anonymous Type returned from Method No additional classes or interfaces Preferably, I do not want to pass in another parameter to the copy() method that tells what type to return, unless copy becomes a generic method (but I think that means defining another class/interface, which I don't want to do)

View 3 Replies

.net - String.Format Decimal With Sign Fixed Number Of Decimal Places, No Decimal Separator?

Jun 27, 2012

What is the cleanest, most readable way to String.Format a decimal with the following criteria

start with a sign symbol (+ or -)
a fixed number of fraction digits
no decimal separator
right aligned
pre-padded with "0"'s

View 3 Replies

Passing Null Decimal Value To Function?

Jul 20, 2010

I have a Function within a data access layer, which accept a number of parameters. Among these is a decimal value, but in some cases the decimal value with be NULL, here is the code from the function

I am using the following code in my code file to pass the value to the function...

Convert.ToDecimal(textbox1)

How can I pass a NULL value to my function?

View 6 Replies

VB Function To Convert Decimal To Elapsed Time?

Jun 21, 2009

display a Decimal (or double) to elapsed time [h]:mm:ss (hours:minutes:seconds)using vb.net?

example:

if you were to type "1.34666666666667" into a cell in Excel then choose Custom Format [h]:mm:ss The result is an elapsed time of "32:19:12". Using the OADate function only runs on a 24 hour clock so this does not work for longer durations unfortunately...

View 4 Replies

RoundUp Function - Which Will Round A Number UP To The Specified Decimal Precision

Apr 29, 2009

I need a function which will Round a number UP to the specified decimal precision, exactly the same as how Excel's RoundUp function works:

Roundup(dblVal, intDecPlaces)

So I need the following:

Roundup(0.896523, 4)
would return
0.8966

However, everything i've tried/found simply rounds to the nearest whole integer, or returns a normal rounded value, hence the above would return
0.8965

I've tried the following:

Math.Round(dblval, intPrecision, midpointrounding.awayfromzero)
' and
Math.Round(dblval, intPrecision, midpointrounding.toeven)

And even custom functions, such as:

Public Function RoundUp(ByVal varValue As Object, _
ByVal iNum As Integer) As Double

'ignore the data types here, I was playing to see 'if changing any of the data types would swing 'the results (knowing full well they wouldnt make 'a difference, thats how fed up with this I am!)

Dim lNum As Long, xVal As Double, xVar As Object

xVar = Fix(varValue)

[CODE]...

I've even looked at converting this to a string, looking at the Xth decimal place, and incrementing it up by 1, then converting it back to a double, while this works (sort of) it seems to be a very roughshod way of doing it, and I'd rather do it mathematically than with lots of data conversion.

View 6 Replies

Duplicate Numeric Valued Objects

Oct 1, 2011

I have a series of files numbered from 1-80 I want to duplicate every 4th file of the series and have the numeric value pushed so that the 80 files become 100. I tried a For Loop going to 80 but for some reason I can't figure a good way out to push the value so that the next item in the list doesn't overwrite the last.My goal is to have the files copied from an original destination to a new one but with their name to be pushed up from its original.

View 1 Replies

.NET Function Return Value?

Jun 15, 2011

Possible Duplicate: VB.NET Function Return If I have a function that returns a boolean, what is the difference between:Return False and Function = False

View 2 Replies

Function Does Not Return Nothing?

Feb 12, 2010

take a look at the following Code:

Private Sub btnDebug_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDebug.Click
Dim d As Date

[Code]....

The Funtion ZZNull always returns Nothing, so IsNothing(d) in the calling method should evaluate to True.

But it does not !

When you run these lines, then you will see that IsNothing(d) evaluates to False

View 7 Replies

Get A Function's Return Value?

Jan 14, 2012

In the documentation of FileInfo.Create Method it says:

'Declaration
Public Function Create As FileStream
'Usage

[code].....

View 7 Replies

How To Use A Function's Return Value

Mar 8, 2009

So the program I am writing validates the controls on the page on button_click.

I want to write a function which checks which step the program is at (0-7) then return something depending on whether or not it validated.

My plan was to return the control which was not valid.

Private Function ValidateInputs() As Control
Select Case wizardStep
Case 0

[Code].....

1. could I return the names off all the controls which did not validate?

2. should I be returning a control type or would something like a string be better?

View 3 Replies

Return More Than One Value From A Function?

Mar 1, 2012

One over time hours and one week's pay @10 hourly pay. I wanted to display those two in two listboxes 1 and 2.

Public Class Form1
Dim overTimeHours As Double
Dim weekPay As Double

[Code].....

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved