• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help with simple Visual Basic .Net logic

Lyfer

Diamond Member
Program needs to counter number of sevens in a 5 digit entry using a loop, here's my code:

(inputs a 5 digit number, assigns it as variable "number")

(below separates number into 5 digits)
d1 = number \ 10000
d2 = (number Mod 10000) \ 1000
d3 = ((number Mod 10000) Mod 1000) \ 100
d4 = (((number Mod 10000) Mod 1000) Mod 100) \ 10
d5 = (((number Mod 10000) Mod 1000) Mod 100) Mod 10

counter7=0 (used to count sevens)
counter=1

while counter <= 5

x="d"&counter (assigns x=d1 and so on essentially)
if x=7 then
counter7=counter7+1
end if
counter=counter+1

end while

(output "counter7" - number of sevens counted)


I still keep getting a 0, am I joining the "d" and counter correctly to identify the digits?
 
Here's how I would do this in c++. I'm sure it can be translated in to basic fairly easily but I don't use basic. 😉

This will find the number of any digit in any length number.

Edit: To answer your question, I think whenyou do this:
x="d"&counter (assigns x=d1 and so on essentially)
what gets stored in the variable x is the string "d1" or "d5", not the variable d1 or d5.
 
Quick way:

Dim sourceNumber as Int32 = 97979
Console.WriteLine("Number of sevens: " & (sourceNumber.ToString().Split("7").Length - 1).ToString())


Long way below.
 
Back
Top