|
Your time now: Mon Nov 23, 2009 3:17 pm
|
View unanswered posts | View active topics
| Author |
Message |
|
valleygirl1919
|
Post subject: I am in need of desperate help with this visual basic prob Posted: Mon Sep 28, 2009 2:49 am |
|
Joined: Mon Sep 28, 2009 2:22 am Posts: 1
|
|
I am struggling with my first programming class and need some help with writing the code to run this program....
"this is my question I need help with " write a program that requests a positive number containing a decimal point as input and then displays the number of digits to the left of the decimal point and the number of digits to the right of the decimal point."
Can anyone help me with this code
|
|
| Top |
|
 |
|
Trill
|
Post subject: Re: I am in need of desperate help with this visual basic prob Posted: Wed Oct 07, 2009 3:47 pm |
|
Joined: Wed Oct 07, 2009 3:11 pm Posts: 2
|
|
Hi you could do some thing like this:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Counter_left As Integer = 0 Dim Counter_right As Integer = 0 Dim My_positive_number As String Dim count As String = "left"
My_positive_number = TextBox1.Text 'your positive number with decimal
For x As Integer = 1 To Len(My_positive_number) If Mid(My_positive_number, x, 1) = "." Then count = "right" If count = "left" Then Counter_left = Counter_left + 1 Else Counter_right = Counter_right + 1 Next
If count = "left" Then ' Check to see if number had a decimal MsgBox("please enter a positive number with a decimal") Else
MsgBox("Left of decimal: " & Counter_left & " Righr of decimal: " & Counter_right - 1)
TextBox2.Text = Counter_left TextBox3.Text = Counter_right - 1 End If End Sub End Class
all you have to do is put 3 text boxes and a button TextBox1 to input the number 2 & 3 to display the number of digits Hope this helps
Mr Trill
|
|
| Top |
|
 |
|
bytelogik
|
Post subject: Re: I am in need of desperate help with this visual basic prob Posted: Sat Oct 17, 2009 2:30 pm |
|
Joined: Tue Oct 06, 2009 8:24 pm Posts: 7
|
|
Try this:
Dim n As String Dim location As Integer,lenOfString As Integer Dim DecimalLeft As Integer, DecimalRight As Integer
n = "1.234567" lenOfString = Len(n) location = InStr(n, ".") 'returns the position of decimal point
DecimalLeft = location - 1 DecimalRight = (lenOfString - DecimalLeft) - 1 MsgBox DecimalLeft & ", " & DecimalRight
Hope this helps.
|
|
| Top |
|
 |
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|