It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming Visual Basic Forum

I am in need of desperate help with this visual basic prob

Moderator: dafunkymunky

I am in need of desperate help with this visual basic prob

Postby valleygirl1919 on Mon Sep 28, 2009 2:49 am

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
valleygirl1919
 
Posts: 1
Joined: Mon Sep 28, 2009 2:22 am

Re: I am in need of desperate help with this visual basic prob

Postby Trill on Wed Oct 07, 2009 3:47 pm

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
Trill
 
Posts: 2
Joined: Wed Oct 07, 2009 3:11 pm

Re: I am in need of desperate help with this visual basic prob

Postby bytelogik on Sat Oct 17, 2009 2:30 pm

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.
bytelogik
 
Posts: 7
Joined: Tue Oct 06, 2009 8:24 pm


Who is online

Users browsing this forum: No registered users and 0 guests