Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How U Will Check Decimal And Non Decimal Values???

Hi Friends
Is anybudy know how to check that is there a decimal value on non decimal value in my text feild??

Thanks alot in advance

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Insert SQL Statement With A Decimal Field When The Decimal Separator Is The Comma
I have a problem with the “Insert” SQL statement in an Access program.
I have a table in which there is a numeric field of Single type, so it can contain decimal numbers. As I’m european, the decimal separator in the control panel (international and language options) is set to the comma “,” and not to the dot “.”
What happens is that, when I want to insert a new row to the table, Access thinks that a decimal number is two separate integer numbers, so it stops for a run-time error saying that the values’ number in the query doesn’t correspond to the destination fields’ one.
For example, suppose that the table is composed by two fields, the first one “intNumField" of Integer type, and the second one "singleNumField" of Single type.
I define and initialize two variables as follows:

Dim intNum As Integer
Dim decNum As Single

intNum = 4
decNum = 1,7 ' (or decNum = 1.7, it's the same)

The statement
DoCmd.RunSQL "insert into Numbers values (" & intNum & "," & decNum & ")"

becomes this one:
DoCmd.RunSQL "insert into Numbers values(4,1,7)"

You can see it defining a String variable as follows:
Dim str As String
str = "insert into Numbers values (" & intNum & "," & decNum & ")"

putting a breakpoint after this statement and checking "str" value.
The run-time error is obviously unavoidable.

Is there a way to let Access know that this one isn't a list of 3 integer numbers (4 and 1 and 7) but a list of 2 numbers, the first integer (4) and the second decimal (1,7)?

Thank you very much

Decimal Values...
Before I start my question, take a look at this code...

If Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) > 0 And Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) <= 25 Then
HoursWorked = Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0") & ".25"
If Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) > 25 And Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) <= 50 Then
HoursWorked = Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0") & ".50"
If Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) > 50 And Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) <= 75 Then
HoursWorked = Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0") & ".75"
If Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) > 75 Then
HoursWorked = Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0")
If Right(Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0.00"), 2) = 0 Then
HoursWorked = Format(DateDiff("s", ScanIn, ScanOut) / 3600, "0")
End If
End If
End If
End If
End If

...and for example, when a person scans in at 02/10/2005 08:11:46 AM and scans out at exactly 02/10/2005 08:11:46 PM, instead of showing a flat 12 hrs., 11.25. I require a value formatted to 0.00 because of course, salary would be calculated based on this not by "1 hr. and 30 mins." kinda way. So it has to be in a manner I stated (0.00). And my bosses want the decimal digits to be either .25, .50, .75, or a whole 0.00. I'm not good at math, so kindly help me out here...

Decimal Values To One
hi , i want to convert decimal values to 1 using VB 6.0.

for example
    if x= 123.56 i want to convert to 124.
    if x=123.05 this should also be converted as 124

anyone pls help me.

Edit: *Moved from VB.NET Forum to VB General Forum - (CanOz)


Edited by - CanOz on 7/6/2005 11:48:58 PM

Output Decimal Values
I have a calculation and i need to output the result to 2 decimal places without rounding off the value. I think the calculation is working correctly up until i reach over 40 hours, thats when it starts to round off. For example if i put in 41 hours it gives me the result of 248 when it should really be 247.50. Another one i tried was 50 hours, the answer should be 321 but it came up as 315
here's the code

If txthours.Text < 41 Then
hours = Val(txthours.Text) * Val(6#)
ElseIf txthours.Text > 40 < 47 Then
hours = FormatNumber((40 * 6) + (Val(txthours.Text) - 40) * 7.5, 2)
ElseIf txthours.Text > 46 Then
hours = ((40 * 6) + (6 * 7.5) + (Val(txthours.Text) - 46) * 9)
End If
lblanswername = FormatNumber(hours, 2)

i solved it worries

Why I Am Getting Wrong Values After Decimal...?

I am getting wrong values after the decimal point. How to sort out the problem?

The following is the code:

VB Code:
Public Sub FourthQuarterSales()Dim sngTotal As Double sngTotal = 0If txtOct.Text <> vbNullString Then  If IsNumeric(txtOct.Text) Then    sngTotal = sngTotal + CSng(txtOct.Text)  End IfEnd If If txtNov.Text <> vbNullString Then  If IsNumeric(txtNov.Text) Then    sngTotal = sngTotal + CSng(txtNov.Text)  End IfEnd If If txtDec.Text <> vbNullString Then  If IsNumeric(txtDec.Text) Then    sngTotal = sngTotal + CSng(txtDec.Text)  End IfEnd If txtFourthQuarterSales.Text = Format(sngTotal, "#,##0.00")txtFourthQuarterSales.Locked = TrueEnd Sub


Check For Decimal
If a user enters a number, how can you check to see if it is a decimal or not?

Why Does Excel Add Decimal Places To My VB Values?
I have some values truncated to 1 decimal place in my VB program.
The program saves these values to an Excel worksheet and, then, Excel adds many decimal places.
Why does this happen?
What can I do to prevent it?


Getting HEX &amp; DECIMAL Values (Open As Binary)
I'd like to get the actual HEX and DEC values of a known byte position when opening a file for BINARY ACCESS. Here is the scenario -- or maybe I'm on the wrong track with the Opening for Binary:


-I know the position of the bytes that I want to read are 41, 42, 43, 44

-I open and get to that as follows (it may not be the easiest way to get it but it makes it clearer to me how I get to it):

TheFile = "C: estmyfile.etc"
Open TheFile For Binary Access Read As #1
Dim temp As String
temp = Space$(44)
Get #1, , temp
Close #1
MyData = Right(temp, 4)

-Now that I have the data (MyData) I want to display it as follows:

MyDataInHex = ???????? (Help Here)
MyDataInDec = ???????? (Help here)

Text1.text = MyDataInHex 'Eg: 00 08 00 00
Text2.text = MyDataInDec 'Eg: 2048 (Hex read in little endian)

-For an extra "topping", sometimes my HEX value will represent ASCII. An example is:

Text3.text = MyDataInHex 'Eg: 64 61 74 61
Text4.text = MyDataInAsci 'Eg: data

Wow ---- thanks for letting me ask this one and thanks in advance.

Decimal Values Saved In Variables
Hi everyone,

I need a variable in my program that can store a decimal number containing two decimal places. What do I need to declare my variable as to use cDec()? Can some show a quick example?

Thanks thanks thanks

Insert Decimal Values Using Command Obj???
hello all,

got a bit of a problem inserting a decimal value using a command object.

the insert keeps rounding the decimal value passed to it?

i had this working by opening an ado recordset and passing parameters to a stored procedure, so i know the table in sql is ok.

i now have to use a command object, which executes ok, but rounds the decimal value?

can anyone spot the mistake?

cn.Open cnStr
Set cmd.ActiveConnection = cn
cmd.CommandText = "usp_insertOrderToOrderedItems_T"
cmd.CommandType = adCmdStoredProc

cmd.Parameters.Append cmd.CreateParameter("Cost", adNumeric, adParamInput, 20, Cost)
'a few more parameters here

cmd("Cost").Precision = 18
cmd("Cost").NumericScale = 2
i've also tried changing the createParameter data type to adDecimal?


How Can I Add The Decimal Values In MS Access Database?
Dear Friends,

When I am trying to add decimal values (ex: 5.50) directly or using vb it saves only the round values (ex: 5.50 becomes 5)? Using MS Access database. The field Data type is "Number" .... Field Size "Long Integer" and The format type is "Standard".

What is the problem? How can I add the value which have decimals. Please help me out.



Decimal Values In Access And Datagrids In VB.NET
Hi everybody,

I'm using a Access 2000 database to store the values created and edited in a application developed in VB.NET. I created a table "Components" in Access with a column named "Prize" and type "Decimal" with 2 decimal digits. I can easily insert a value into the table (With Access application) for example 1.95.

But I can't seem to get it right in my application in VB.NET.

I made a application with a DataSet. In this dataset the table "Components" is available and the column "Prize" too (with type decimal). But on a form with a DataGrid things just don't work. Values (like 1.95) already in the table are shown OK. But when I update the DataSet after I edited or added a value everything is rounded down......

I don't know why.......... Can't find the problem..... and everything seems right to me.

Any suggestions?



Access Decimal Values Return Only 0
Hopefully someone here has seen this problem, it's driving me crazy.

Very simple - I have a table "vehicle" in Access 2000 that has a field "vehOdometer" with data type number, field size decimal, precision 18, scale 0, decimal places auto, default value 0.

When I populate a dataset with "SELECT * FROM vehicle" using oledbdataadapter, the value of column "vehOdometer" is always 0 even though there's data in the database.

I've tried filling the dataset manually, using the visual studio tools to drag the table on the form but the values are always 0. This is driving me nuts.

Jason Trent

Edited by - jtrent on 10/4/2002 1:35:17 PM

How I Can Convert Decimal To Hexa Decimal??
I want to convert a decimal to hexadecimal in VB.

the value is more than signed32 bit.

i got one code ConvertDecimalToHexadecimal(ByVal Value As Double) from internet which is also giving overflow error.

Can anyone take up this challenge to help me out.

the decimal number for which i need hex(the number is a random generated one) = 11783197335

I need a quick response.

Thank you in advance

How To Check That A Number Is Negative Or Decimal???
i need to tell if the number in my textbox is a decimal or negative
how to change it first to a numeric since VB takes it as a string???
then do i use CDec?
ans for the negative number check?
pls help

Creating DWORDs To Windows Registry With Decimal Values
Hello, I'm using this code from APIList to write STRINGS to the registry. But I haven't been able to modify it to create DWORDs. Can anyone please help me?

Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_DYN_DATA = &H80000006
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_USERS = &H80000003

Public Const REG_SZ = 1 ' Unicode nul terminated string
Public Const REG_BINARY = 3 ' Free form binary

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long

Public Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
'retrieve nformation about the key
lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
If lResult = 0 Then
If lValueType = REG_SZ Then
'Create a buffer
strBuf = String(lDataBufSize, Chr$(0))
'retrieve the key's content
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
'Remove the unnecessary chr$(0)'s
RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
End If
ElseIf lValueType = REG_BINARY Then
Dim strData As Integer
'retrieve the key's value
lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
If lResult = 0 Then
RegQueryStringValue = strData
End If
End If
End If
End Function

Public Function GetString(hKey As Long, strPath As String, strValue As String)
Dim Ret
RegOpenKey hKey, strPath, Ret 'Open the key
GetString = RegQueryStringValue(Ret, strValue) 'Get the key's content
RegCloseKey Ret 'Close the key
End Function

Public Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim Ret
RegCreateKey hKey, strPath, Ret 'Create a new key
RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData) 'Save a string to the key
RegCloseKey Ret 'close the key
End Sub

Public Sub DelSetting(hKey As Long, strPath As String, strValue As String)
Dim Ret
RegCreateKey hKey, strPath, Ret 'Create a new key
RegDeleteValue Ret, strValue 'Delete the key's value
RegCloseKey Ret 'close the key
End Sub

Displaying Double Values In Grid, Decimal Problem
Hello, I am displaying a double value in a MSHFlexgrid. I get the value from an Access database. Here it is saved as Double, Fixed with 2 decimal places. When i put the value in the access database i have put it in using Round(x,2).

Even after doing all this when i display the value on the grid it comes out like 1.220000002. I cant imagine why this is happening. i just want to display 1.22 . Any ideas? Any suggestion is helpful.

Hello To Us, Check This Out A Little Code That Avoid Duplicate Decimal And Character!
'This is so easy to underst and it is alittle bit code.
'Hope will help us this code to all who wanted to know how to avoid duplicate decimal value and not allowing to type any characters.

Dim MyDot

MyDot = IIf(InStr(Text1.Text, ".") = 0, True, False)

If KeyAscii <> 8 Then

If MyDot = True Then

If (KeyAscii < 46) Or (KeyAscii > 57) Then

KeyAscii = 0

End If

MyDot = False


If (KeyAscii < 47) Or (KeyAscii > 57) Then

KeyAscii = 0

End If

End If

End If
giving me an ideas will appretiate it!!!
Alison Bros..

The Decimal Part Of A Decimal

How can I grab the decimal (non integer) part of a decimal number from a variable. The integer part I can do but I'm struggling to find a reference for other part.

e.g. 0.999 from 15.999.

Thanks in advance.

Yes, I am a newbie.

Sorry, wrong section I'm using VB .net

Whole Or Decimal
want to be able to test if a number is whole or not ( decimal), for VB6.
does any 1 know a simple way of doing this?

Just The Decimal, Please.
I need to strip the decimals from a bunch of numbers. Is there a function that would take the place of having to say x - int(x) every time?

Get Decimal Value
is there a build in function to get the decimal value of a double???

e.g. 43.09
i will get the 0.09 value...

Hex To Decimal
While researching colors I realised there IS a built in hex to decimal converter, it is just not obvious.

The simplest method is to draw a line on your form where it cannot be seen.

Set it's bordercolor to the hex value you want to change .
Then read that value back. It comes back as a decimal value.

a = "&H" & HexValue
Line1.BorderColor = a
a = Line1.BorderColor

For those who want a little hex to decimal converter, here is a project to compile.

Decimal Help
I'd Like to be able to display Decimals to the 15th point, or maybe further...whats the furthest it can go and what would I put to make it go that far?

Decimal 2 Hex Help Very Big N#
any ezzy function can convert big decimal N# to hex
pls tks

that is big exampl N#

8264470543703672940531618379948168270521787184122247955283844184452808 4812093331373663439564688277341566847502754337778272468800909743226426 227

u can email me @

After Decimal
Hi all,

I want To Take The Three to Four Digits After The Decimal.
Is There Any Function For That ?
actually I want To Calculate The Amount And I Want The Exact Amount After All The Calculations.

Pls Givee Me Any Suggestion .

Hi im a newbie at VB.

I´m working with VB 6.0, and my first project is to make a calculator, as so many else :-).

