| Math.Round and SQL Server Round |
|
 |
Index ‹ Visual Studio ‹ Visual Basic [VB]
|
- Previous
- 1
- Visual Basic [VB] >> ADO in VB.NETHi
I want to apply ADO object in VB.NET. Can I bind the textbox, editmask,
combo box and grid control to the ADO recordset?
Any sample would be appreciated.
Thanks...Douglas
- 2
- 3
- 4
- Visual Basic [VB] >> Serial Comm ProblemI wrote a program that communicate with SerialComm. In every 300
milliseconds, my program continuously send & receive data via the serial
port once the program starts.
My program is once in a while, the serial port seems corrupted because when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen
the port again.
Why?!! Is there any way to fix this problem or I have to check for
corruption port, then I reopen the serial port again?
Thanks!
Michael
- 5
- Visual Basic >> timer bombs out vb6I have an app written in VB6 that works fine on 90% of the machines it is
installed on. The other 10% get this wierd error. I added a lot of debug
code to catch it and what is boils down to is that the timer object quits
working. The interval is 5 seconds, and as far as I can tell the app keeps
responding. But the timer gives an error 429 at seemingly random times.
Does not seem to matter if I enable and disable the timer at some interval
(once every 5 minutes), etc.
Anyone else ever seen this?
- 6
- VB Scripts >> Run MBSA tool as administrator?Hi folks,
I have a logon vbscript to run the MBSA tool, but it apparently needs
to be ran with admin privledges. I know there are 3rd party utilities
that can help do this, but I'd rather just incorporate the necessary
info into my script. I've seen people mention how to do this, but I'm a
little confused about how to incorporate this into my script. Here's my
script:
Sub run_mbsa
Set oShell = WScript.CreateObject ("WSCript.shell")
return = oShell.Run("""C:\Program Files\Microsoft Baseline Security
Analyzer\mbsacli.exe"" /c %computername% /o %C%.%D%.com.xml /f
c:\output.txt", 0, true)
Set objFSO = CreateObject("Scripting.FileSystemObject")
xmlfiles = oShell.ExpandEnvironmentStrings("%userprofile%") +
"\securityscans\*.xml"
objFSO.CopyFile xmlfiles, "\\servername\foldername" , True
objFSO.DeleteFile xmlfiles
Set oShell = Nothing
Set objFSO = Nothing
End Sub
Can someone tell me how to run this as an admin?
Thank you,
Ed
- 7
- MFC >> Where is MSCOMM object ?Hello,
Where is the MSCOMM activeX object (for communicating with com ports) ? (the
friendly name of activeX object).
Thanks :)
- 8
- MFC >> OnReleasedcaptureSliderhi
i hav taken a control of Slider m_ctrlSlider ...and i have seen in
msdn that GetSelection method
from that we can get the current end and position of slider ...but
when i m debuging and move the slider it does not give right thing
......both current and end position it gives 0,0;
plz some one tell me where i m going wrong
i will appreciate ...
void CThumbnailDlg::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT*
pResult)
{
// TODO: Add your control notification handler code here
int i,,j;
//int i=m_ctrlSlider.GetPos();
//m_ctrlSlider.GetRange(j,k);
//i =m_ctrlSlider.GetRangeMin();
//i=m_ctrlSlider.GetRangeMax();
/
m_ctrlSlider.GetSelection(j,k);//this is not working properly
*pResult = 0;
}
- 9
- 10
- MFC >> HOWTO: Notify owner from a DLL?Hi,
I have an MFC based dialog app that is used to
control external devices over a standard, RS-232
serial com port. The serial port code creates a
secondary thread to handle incoming bytes and
notifies the parent dialog when data is received
by using ::PostMessage. Everything works great.
Now I want to put the functionality of the dialog
app into a DLL. But I have never created a DLL so
here are some basic questions.
1. If I want the DLL to be useable by clients that
are non-MFC, is it correct that I should create a
regular DLL (as opposed to an extension DLL)?
2. I would prefer to statically link the DLL so
that I don't have to include the MFC DLL with the
distribution. Is static linking OK?
3. How do I notify a client using the DLL, when a
serial port event occurs? If I can still use
::PostMessage, then I guess I would need to get
the handle of the client app with some kind of
Init() function?
Thanks for your help..
RickL
- 11
- Visual Basic [VB] >> Fill Combobox with DVI would like to fill a combobox with the values of one
column of the dataview I am using. When I set it up the
way I expect it would be, I get every row in the combobox
says: System.Data.DataRowView
If I click on one, it navigates to the right place. Any
idea how I would get the System.Data.DataRowView to show
the actual values in the column?
Thanks
- 12
- Mcse >> OT: Beta 2Beta 2 is here!!!
Windows Server 2007 beta 2
Office 2007 beta 2
Vista beta 2
All should be available to anyone, I think!
And yeah, Virtual Server R2 SP1 beta 1, too!
What a great time to be a nerd!
- 13
- Visual Studio C++ >> FindFirstFileI write a code to see files and subdirectories of a directory.
But if a directory has no subdirectory or any file, findClose does not
release directory handle. So I cannot remove that directories.
(It does not enter if block pointed by 4). But filefinddata shows ".."
as cfilename. But handle shows 0xFFFFFF.Although it's value equals to
INVALID_HANDLE_VALUE It has lock over directory that I want to list.
but if there is any file or sub directory in the directory it enters if
block and handle shows valid value and findClose works and releases
lock over the directory.
Note1: I check locks over directories with "Unlocker 1.7.1"
Note2: I work with platform builder and x86 emulator. So I can control
directories on my disk.
SOURCE CODE
void listView::ReadDirectory(LPTSTR dir,HWND listHandle)
{
LPTSTR retVal=(LPTSTR)LocalAlloc(LPTR, 500);
1--> WIN32_FIND_DATA FindFileData;
2--> HANDLE hFind;
retVal=wcscat(retVal,dir);
int listNumber;
if(wcslen(dir)!=0){
insertDefaultDir(listHandle);
listNumber=0;
}else{
listNumber=-1;
}
if(hWnd!=listHandle){
otherList->activeDir=dir;
}else{
activeDir=dir;
}
retVal=wcscat(retVal,_T("\\*.*"));
3--> hFind = FindFirstFile(retVal, &FindFileData);
SendMessage(listHandle,WM_SETREDRAW ,false,NULL);
4--> if(INVALID_HANDLE_VALUE !=hFind)
do
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
listNumber++;
LV_ITEM litem=createListItem(listNumber,FindFileData.cFileName);
ListView_InsertItem(listHandle, &litem);
ListView_SetItemText(listHandle, listNumber, 1, _T("<dir>"));
SYSTEMTIME myTime;
FileTimeToSystemTime(&FindFileData.ftLastWriteTime,&myTime);
LPTSTR dateValue=convertDateToString(myTime);
ListView_SetItemText(listHandle,listNumber,3,dateValue);
LocalFree(dateValue);
}
else if(! (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
listNumber++;
int pos=findR(FindFileData.cFileName,'.');
LPTSTR
filename=pos!=-1?mid(FindFileData.cFileName,0,pos):FindFileData.cFileName;
LPTSTR
ext=pos==-1?_T(""):mid(FindFileData.cFileName,pos+1,wcslen(FindFileData.cFileName)-(pos+1));
LV_ITEM litem=createListItem(listNumber,filename);
ListView_InsertItem(listHandle, &litem);
ListView_SetItemText(listHandle, listNumber, 1, ext);
long fileSize=(FindFileData.nFileSizeHigh * MAXDWORD+1) +
FindFileData.nFileSizeLow;
ListView_SetItemText(listHandle,listNumber,2,convertToString(fileSize,10));
SYSTEMTIME myTime;
FileTimeToSystemTime(&FindFileData.ftLastWriteTime,&myTime);
LPTSTR dateValue=convertDateToString(myTime);
ListView_SetItemText(listHandle,listNumber,3,dateValue);
if(pos!=-1){
LocalFree(filename);
LocalFree(ext);
}
LocalFree(dateValue);
}
6 --> }while (FindNextFile(hFind, &FindFileData) != 0);
7--> FindClose(hFind);
LocalFree(retVal);
SendMessage(listHandle,WM_SETREDRAW ,true,NULL);
UpdateWindow(listHandle);
focusedItem=0;
ListView_SetItemState(listHandle,focusedItem,LVIS_FOCUSED
,LVIS_FOCUSED); // select item
}
THANKS IN ADVANCE
- 14
- MFC >> questin about enum all threads of a processHi all:
I know I can enum the threads of a process using toolhelper lib in win2k
or win9x. but the lib is not availble at Winnt. instead of toolhelper,
microsoft supply the performance data library, but the data struct is too
complex. Can I have another way to get all threads handle of a process?
Thank advance.
sincecely
- 15
- Visual Basic >> When using a Frame my embeded contols loose their text?I have a frame with 3 controls on it. 1 text box and 2 option controls. The
text control gets it's text from an INI file and the Option buttons get their
captions from this same ini file when the program loads. For some reason when
the program loads I loose the text and captions? I have been playing around
with the frame settings but have had no luck so I must be missing something
simple right?
|
| Author |
Message |
joonehotmailcom

|
Posted: Mon Nov 29 12:59:17 CST 2004 |
Top |
Visual Basic [VB] >> Math.Round and SQL Server Round
I'm trying to determine the best approach for rounding in an application I'm
building. Unfortunately it appears as though SQL Server and VB.NET round in
different ways.
SQL Server
select round(123.465,2)
returns
123.470
Which I think is correct.
VB.NET
Math.Round(123.465, 2)
returns
123.46
Through online help I have read that the VB.NET way of doing it is "called
rounding to nearest, or banker's rounding."
I guess my first question is what is correct (when determining Tax or Sale
prices)?
My next question is what is the best approach for standarizing? Can I make
SQL Server act like VB.NET or VB.NET act like SQL Server?
Are there additional functions either in SQL Server or VB.NET that I am
missing?
Also it appears as if the behavior is consistent throughout the VB.NET
environment (formatcurrency and formatpercent).
There are certain parts of the applicaiton where it makes sense for SQL
Server to calculate some of the numbers and other where it makes sense for
VB.NET to.
Thanks
Visual Studio221
|
| |
|
| |
 |
David

|
Posted: Mon Nov 29 12:59:17 CST 2004 |
Top |
Visual Basic [VB] >> Math.Round and SQL Server Round
tmeister wrote:
>
> I guess my first question is what is correct (when determining Tax or
> Sale prices)?
>
Your accountant / CFO should be able to tell you which is the correct
accounting method. Why is this calculation being left to the
programmers? This is a financial matter, not a programming one.
--
David Gugick
Imceda Software
www.imceda.com
|
| |
|
| |
 |
tmeister

|
Posted: Mon Nov 29 14:01:08 CST 2004 |
Top |
Visual Basic [VB] >> Math.Round and SQL Server Round
I realize this is an accountant question, but if I'm playing every role, it's
now my decision. I can't imagine that this type of question is not addressed
with almost every ecommerce site on the Internet. Once a decision is made, I
will need to know how to implement the appropriate functionality either on
SQL Server or insided VB.NET.
Thanks
"David Gugick" wrote:
> tmeister wrote:
> >
> > I guess my first question is what is correct (when determining Tax or
> > Sale prices)?
> >
>
> Your accountant / CFO should be able to tell you which is the correct
> accounting method. Why is this calculation being left to the
> programmers? This is a financial matter, not a programming one.
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>
>
|
| |
|
| |
 |
James

|
Posted: Mon Nov 29 15:07:43 CST 2004 |
Top |
Visual Basic [VB] >> Math.Round and SQL Server Round
"tmeister" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> I'm trying to determine the best approach for rounding in an application
I'm
> building. Unfortunately it appears as though SQL Server and VB.NET round
in
> different ways.
>
> SQL Server
> select round(123.465,2)
> returns
> 123.470
> Which I think is correct.
> VB.NET
> Math.Round(123.465, 2)
> returns
> 123.46
VB Rounds a 5 to the nearest EVEN number so:
123.465 becomes 123.46 while 123.475 becomes 123.48 I personally consider
this to be an incredibly inconsistent form of rounding and find that is
causes numerous issues when programming. As far as I know only Microsoft
rounds this way and it might only be VB.
To Cause VB to round in a normal way take the int of +.5 so for the numbers
above Int((Num*100)+.5))/100 Or if the Floor function takes an argument for
the number of decimals Floor(Num+.005,2) I don't use VB much so I'm not
sure about the Function Names.
To Make SQL round the VB way is trickier, you need to determine whether the
rounding digit(s) = 5 and then if the digit before the rounding digit is
even or odd. Something like:
DECLARE @Num as Numeric(8,4)
Declare @Dig as Numeric(8,4)
Declare @Dig2 as Integer
Declare @Even as integer
SET @Num = 123.465
SET @Dig = @Num * 1000 - (CAST(@Num*100 as integer)*10)
SET @Dig2 = CAST(@Num * 100 as Integer) - (CAST(@Num * 10 as Integer)*10)
SET @Even = Case When @Dig2 in (2,4,6,8,0) then 1 else 0 end
SELECT Round(Case @Dig When 5 THEN CASE @Even When 1 THEN @Num-0.001
ELSE @Num+.001 END
ELSE @Num END,2)
Regards,
Jim
|
| |
|
| |
 |
David

|
Posted: Mon Nov 29 15:36:27 CST 2004 |
Top |
Visual Basic [VB] >> Math.Round and SQL Server Round
tmeister wrote:
> I realize this is an accountant question, but if I'm playing every
> role, it's now my decision. I can't imagine that this type of
> question is not addressed with almost every ecommerce site on the
> Internet. Once a decision is made, I will need to know how to
> implement the appropriate functionality either on SQL Server or
> insided VB.NET.
>
> Thanks
>
My point is if you are in charge, you should not take the word of anyone
but an accountant or someone else who is in the know. The fact that SQL
Server and VB round differently is not really an issue until you know
how you must process the data using certified accounting principles.
--
David Gugick
Imceda Software
www.imceda.com
|
| |
|
| |
 |
Steve

|
Posted: Mon Nov 29 15:55:43 CST 2004 |
Top |
Visual Basic [VB] >> Math.Round and SQL Server Round
James Goodwin wrote:
>"tmeister" <EMail@HideDomain.com> wrote in message
>news:EMail@HideDomain.com...
>
>
>>I'm trying to determine the best approach for rounding in an application
>>
>>
>I'm
>
>
>>building. Unfortunately it appears as though SQL Server and VB.NET round
>>
>>
>in
>
>
>>different ways.
>>
>>SQL Server
>>select round(123.465,2)
>>returns
>>123.470
>>
>>
>
>
>
>>Which I think is correct.
>>
>>
>
>
>
>>VB.NET
>>Math.Round(123.465, 2)
>>returns
>>123.46
>>
>>
>
>VB Rounds a 5 to the nearest EVEN number so:
>123.465 becomes 123.46 while 123.475 becomes 123.48 I personally consider
>this to be an incredibly inconsistent form of rounding and find that is
>causes numerous issues when programming. As far as I know only Microsoft
>rounds this way and it might only be VB.
>
>
James,
This is called "Banker's Rounding", and is widely used in finance
(http://support.microsoft.com/kb/196652). It may be required by law in
some places. There is no "correct" way to round the last digit away
when a number ends in 5.
Steve Kass
Drew University
>To Cause VB to round in a normal way take the int of +.5 so for the numbers
>above Int((Num*100)+.5))/100 Or if the Floor function takes an argument for
>the number of decimals Floor(Num+.005,2) I don't use VB much so I'm not
>sure about the Function Names.
>
>To Make SQL round the VB way is trickier, you need to determine whether the
>rounding digit(s) = 5 and then if the digit before the rounding digit is
>even or odd. Something like:
>
>DECLARE @Num as Numeric(8,4)
>Declare @Dig as Numeric(8,4)
>Declare @Dig2 as Integer
>Declare @Even as integer
>
>SET @Num = 123.465
>SET @Dig = @Num * 1000 - (CAST(@Num*100 as integer)*10)
>SET @Dig2 = CAST(@Num * 100 as Integer) - (CAST(@Num * 10 as Integer)*10)
>SET @Even = Case When @Dig2 in (2,4,6,8,0) then 1 else 0 end
>
>SELECT Round(Case @Dig When 5 THEN CASE @Even When 1 THEN @Num-0.001
>
>ELSE @Num+.001 END
> ELSE @Num END,2)
>
>
>Regards,
>Jim
>
>
>
>
|
| |
|
| |
 |
| |
 |
Index ‹ Visual Studio ‹ Visual Basic [VB] |
- Next
- 1
- Visual Studio C++ >> Problem with covariant return typesThe following code won't compile (error C2555: 'B::f': overriding virtual
function return type differs and is not covariant from 'A::f') unless I
moved the definitions of X and Y to before the definitions of A and B
respectively. Now I can understand that the compiler doesn't know that Y is
derived from X when parsing B but at the very least this is a very confusing
error message and I'm not sure it shouldn't be accepted.
Rob.
class X;
class A
{
public:
virtual X* f () const = 0;
};
class X
{
public:
};
class Y;
class B : public A
{
public:
virtual Y* f () const;
};
class Y : public X
{
public:
};
- 2
- 3
- Visual Studio C++ >> bit shiftingi wanna shift the unsigned int e.g.
from
BINARY: 0110 0000 0011 0000 1101 0000 0000 0001
into
BINARY: 1000 0000 0000 0100 0000 0000 0000 0000
with the code i << 18;
but it seems that it won't detected the leading zero during shifting ?
and wrongly give me
0100 0000 0000 0100 0000 0000 0000 0000
any solution for that ?~
- 4
- Visual Basic [VB] >> Share source files among projects?Is it possible to share a single source file among two or more Projects in a
Solution?
I'm not talking about a DLL, just a .vb file that might contain a class or
module with common code to be compiled into each project. That way this
code can be updated once instead of makiing duplicate changes to identical
code within each project.
I have tried putting the source in a common folder, then using Add Existing
Item to add it to each project, but that creates a separate copy of the file
in each project folder. Then I'm back to keeping changes syncronized
manually.
I have been searching VB.NET help and newsgroups, but either this can't be
done or I am asking the wrong questions.
thanks
Dick
- 5
- 6
- MFC >> Fatloss computer programI have been using this computer program for a couple weeks now and i am very pleased with the results so far. its a software fatloss program, if your looking for a diet/weightloss plan i reccomend you check this place out first: http://fatloss9.50webs.com
- 7
- Visual Basic >> ErrorsDear All,
Does anyone know of a third party tool that can add error handling code to
all subs/functions in a class or module to a specified format which then can
be customised to deal with the errors likely to be raised at the code?
I have been neglectful in adding error handling code and comments as I go as
the project has now grown and other developers are going to be using my
code. I know that it is bad practice and I have learned my lesson, but any
advice, other than its your own fault, would be most welcome. If I have to
create my own add-in for the future, can anyone suggest how I can
programatically find the start and end of a sub to add the suggested code?
Thanks again.
Alastair MacFarlane
- 8
- MFC >> ActiveX in MFCI'm trying to create an ActiveX control in MFC.
I have a library which was provided for the development of an MFC program
NOT ActiveX.
I made a sample ActiveX and included the library under
Project->Settings->Link Tab but after building the ActiveX and viewing the
control in Test Container, no methods were exposed??
Am I doing something wrong or will the library NOT work with an ActiveX???
Thanks
David
- 9
- Visual Studio C++ >> How to convert _TCHAR * to string?I need to check command line parameter
if (argv[1] == option) .... // option is a string variable
And argv is defined as _TCHAR* argv[] by MSVS wizard.
The code don't work and it's very hard to convert argv[1] to string.
- 10
- Visual Basic >> Profiler in Team Edn for S/W Dev--Any successes?I am struggling to get any useful performance data out of the profiling tool
in Visual Studio Team Edition for Software Developers.
On a simple command-line app, it reports bogus call paths in release and
release with debug info builds. With a debug build, the results are so
compromised by the overhead of calling inline functions that they are useless.
With a real-world, complex app, it either runs out of memory trying to
analyze the profile data or crashes. This is for an app that runs in 1.2
seconds normally.
It won't even run the app if you select sampling; profiling must be done
with instrumented code.
I've used MetroWerks Hierarchical Profiler, Rational Quantify and Compware
DevPartner, and all have provided useful information that have enabled me to
track down, understand and fix performance problems. Not so Visual Studio
Team Edition. Is there some trick that makes it work usefully?
Thanks,
Rich
- 11
- VB Scripts >> force clicking on an objectHello,
How can I force clicking on an object,
if I have the following code, and I want to do click on event_view -
How can I do that ?
Thanks :)
The code :
-------------
<input type="hidden" id="event_view" onclick = "myview" />
...
- 12
- 13
- MFC >> Debug Assertion FailedFirst the problem, then I'll attempt to post all of the info I think may be pertinent. I get the following message when I try to register a dll on a machine other than the one I built it on
Debug Assertion Failed
Program: C:\B7\DV7333\bin32\REGSVR32.EX
File: olelink.cp
Line: 29
When developing, it builds fine and I am able to register it on the development machine
This is an MFC dll which implements the class wizard generated: DllGetClassObject, DllCanUnloadNow, and DllRegisterServer functions
I have used depends.exe on the target machine and all it's dependcies are accounted for
I have another VB created dll that provides a few classes that are used in this problem dll. I access those via the following statement: #import "vbdll.dll" no_namespac
This stuff I dont really understand, but it appears to work. I do receive the following warning message during the mfc dll build
d:\program files\microsoft visual studio\vc98\include\comip.h(31) : warning C4042: '_IID' : has bad storage clas
d:\program files\microsoft visual studio\vc98\include\comip.h(57) : see reference to class template instantiation '_com_IIID<struct _vbdllObject,&struct __s_GUID _GUID_22b44757_efef_4c0b_be51_32138fe6eb04>' being compile
S:\VC++\dllProject\dllCode.cpp(328) : see reference to class template instantiation '_com_ptr_t<class _com_IIID<struct __vbdllObject,&struct __s_GUID _GUID_22b44757_efef_4c0b_be51_32138fe6eb04>>' being compile
The VB dll IS registered and IS in the path on the target machine
Thanks in advance for any insight into this problem
Jeremy
- 14
- MFC >> When user trying to quit program while thread is runningHi guys, I have a memory leak problem. When I tried to quit program by click
'x' at top right corner while my ui thread and its child worker thread are
running, debugger display following messages:
The thread 0x570 has exited with code 0 (0x0).
The thread 0x574 has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
c:\work\MyProject\MyUIthread.cpp(396) : {717} normal block at 0x00C17CA8, 4
bytes long.
a CWinThread object at $00C17BF0, 112 bytes long
c:\work\MyProject\MyUIthread.cpp(96) : {550} normal block at 0x00C17FC0, 12
bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD
c:\work\MyProject\MyUIthread.cpp(94) : {549} normal block at 0x00C17398, 12
bytes long.
Data: < 0 > C2 30 00 00 F2 C9 00 02 D1 01 00 00
c:\work\MyProject\mainfrm.cpp(746) : {535} client block at 0x00C17E40,
subtype 0, 128 bytes long.
a CMyUIThread object at $00C17E40, 128 bytes long
Object dump complete.
The thread 0x304 has exited with code 0 (0x0).
The program c:\work\MyProject\Debug\MyProject.exe' has exited with code 0
(0x0).
In my program, ui thread is created when certain selection made from combo
box and shutdown, deleted when combo box selection. Ui thread creates one
worker thread for communication with embeded system via COM port. So in a
normal situation(combo box changed), shutdown prccedure is like this: First,
main frame PostThreadMessage(QUIT) to ui thread. Ui thread set 'running'
flag to FALSE to let worker thread exit its while(running) loop. Just before
exit, worker thread sends another QUIT packet to embeded system to power off
then PostMessage(THREAD_QUIT) to main frame. Message handler in main frame
wait for m_hThread and delete pThread. Debugger doesn't complain about this
normal shutdown and the program looks just fine when I try without debugger.
Can I neglect this situation?
Where can I insert this shutdown procedure when program is forced to quit
while threads running?
Any suggestion appreciated. Cheers
- 15
|
|
|