English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Please help me. I need to do this program that every time the users enter any numbers, those numbers shows in a lable digit per digit. Here is an example
Users enter 12345
the computer shows that number in five different labels as:
1 2 3 4 5
I have this code but, the result in giving me as decimal. I do not want decimal. I want integer. Here is my code

2007-02-23 03:40:08 · 3 answers · asked by yo m 1 in Computers & Internet Programming & Design

Public Class frmDigitExtractor

Private Sub lblExtractDigit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblExtractDigit.Click

End Sub

Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click


Dim fifth As Integer
Dim fourth As Integer
Dim third As Integer
Dim second As Integer
Dim first As Integer

fifth = lbl5.Text
fourth = lbl4.Text
third = lbl3.Text
second = lbl2.Text
first = lbl1.Text

lbl5.Text = fifth Mod 10
lbl4.Text = fifth / 10 Mod 10
lbl3.Text = fifth / 100 Mod 10
lbl2.Text = fifth / 1000 Mod 10
lbl1.Text = fifth / 10000 Mod 10

2007-02-23 03:40:57 · update #1

Private Sub txtInput_TextChanged(ByVal sender As System.Object , ByVal e As System.EventArgs) Handles txtInput.TextChanged


End Sub

Private Sub lbl5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl5.Click

End Sub

Private Sub lbl4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl4.Click

End Sub

Private Sub lbl3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl3.Click

End Sub

Private Sub lbl2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl2.Click

End Sub

Private Sub lbl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click

End Sub
End Class

2007-02-23 03:41:11 · update #2

3 answers

Just fix your calucations. E.g.:

lbl1.Text = Fix((fifth / 10000) Mod 10)

2007-02-23 03:44:57 · answer #1 · answered by Anonymous · 2 0

I suggest this function, from the top of my head (not tested):

Public Function SplitDigits(ByVal n As Decimal) As Char()
Dim s As String = CStr(CInt(n))
Return s.ToCharArray()
End Function

Then, use each element to fill the Text property of each label; use an array, please, like

Private digit As Label()

digit(0) = New Label

Initialize it, and fill it somewhere. It's more elegant than declaring five unrelated Labels.

2007-02-23 13:05:33 · answer #2 · answered by jcastro 6 · 2 0

Convert the results to an integer. That will get rid of the decimal. You can use either CINT or Convert.ToInt32 functions to accomplish this.

2007-02-23 11:48:02 · answer #3 · answered by Scottee25 4 · 3 0

fedest.com, questions and answers