but i got some problems.

When i take pi which is = 3.141592654 and just * with any other number, f.exa. 3,14156 * 2 = 6.
I only get hole number, and i cant see what I am doing wrong because i am dim pi as a const at 3.141592654 .
and i can calculate with other numbers if i take 2,34 * 2,45 ill get 5,733. it works.
And the calculation var is integer, have also tried single. ?

How can i get the keyboard to work, when i press f.ex. 2 I want a 2 to appear in the window of the calculator, and when i pres f.exa. + it want +to work. ?

and last i cant find any code, so i can push the off button, that i did make, so that the program can shutdown?

plz help me, i have to show the calculator for the class tomorow irts my project.

And sorry for my poor english, im trying ... Benjamin Denmark

HEX Value To Decimal
anyone know how to take a hex value, say 5B, and convert it to decimal? i converted an integer to hex using something like:


which gave me a string similar to 5B...anyone know how to change it back? functions like CInt() and Val () don't work b/c they view the expression as the string "5B"...

Hex To Decimal
Dear Users,

Normally i will use the HEX( ) to get the hex representation from a normal numbers.

Is there any function that will reverse back that process
(such as Hexadecimal value to Decimal value).?

Thanks & Regards;

I am getting value of 40833.0 displaying in my VB textbox, generating from another program. Now I wanted to move decimal at -3, turning it into 40.8. How do I do this with VB code?

