Convert from Fractional to Decimal Numbers

Convert from Fractional to Decimal Numbers

While developing a database front end for hand-tool management, I discovered a need to handle both fractional and decimal representations of dimensions in the same text box. This makes it easier on users who worked from a variety of prints to input part feature sizes. To accomplish this, place this function in the LostFocus event of any text box that can receive numerical input. You can also cycle through the appropriate text boxes and run the function against the text value of each. In addition, this function only checks for the inches character (double quotes) at the end of the text string of fractional dimensions. It also looks for spaces and/or dashes between whole numbers and fractions and checks for both forward and backward slashes within fractions. It doesn’t work with negative values:

 Private Function ReturnDecimalValue(Size As _	String) As String	Dim strSize As String	Dim iGap As Integer	Dim iSlash As Integer	Dim sWhole As Single	If Size <> "" Then Size = LTrim(RTrim(Size))	'previous code may have stripped text to nothing 	'if it was just spaces, so test	If Size <> "" Then		'strip off inch character (double 		'quotes) if it's there		If Right(Size, 1) = Chr$(34) Then _			Size = Left(Size, Len(Size) - 1)		iGap = InStr(Size, "-")		If iGap = 0 Then iGap = InStr(Size, " ")		If iGap Then sWhole = CSng(Left(Size, iGap - 1))		strSize = Right(Size, Len(Size) - iGap)		iSlash = InStr(strSize, "/")		'user may have input backward slash 		'in fraction instead of forward slash; 		'verify		If iSlash = 0 Then iSlash = InStr(strSize, "")		'convert result to decimal form for 		'saving in database		If iSlash Then Size = CStr(sWhole + _			(CSng(Left(strSize, iSlash - 1)) / _			CSng(Right(strSize, Len(strSize) - iSlash))))	End If	ReturnDecimalValue = SizeEnd Function
Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as