Ok guys, This is a quick overview of what I'm trying to do. 2 textboxes. textbox1 has a fraction entered by the user into it in one of these 2 ways
1(space)3/4 or simply 3/4
Now what this code is supposed to do is get the length of the entry ans tear it apart storing any numbers found in the string. These are later used to turn the fraction entered into a ecimal equivelent. (Note) i know I can do this with 3 boxes by having a whole #,numerator, and denominator box I allready have. But I would like to have only 1 box for the entry. Below is what I have come up with so far (with notations) But it doesn't seem to be reading the string at all. when i run it I get "NaN" in textbox2. Any ideas would be greatly appreciated.
[/vb]
2 1660
Ok guys, This is a quick overview of what I'm trying to do. 2 textboxes. textbox1 has a fraction entered by the user into it in one of these 2 ways
1(space)3/4 or simply 3/4
Now what this code is supposed to do is get the length of the entry ans tear it apart storing any numbers found in the string. These are later used to turn the fraction entered into a ecimal equivelent. (Note) i know I can do this with 3 boxes by having a whole #,numerator, and denominator box I allready have. But I would like to have only 1 box for the entry. Below is what I have come up with so far (with notations) But it doesn't seem to be reading the string at all. when i run it I get "NaN" in textbox2. Any ideas would be greatly appreciated.
[/vb]
nevermind guys i found a way to do it from another angle using "IndexOf"
Here's what I wound up with -
-
' on button click event
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
' Set my variables
-
Dim WholeNumber As Integer
-
Dim Numerator As Integer
-
Dim Denominator As Integer
-
Dim StoreVariable1 As Integer
-
Dim StoreVariable2 As Integer
-
Dim StoreVariable3 As Integer
-
Dim space1 As Integer
-
Dim slash1 As Integer
-
Dim DecimalNumber As Double
-
-
' look for the space in the entry
-
space1 = TextBox1.Text.IndexOf(" ")
-
-
' runs if there is no space found
-
If Not (space1 >= 0) Then
-
-
'looks for a slash in the entry
-
slash1 = TextBox1.Text.IndexOf("/")
-
' stores what it finds from the beginning to the slash as a number
-
StoreVariable2 = TextBox1.Text.Substring((space1 + 1), (slash1 - (space1 + 1)))
-
'looks at everything after the slash then stores that as a number
-
StoreVariable3 = TextBox1.Text.Substring(slash1 + 1)
-
-
' does the same as the if not but only when a space is found
-
Else
-
-
-
StoreVariable1 = TextBox1.Text.Substring(0, space1)
-
-
slash1 = TextBox1.Text.IndexOf("/")
-
-
StoreVariable2 = TextBox1.Text.Substring((space1 + 1), (slash1 - (space1 + 1)))
-
-
StoreVariable3 = TextBox1.Text.Substring(slash1 + 1)
-
-
End If
-
' this if else places the stored values into the proper place and does appropriate math
-
If (space1) = Nothing Or (space1 <= 0) Then
-
-
Numerator = StoreVariable2
-
Denominator = StoreVariable3
-
DecimalNumber = (Numerator / Denominator)
-
TextBox2.Text = (DecimalNumber)
-
-
Else
-
-
WholeNumber = StoreVariable1
-
Numerator = StoreVariable2
-
Denominator = StoreVariable3
-
DecimalNumber = ((Numerator / Denominator) + (WholeNumber))
-
TextBox2.Text = (DecimalNumber)
-
-
End If
-
-
End Sub
-
It's probably over coded so going to try to clean it up. Works perfectly though.
nevermind guys i found a way to do it from another angle using "IndexOf"
Here's what I wound up with -
-
' on button click event
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
' Set my variables
-
Dim WholeNumber As Integer
-
Dim Numerator As Integer
-
Dim Denominator As Integer
-
Dim StoreVariable1 As Integer
-
Dim StoreVariable2 As Integer
-
Dim StoreVariable3 As Integer
-
Dim space1 As Integer
-
Dim slash1 As Integer
-
Dim DecimalNumber As Double
-
-
' look for the space in the entry
-
space1 = TextBox1.Text.IndexOf(" ")
-
-
' runs if there is no space found
-
If Not (space1 >= 0) Then
-
-
'looks for a slash in the entry
-
slash1 = TextBox1.Text.IndexOf("/")
-
' stores what it finds from the beginning to the slash as a number
-
StoreVariable2 = TextBox1.Text.Substring((space1 + 1), (slash1 - (space1 + 1)))
-
'looks at everything after the slash then stores that as a number
-
StoreVariable3 = TextBox1.Text.Substring(slash1 + 1)
-
-
' does the same as the if not but only when a space is found
-
Else
-
-
-
StoreVariable1 = TextBox1.Text.Substring(0, space1)
-
-
slash1 = TextBox1.Text.IndexOf("/")
-
-
StoreVariable2 = TextBox1.Text.Substring((space1 + 1), (slash1 - (space1 + 1)))
-
-
StoreVariable3 = TextBox1.Text.Substring(slash1 + 1)
-
-
End If
-
' this if else places the stored values into the proper place and does appropriate math
-
If (space1) = Nothing Or (space1 <= 0) Then
-
-
Numerator = StoreVariable2
-
Denominator = StoreVariable3
-
DecimalNumber = (Numerator / Denominator)
-
TextBox2.Text = (DecimalNumber)
-
-
Else
-
-
WholeNumber = StoreVariable1
-
Numerator = StoreVariable2
-
Denominator = StoreVariable3
-
DecimalNumber = ((Numerator / Denominator) + (WholeNumber))
-
TextBox2.Text = (DecimalNumber)
-
-
End If
-
-
End Sub
-
It's probably over coded so going to try to clean it up. Works perfectly though
Sign in to post your reply or Sign up for a free account.
Similar topics
by: john67 |
last post by:
The company I work for is about to embark on developing a commercial
application that will cost us tens-of-millions to develop. When all is
said and done it will have thousands of business...
|
by: Dave Turner |
last post by:
I know that its impossible to completely prevent somebody from ripping a
site (or cracking software) if that person has the skills and the
time/patience, but there are tricks that can be employed...
|
by: mt |
last post by:
Hi,
W H A T
I am considering moving my windows app written in Visual C++ 6.0 to C# .NET.
Q U E S T I O N
I was wondering if application speed will be a problem in .NET when compared
to a...
|
by: Deano |
last post by:
Hi,
I have a finished Microsoft Access app that we are distributing using an
Access runtime. This works fine (mostly) but I'm sold on the advantages of
dot.NET and upgrading to vb.NET seems...
|
by: noridotjabi |
last post by:
I'm working on a prompt style thing and I need a way to pass arguments
to commands within my program. For example:
::hello -v -r -n
If this is entered as one input string, can I (in any...
|
by: M O J O |
last post by:
Hi,
I've have searched google, but can't find a solution to my problem.
Om my develloper machine, I use one app.config, but when I deploy, I need to
deploy another app.config.
The reason...
|
by: =?Utf-8?B?QnJhZA==?= |
last post by:
im trying to create a vfp app that can talk to a vb 2005 app to launch forms
basically, i want to tell the vfp app to launch a form when they select an
option from the vb menu that hasnt been...
|
by: PromisedOyster |
last post by:
We have an executable that uses an App.Config file to hold things such
as database connection strings etc.
We now want to write a wrapper DLL around that executable to expose
functionality to...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
| |