I tried divididng by 1000 and I get round off to 41.0... Actually I want precise number "40.8. Anyone?

this is the code string
CurValue = 6122 * 6.67 = 40833.0 ---> wanted 40.8

Hi everyone,
i created 10 textboxes where when i enter data in one it calculate results in the others, what i wanted to do is when i enter the data in say text box one then it shifts the decimals points 4places, ie type in 12345 and when i press tab to go to next box then the result would be 1.2345
i tred something like this but obviously i am wrong cause it only shifts the decimal point in that box and not the others

Private Sub OpenPrice_LostFocus()
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 4) & "." & Right(Text1.Text, 4)
end sub

Hex To Decimal
Hello all!!

Does anyone know why when I try to convert hex to decimal I get the wrong value? When I convert the hex value (815C) I get (-32420)..... Duno? Any help would be appreciated. Thanx in advance.

Function CHEX2DEC(HexNum) As long
CHEX2DEC = Val("&h" & HexNum)
End Function

Decimal To HEX
Hi to all
i have a combobox and list box
combobox having different decimal numbers
and i want to add items to listbox such a way that if i click any number(decimal) in combobox then it add a item in the listbox in HEX coresspondingly and finally add these HEX number and return in a variable.

Again With Decimal...........
i am able to validate decimal input with TextBox. I used the following codings so that only 2 numbers are allowed aftr decimal.also, only 1 decimal is allowed in a textbox.

