473,791 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert string expression to value?

MLH
I have this expression in a query ...
Trim$(Left$([RawData],[FirstQuote]-1))

It evaluates to "1/16"

How can I convert that to the numeric value 0.0625?
Nov 13 '05 #1
5 7236
MLH
BTW, I tried CDbl(Trim$(Left $([RawData],[FirstQuote]-1)))
and it gave me an error.
Nov 13 '05 #2
MLH wrote:
I have this expression in a query ...
Trim$(Left$([RawData],[FirstQuote]-1))

It evaluates to "1/16"

How can I convert that to the numeric value 0.0625?


The Eval function might suffice if your [RawData] always starts with a
fraction.

James A. Fortune

Nov 13 '05 #3
Hi
I have this expression in a query ...
Trim$(Left$([RawData],[FirstQuote]-1))
It evaluates to "1/16"
How can I convert that to the numeric value 0.0625?


Try the function <Frac2Num> ( found in MS samples) :

Regards
Jens

-----------------------------------------

Function Frac2Num(strX As String) As Double
'
' Frac2Num("2/5") = 0.4
' Frac2Num("3 1/2") = 3.5
' Frac2Num("1/16") = 0.0625

Dim Temp As String, P As Integer, N As Double, Num As Double, Den As Double
If VarType(strX) < 2 Or VarType(strX) = 7 Then
Frac2Num = Null
ElseIf VarType(strX) <> 8 Then
Frac2Num = strX
Else
Temp = Trim$(strX)
P = InStr(Temp, " ")
If P = 0 Then
If InStr(Temp, "/") = 0 Then
N = Val(Temp)
Else
N = 0
End If
Else
N = Val(Left$(Temp, P - 1))
Temp = Mid$(Temp, P + 1)
End If
P = InStr(Temp, "/")
If P <> 0 Then
Num = Val(Left$(Temp, P - 1))
Den = Val(Mid$(Temp, P + 1))
If Den <> 0 Then
N = N + Num / Den
End If
End If
Frac2Num = N
End If
End Function
Nov 13 '05 #4
MLH
Perfect! Yes, they ALL start with a fraction.
Eval = the best alternative. Thx Mr Fortune.
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxx
On 25 Sep 2005 22:17:03 -0700, ji********@comp umarc.com wrote:
MLH wrote:
I have this expression in a query ...
Trim$(Left$([RawData],[FirstQuote]-1))

It evaluates to "1/16"

How can I convert that to the numeric value 0.0625?


The Eval function might suffice if your [RawData] always starts with a
fraction.

James A. Fortune


Nov 13 '05 #5
MLH
Thx, Jens. But its hard to beat the 1-liner Eval.
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18029
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript function and have JS put this into an array. Then JS would use this array to create a selection list which displays only the names of the drugs. When the user selections one of the drugs, another selection list will be loaded with the avaiable...
4
9772
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
3
1836
by: David | last post by:
for example: int x=10; char *str="\"x=%d\",x"; if I use printf(expression(str)); then the results is x=10 even I know it's not easy to return a expression from a function.
19
11311
by: caramel | last post by:
i've been working on this program forever! now i'm stuck and going insane because i keep getting a syntax error msg and i just can't see what the compiler is signaling to! #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h>
2
13038
by: MarkusJNZ | last post by:
Hi, I have a textbox in an asp.net app and all I want to do is store the value of the textbox in a short if there is a value in the text box; I came up with the following (Where txtID is a asp.net textbox control) short ID = (txtID.Text != string.Empty ? short.Parse(txtID.Text) : 0); But I get the following error
4
25069
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. Anybody please help in c language. Thanks in Advance.
1
2190
by: Michel Walsh | last post by:
In the same spirit, but more LINQ related, you can also use ExecuteQuery: var query = dataContext.ExecuteQuery<className>( @"SELECT ... WHERE ... AND... OR... "); where className is appropriate to recuperate the result of your dynamically built SQL statement, as a string.
6
2038
by: priravi | last post by:
Hi, I'm having a numeric expression say "((2*3)-(3*4+5))" returned from a method as a string value... now i have to evaluate the expression and store it in an integer vaariable. Convert.toint or int.parse is not working and since i'm new to .net development i have no idea of how else to convert this.Please do help me regarding this
1
8839
by: pankajprakash | last post by:
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this code in vb.net it returns 1.0E5 I need the same expression for the c#. I am using the following code String.Format("{0:E}", 100000) and its returns 1.000000E+005, but I need 1.0E5. The same for the another value String.Format("{0:E}",...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.