question

WipfMarleyDSUStudent-6811 avatar image
0 Votes"
WipfMarleyDSUStudent-6811 asked WipfMarleyDSUStudent-6811 answered

Separation by digit?

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.

dotnet-visual-basic
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What is the type of the variable containing the initial
number? Is it a String? An Integer? Other?

Since you say you aren't supposed to use an "if" we
may conclude that this is a course assignment. In such
cases we should not be providing you with a complete
solution, but rather guiding you toward your own answer.

  • Wayne

0 Votes 0 ·
WayneAKing-0228 avatar image
1 Vote"
WayneAKing-0228 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WipfMarleyDSUStudent-6811 avatar image
0 Votes"
WipfMarleyDSUStudent-6811 answered

@WayneAKig-0228 Thank you

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.