I need to convert a string to a integer. I tryed to use the Val() Function
but the i need the string to be added. The string is "(x+3)^2" where the x
is a part of the for/next statement. And i used a statement like y =
replace(y, "x", x) to replace the x in the tring to a number. But when I use
the Val() function it only grabs the first number. Is there a function or
piece of code that i can use to change the sting to a integer and doing the
math? It would be greatly appreciated.
-Julien 7 2865
"John MacDonald" <jm****@sympati co.ca> wrote in message
news:4A******** ***********@new s20.bellglobal. com... I need to convert a string to a integer. I tryed to use the Val() Function but the i need the string to be added. The string is "(x+3)^2" where the x is a part of the for/next statement. And i used a statement like y = replace(y, "x", x) to replace the x in the tring to a number. But when I
use the Val() function it only grabs the first number. Is there a function or piece of code that i can use to change the sting to a integer and doing
the math? It would be greatly appreciated.
-Julien
Can you post the exact code snippet for what you are trying to do? It might
help us help you, you know? :)
Ken un*****@hotmail .nospam.com
"John MacDonald" <jm****@sympati co.ca> wrote in message
news:oH******** ***********@new s20.bellglobal. com... I understand that no one understands the problem that i am having do to the explination so I created a small piece of code that contains my problem. I have attached the program to this
message and i have wrote out the program below if you dont trust downloading files do to the virus going around.
-In Visual Basic 6.0 create a form. -Add to this form a TextBox a CommandButton and a ListBox -then add this peace of code to the program
Private Sub Command1_Click( )
y = Text1.Text For x = 1 To 10 z = Replace(y, "x", x) List1.AddItem y
OK, this is part one. When you type the assignment statement
'z=Replace(y,"x ",x) that is telling Visual Basic to search the string (y)
for the value "x" and replace it with (x) and then place the resultant
string into (z) ... so change z to z1 and replace the y in the next line
(List1.AddItem y) to z1. That will at least have the Listbox showing the
formula correctly.
'At this point i would like to do the math that is in 'Text1.Text z = Val(y)
All Val() does is return the numeric portions of a string minus any
extrenuous characters. In this case, Val("(1+3)^2") sees the first
parenthesis and returns the value of 0 since it didn't see any numbers
before that parenthesis. If you remove the parenthesis, it will only return
the value which is before the + symbol, since it doesn't recognize that as a
number. Also, the (y) here should be replaced with (z1) as per the previous
explanation.
In order to do what you are trying to do, you would have to parse the string
yourself and perform any math functions involved. I am not aware of any
functions included with VB which will parse a string and perform the math
for you. I am sure than someone else in this group could tell me if I am
wrong about that ... so let them speak now or forever hold their peace.
'Should state the answer to the above AddItem in List1 List1.AddItem z Next x
'This is not the program that i am stuck on but this gives 'an example where I run into my problem 'Help Would be appresiated 'Julien End Sub
-when you run the program input the equation "(x+3)^2"
The problem that I am having is that the number under the equation
should be the answer but it keeps telling me the answer is 0. If someone could help me it will be greatly appresiated.
Thank you, Julien
Ken un*****@hotmail .nospam.com
"Trousle Undrhil" <un*****@hotmai l.nospam.com> wrote In order to do what you are trying to do, you would have to parse the string yourself and perform any math functions involved. I am not aware of any functions included with VB which will parse a string and perform the math for you. I am sure than someone else in this group could tell me if I am wrong about that ... so let them speak now or forever hold their peace.
Dim Z
With ScriptControl1
.AddCode "X = 3"
.AddCode "Y = 1"
Z = .Eval("(X + Y) ^ 2")
End With
MsgBox Z ' 16
The ScriptControl can parse the string and evaluate the expression.
LFS
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Every time i try to run your piece of code, i get an "Object Required"
error. Is there a file that i need to download to let this piece of code
work?
Thank you so much everyone for your help.
-Julien
"Larry Serflaten" <Ab***@SpamBust ers.com> wrote in message
news:40******** @corp.newsgroup s.com... "Trousle Undrhil" <un*****@hotmai l.nospam.com> wrote
In order to do what you are trying to do, you would have to parse the
string yourself and perform any math functions involved. I am not aware of
any functions included with VB which will parse a string and perform the
math for you. I am sure than someone else in this group could tell me if I
am wrong about that ... so let them speak now or forever hold their
peace.
Dim Z
With ScriptControl1 .AddCode "X = 3" .AddCode "Y = 1" Z = .Eval("(X + Y) ^ 2") End With
MsgBox Z ' 16
The ScriptControl can parse the string and evaluate the expression.
LFS
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Larry Serflaten Every time i try to run your piece of code, i get an "Object Required" error. Is there a file that i need to download to let this piece of code work?
The ScriptControl is not in the VB toolbox by default. You have to
add it in from the Project>Compone nts menu (Ctrl-T) dialog. Once
you add the control to the toolbox, you treat it like any other control,
if you want to use it, you have to put one on the form.
LFS
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
"Trousle Undrhil" <un*****@hotmai l.nospam.com> wrote in message
news:HZ******** *********@bigne ws5.bellsouth.n et... "John MacDonald" <jm****@sympati co.ca> wrote in message news:oH******** ***********@new s20.bellglobal. com...
<< SNIP >>
OK, this is part one. When you type the assignment statement 'z=Replace(y,"x ",x) that is telling Visual Basic to search the string (y) for the value "x" and replace it with (x) and then place the resultant string into (z) ... so change z to z1 and replace the y in the next line (List1.AddItem y) to z1. That will at least have the Listbox showing the formula correctly.
OK ... with the ScriptControl, this part is still the same. 'At this point i would like to do the math that is in 'Text1.Text z = Val(y)
All Val() does is return the numeric portions of a string minus any extrenuous characters. In this case, Val("(1+3)^2") sees the first parenthesis and returns the value of 0 since it didn't see any numbers before that parenthesis. If you remove the parenthesis, it will only
return the value which is before the + symbol, since it doesn't recognize that as
a number. Also, the (y) here should be replaced with (z1) as per the
previous explanation.
Instead of using z = Val(z1), use z = ScriptControl1. Eval(z1). Then
follow-up with the rest of the code to add z to the listbox.
In order to do what you are trying to do, you would have to parse the
string yourself and perform any math functions involved. I am not aware of any functions included with VB which will parse a string and perform the math for you. I am sure than someone else in this group could tell me if I am wrong about that ... so let them speak now or forever hold their peace.
This is working now thanks to Larry Serflaten and the idea of using the MS
Script Control! :) :) :) 'Should state the answer to the above AddItem in List1 List1.AddItem z Next x
'This is not the program that i am stuck on but this gives 'an example where I run into my problem 'Help Would be appresiated 'Julien End Sub
-when you run the program input the equation "(x+3)^2"
The problem that I am having is that the number under the equation should be the answer but it keeps telling me the answer is 0. If someone could help me it will be greatly appresiated.
Thank you, Julien
Ken un*****@hotmail .nospam.com
Thank you very much my program is working great now. Thank you Larry and
Ken.
-Julien
"Larry Serflaten" <Ab***@SpamBust ers.com> wrote in message
news:40******** @corp.newsgroup s.com... Larry Serflaten
Every time i try to run your piece of code, i get an "Object
Required" error. Is there a file that i need to download to let this piece of
code work?
The ScriptControl is not in the VB toolbox by default. You have to add it in from the Project>Compone nts menu (Ctrl-T) dialog. Once you add the control to the toolbox, you treat it like any other control, if you want to use it, you have to put one on the form.
LFS
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =----- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Golan |
last post by:
Hello,
I have a hexa file which I need to convert to decimal.
I use memcpy into variables (char for one octet, short for 2 octets
and int for 4 octets) and then print the value into the file by using
fprintf.
The problem is that I don't know how to convert a field of 6 octets?
Should I use a long variable?
Thanks
|
by: Frederik Vanderhaeghe |
last post by:
Hi,
I have a problem converting text to a double. Why doesn't the code work:
If Not (txtdocbedrag.Text = "") Then
Select Case ddlBedrag.SelectedIndex
Case 0
Case 1
|
by: gg9h0st |
last post by:
i'm a newbie studying php.
i was into array part on tutorial and it says
i'll get an array having keys that from member variable's name
by converting an object to array.
i guessed "i can get public members but not protected, private, static
members"
|
by: Rob Meade |
last post by:
Hi all,
Ok - I've come from a 1.1 background - and previously I've never had any
problem with doing this:
Response.Write (Session("MyDate").ToString("dd/MM/yyyy"))
So, I might get this for example:
21/05/2006
|
by: stephen |
last post by:
Hi,
I have been working using VB .NET and I wanted to convert a code to C#
in VB .Net I use modules so that I can declare variables, STP holders so
that I can replace them easily when I move b/w Dev and Prod like this
Module modAVSVariables
'Arraylist and Array Variables
Friend pathArray As Array
Friend temp_arrAllFiles As Array
Friend getPath As ArrayList = New ArrayList
| |
by: coolindienc |
last post by:
I converted this program from using global variables to local variables. When I did that my while loop stopped working in my main function(module). Anyone, any idea why? I underlined the area where I think the problem occured after my changes.
Old Code working FINE
from math import *
def menu():
global menuSel
print "\nSlect one of the following:"
print "1. Calculate Area of Rectangle"
|
by: rpjd |
last post by:
Apache2 over XP Home, PHP5, PostgreSQL8.2
If this is not the correct forum for this, it can be reposted accordingly.
I have php variables/arrays that I want to display in a php webpage. What I am doing is using my server-side php script to generate javascript and convert my php data. The 1st bit of code is my php script, the 2nd is my javascript from my php webpage. I have 2 variables $numrows and $numfields, and 2 arrays $fieldname and...
|
by: dishal |
last post by:
Can anyone help me please? How do I convert these codes to launch from a JFrame instead of a Java Applet?
A simple program where the user can sketch curves and shapes in a
variety of colors on a variety of background colors. The user selects
a drawing color form a pop-up menu at the top of the
applet. If the user clicks "Set Background", the background
color is set to the current drawing color and the drawing
...
|
by: cmdolcet69 |
last post by:
Can anyone give me some ideas on how to convert the following program
to vb 2003? I would like to jsut take this code and implement it in
vb.
def.h
/* Global Type Definitions */
typedef unsigned char byte; // 'byte' is an 8-bit
unsigned value
|
by: sparks |
last post by:
After changing all the variables in a table from long to double.
you get 9.1====becomes==== 9.19999980926514
ok I checked microsoft and they had a workaround.
export the values to excel...then import them back into the new table.
well I tried that and get the same thing.
is there a work around for the work around LOL
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |