Hi everyone , i am trying to fully uderstand the recursion method in vb but i still have problems in making the programs work, Can anyone help me to create a program that convert decimal numbers to binary numbers or point me to the right direction,I know that this can be done by continuing dividing by 2 until the is no more result left but in a recursive method i have problems. Thank you

Recommended Answers

All 3 Replies

Hi i found this code on the web that works but can someone tell my how does this works


Private Function RecursionFunc(ByRef AsciiNum As Short, ByRef SubNum As Short) As Object

If AsciiNum - SubNum > 0 Then
txtNew.Text = txtNew.Text & 1 'Add a 1 to indicate that it contains a subnum in it
If SubNum <> 1 Then 'Check to make sure it's not 1
RecursionFunc(AsciiNum - SubNum, SubNum / 2) 'Call myself with the new asciinum and subnum
End If
Else
txtNew.Text = txtNew.Text & 0 'Add a zero to indicate that the subnum is not contained
If SubNum <> 1 Then 'Check to make sure it's not 1
'Call myself with the same asciinum because it does not contain a subnum and make subnum the next smallest
RecursionFunc(AsciiNum, SubNum / 2)
End If
End If

Hi i found this code on the web that works but can someone tell my how does this works

u said it works but you want to someone tell u how it works?confusing statement.

yes how does this code works

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.