VB Code:
Option ExplicitDim k, s, c Private Sub Text1_Change()If Len(Text1.Text) = s ThenCommand1.SetFocusEnd IfEnd Sub Private Sub Text1_KeyPress(KeyAscii As Integer)k = Chr(KeyAscii) Like "[0-9]" If KeyAscii = 46 And c >= 1 ThenKeyAscii = 0End If If KeyAscii = 46 Thens = Len(Text1.Text) + 3c = c + 1End IfEnd Sub

the problem arises when i use backspace.i am unable to type Decimal point again.

hw shud i track whether decimal point is being erased or that aftr typing decimal point for second time{(ie)aftr erasing first one using backspace},only 2 digits are allowed aftr it.

plzzzz help me solve this.

Hex To Decimal
Can anyone help me please?

I am trying to convert a Hex value into an decimal, i am using a variable so i cannot use:

VB Code:

is there a quick function to do this?

Hex To Decimal
say i read some variables such as

just a example

i read them in as strings but i want to convert them to decimal


how would this be done in VB ? im actually using C++ but the VB Code will help.

Right Of Decimal
OK I know this should be easy, but I just can't remember.
How do I return the number of places to the right of a decimal?

Eg. 5.0252
I would like to know that there are 4 characters to the right of the decimal.

Thanks in advance.

Hex To Decimal
to go from a decimal into a hex


but how do I go the other way?

Hex To Decimal??
can anyone help me, please?
how to convert from a hexadecimal number to a decimal in VB?

thanks a lot,

Decimal To Hex :S
how to convert decimal to hex?

Hex To Decimal
Does anyone know of a quick piece of code, or built in function to convert a hex string to a decimal number?

Decimal To Hex
Right how can i take a Decimal Value

and change it to its hex value



Hex To Decimal
Before people start B**chin at me.... i know this has been asked before... im just to lazy to look around...
But whats the code to go from Hex to Decimal (or regular numbers). Becuase i know if u go...


That it will give u a hex to a number... but i want the other way around.

Thanks alot

I store some variables in a INI to eksample a=0,12345; b = -0,3215
I juse the comma as dicimal point. Then I have a problem if my computer Use US Keyboard Where the decimal point is a Point,
How du I format this so I Read the the decimal point corect depend of the country code.

Decimal Help
Hello vb-world

i'm a pretty new at vb so go slow. I'm trying to format a textbox entry, if a user enters a number such as .533 i want to be able to change it 0.533 however if a user enters 1.00 i want to leave it that way. any help would be greatly appreciated.

Decimal To Hex Or Hex To Decimal
hi there,

how do i do this ?


I am creating a Calculator.All most all i have Completed.I have Problem With Decimal(.)anybody tell me how to put (.)only one time in text box after pressed a sign or number.


Decimal To Hex
I know that it's easy to convert a decimal value to Hex using:

HexValue = Hex(DecimalValue)

That's fine, until I have a very large decimal value like:

123456789877754 (which is basically of DataType Variant, with a CDec conversion)

This causes an overflow when trying to convert to Hex.

 I've trawled through various threads, which seem to mainly deal with the issues of Hex to Decimal (and which I have under control!)

Any ideas?

Before And After Decimal?
Is it possible to do something like this:

yes = Instr(SearchString, [0-9].[0-9])

I need to see if there is a number before and after the decimal. ANy ideas?


Copyright © 2005-08, All rights reserved