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 1675
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 objects/classes, some
of which will have hundreds-of-thousands of instances stored in a DB.
Our clients will probably have somewhere between 50-200 users working
on the app during the day, possibly in mutiple offices, and then a
large number of batch...
|
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 in software which
slow crackers down, from things like self-decrypting code to anti-debug
tricks, and most people have a breaking point - if you can slow them down
and waste enough of their time they usually move on to easier targets (and
as there...
|
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 VC++6? Am I going to take a big performance hit?
|
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 like a good idea for the future. I'm
also keen to develop new software in vb.NET as soon as possible.
I will work out how to port the app and how to use ado.NET etc, however I'm
not certain about all the things I need to consider hence the...
|
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 simple way) break
it apart so I have something like:
str = "hello"
str = "-v"
| |
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 is, that on my develloper machine, my app.config sqlconnection is
pointing to my (local) database and I have several settings like
"Debug=True", but when I deploy (using ClickOnce), I need to use an
|
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 converted to vb yet...
any suggestions???
|
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 integrate with another app.
Therefore we aim to have one new executable talking to the wrapper DLL
that in turn talks to the original app. Although the original app is
an executable, it can be treated like a DLL.
|
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: 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,...
|
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: 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...
|
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...
|
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
| |