Help with Integer

srjc98

New member
Joined
Feb 21, 2007
Messages
2
Programming Experience
Beginner
Hi everybody;
I am new in any programming language. I like VB.Net

I am doing this program, but even thought I give lbl1 lbl2 lbl3 lbl4 as Integer, it still shows in the result as float. I want to be Integer.

Could you guys help me please!!! :( :(

this is my code.

[FONT=&quot]Public[/FONT][FONT=&quot] Class frmDigitExtractor[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub lblExtractDigit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblExtractDigit.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Dim fifth As Integer[/FONT]
[FONT=&quot] Dim fourth As Integer[/FONT]
[FONT=&quot] Dim third As Integer[/FONT]
[FONT=&quot] Dim second As Integer[/FONT]
[FONT=&quot] Dim first As Integer[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] fifth = lbl5.Text[/FONT]
[FONT=&quot] fourth = lbl4.Text[/FONT]
[FONT=&quot] third = lbl3.Text[/FONT]
[FONT=&quot] second = lbl2.Text[/FONT]
[FONT=&quot] first = lbl1.Text[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] lbl5.Text = fifth Mod 10[/FONT]
[FONT=&quot] lbl4.Text = fifth / 10 Mod 10[/FONT]
[FONT=&quot] lbl3.Text = fifth / 100 Mod 10[/FONT]
[FONT=&quot] lbl2.Text = fifth / 1000 Mod 10[/FONT]
[FONT=&quot] lbl1.Text = fifth / 10000 Mod 10[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub txtInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInput.TextChanged[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub lbl5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl5.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub lbl4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl4.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub lbl3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl3.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub lbl2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl2.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] Private Sub lbl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] End Sub[/FONT]
[FONT=&quot]End[/FONT][FONT=&quot] Class[/FONT]
 
Try this

If (Integer.TryParse(Me.lbl1.Text, first)) Then
msgbox ("It Works")
End If

'''''' Pls Send me the result '''''''
 
Hi Behrooz,
I just tried, and the result still gives me as float number.

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

If (Integer.TryParse(Me.lbl1.Text, first)) Then
MsgBox("It Works")
End If

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

lbl5.Text = txtInput.Text Mod 10
lbl4.Text = txtInput.Text / 10 Mod 10
lbl3.Text = txtInput.Text / 100 Mod 10
lbl2.Text = txtInput.Text / 1000 Mod 10
lbl1.Text = txtInput.Text / 10000 Mod 10
 
Hi,

This is normal behaviour since fifth Mod 10 will perform an implicit cast to a float.

There are multiple solutions to solve this:
- perform an explicit cast to int:
Label3.Text = CType(fifth / 100 Mod 10, Integer)

- use the ToString with a formatting:
Label3.Text = (fifth / 100 Mod 10).ToString("N0")

Greetz,

Geert
 
Back
Top