Separation by digit?

Wipf, Marley - DSU Student 21 Reputation points
2021-03-31T01:12:41.113+00:00

Hello I'm a little new to VB and needed some help with something.

I'm making a program which will separate a number with three digits, for example, 365 has three digits in it and I need to move the digits from this number to their own labels. Hundreds = 3, Tens = 6, Ones = 5 Now the one catch is I'm trying to do it without "if".

That being said. If their is no way to do it without an if statement then I will have to use one but its where I'm stuck now so if anyone has any ideas, I would be grateful.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,569 questions
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2021-03-31T03:38:05.103+00:00

    Here's another console example that digitizes an Integer
    of less than 1000 without converting ti to a String first:

    Dim number As Integer = 365
    Console.WriteLine(number \ 100)
    Console.WriteLine((number Mod 100) \ 10)
    Console.WriteLine((number Mod 100) Mod 10)
    
    • Wayne
    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. WayneAKing 4,921 Reputation points
    2021-03-31T03:23:30.4+00:00

    If the number is a String, here's one way to digitize it:

    Dim num As String = "365"
    For Each digit As Char In num
        Console.WriteLine(digit)
    Next
    

    This example assumes a console app. Obviously you would
    need to adapt it to your specific requirements re use
    of labels.

    • Wayne
    0 comments No comments

  2. Wipf, Marley - DSU Student 21 Reputation points
    2021-03-31T19:42:55.103+00:00

    @WayneAKig-0228 Thank you

    0 comments No comments