none
Need help to migrate code below to if and else and endif which include function RRS feed

  • Question

  • Module Module1

    Sub main()
    Console.Write("Please enter an integer: ")
    Dim input As String
    Dim MyBinary As String
    Do While True 'Loop

    input = Console.ReadLine()
    If (input < 0) Then Exit Do 'Perform loop till input is

    Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )

    MyBinary = Convert.ToString(dec, 2) 'Perform conversation
    Console.Write("The binary number is: ") 'Write string
    Console.WriteLine(MyBinary) 'Write result with new line

    Console.WriteLine() 'Create new line

    Console.Write("Please enter an integer")
    Loop

    Console.WriteLine()
    Console.WriteLine("***End of Program***")
    Console.WriteLine("***Press any key to close")
    Console.Read()

    End Sub

    End Module


    Siva

    Thursday, March 7, 2019 1:44 AM

All replies

  • Hi

    1. If you have a question, then you need to change the post type to Question.

    2. This is a student assignment - for YOU,. Not for a copy/paste/adapt.

    3. You will need to show your own code and where stuck, ask for help.

    4. Your post title is very misleading. What does 'to if and else and endif which include function' mean?



    Regards Les, Livingston, Scotland

    Thursday, March 7, 2019 2:02 AM
  • Sorry..  i have change it to question now. Yes it is for me 

    Need to rewrite the code which has function and  if and else loop.

    IF

    Else

    End if 


    Siva

    Thursday, March 7, 2019 2:11 AM
  • Module Module1

    Sub main()
    Console.Write("Please enter an integer: ")
    Dim input As String
    Dim MyBinary As String
    Do While True 'Loop

    input = Console.ReadLine()
    If (input < 0) Then Exit Do 'Perform loop till input is

    Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )

    MyBinary = Convert.ToString(dec, 2) 'Perform conversation
    Console.Write("The binary number is: ") 'Write string
    Console.WriteLine(MyBinary) 'Write result with new line

    Console.WriteLine() 'Create new line

    Console.Write("Please enter an integer")
    Loop

    Console.WriteLine()
    Console.WriteLine("***End of Program***")
    Console.WriteLine("***Press any key to close")
    Console.Read()

    End Sub

    End Module


    Siva

    Thursday, March 7, 2019 2:12 AM
  • Hi,

    Is this code ok?

    Module Module1
    
        Sub Main()
    Day:
            Console.Write("Please enter an integer: ")
            Dim input As String
            Dim MyBinary As String
            'Do While True 'Loop
    
            '    input = Console.ReadLine()
            '    If (input < 0) Then Exit Do 'Perform loop till input is
    
            '    Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )
    
            '    MyBinary = Convert.ToString(dec, 2) 'Perform conversation
            '    Console.Write("The binary number is: ") 'Write string
            '    Console.WriteLine(MyBinary) 'Write result with new line
    
            '    Console.WriteLine() 'Create new line
    
            '    Console.Write("Please enter an integer")
            'Loop
    
            'Console.WriteLine()
            'Console.WriteLine("***End of Program***")
            'Console.WriteLine("***Press any key to close")
            'Console.Read()
    
    
            input = Console.ReadLine()
            If input < 0 Then
                Console.WriteLine()
                Console.WriteLine("***End of Program***")
                Console.WriteLine("***Press any key to close")
                Console.Read()
                'Console.ReadLine()
            Else
                Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )
    
                MyBinary = Convert.ToString(dec, 2) 'Perform conversation
                Console.Write("The binary number is: ") 'Write string
                Console.WriteLine(MyBinary) 'Write result with new line
    
                Console.WriteLine() 'Create new line
    
                'Console.Write("Please enter an integer")
                GoTo Day
            End If
        End Sub
    
    End Module

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 7, 2019 2:39 AM
  • Can you include function ? Thanks

    Siva

    Thursday, March 7, 2019 2:51 AM
  • Hi,

    What do you mean by putting the code in the function?

    Module Module1 Sub Main() enterinteger() End Sub

    Public Function enterinteger() Day: Console.Write("Please enter an integer: ") Dim input As String Dim MyBinary As String 'Do While True 'Loop ' input = Console.ReadLine() ' If (input < 0) Then Exit Do 'Perform loop till input is ' Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation ) ' MyBinary = Convert.ToString(dec, 2) 'Perform conversation ' Console.Write("The binary number is: ") 'Write string ' Console.WriteLine(MyBinary) 'Write result with new line ' Console.WriteLine() 'Create new line ' Console.Write("Please enter an integer") 'Loop 'Console.WriteLine() 'Console.WriteLine("***End of Program***") 'Console.WriteLine("***Press any key to close") 'Console.Read() input = Console.ReadLine() If input < 0 Then Console.WriteLine() Console.WriteLine("***End of Program***") Console.WriteLine("***Press any key to close") Console.Read() 'Console.ReadLine() Else Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation ) MyBinary = Convert.ToString(dec, 2) 'Perform conversation Console.Write("The binary number is: ") 'Write string Console.WriteLine(MyBinary) 'Write result with new line Console.WriteLine() 'Create new line 'Console.Write("Please enter an integer") GoTo Day End If Return 0 End Function End Module

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 7, 2019 2:57 AM
  • Thanks Alex. It work perfectly and are you able to incorporate loop into existing code

    Siva

    Thursday, March 7, 2019 7:20 AM
  • like this:

    Module Module1
    
        Sub Main()
            enterinteger()
        End Sub
        Public Function enterinteger()
            Dim t As Boolean = True
            If t = True Then
                Console.Write("Please enter an integer: ")
                Dim input As String
                Dim MyBinary As String
                Do While True 'Loop
    
                    input = Console.ReadLine()
                    If (input < 0) Then Exit Do 'Perform loop till input is
    
                    Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )
    
                    MyBinary = Convert.ToString(dec, 2) 'Perform conversation
                    Console.Write("The binary number is: ") 'Write string
                    Console.WriteLine(MyBinary) 'Write result with new line
    
                    Console.WriteLine() 'Create new line
    
                    Console.Write("Please enter an integer")
                Loop
    
                Console.WriteLine()
                Console.WriteLine("***End of Program***")
                Console.WriteLine("***Press any key to close")
                Console.Read()
            Else
    
            End If
            'Day:
            'Console.Write("Please enter an integer: ")
            '    Dim input As String
            '    Dim MyBinary As String
            'Do While True 'Loop
    
            '    input = Console.ReadLine()
            '    If (input < 0) Then Exit Do 'Perform loop till input is
    
            '    Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )
    
            '    MyBinary = Convert.ToString(dec, 2) 'Perform conversation
            '    Console.Write("The binary number is: ") 'Write string
            '    Console.WriteLine(MyBinary) 'Write result with new line
    
            '    Console.WriteLine() 'Create new line
    
            '    Console.Write("Please enter an integer")
            'Loop
    
            'Console.WriteLine()
            'Console.WriteLine("***End of Program***")
            'Console.WriteLine("***Press any key to close")
            'Console.Read()
    
    
            'input = Console.ReadLine()
            'If input < 0 Then
            '    Console.WriteLine()
            '    Console.WriteLine("***End of Program***")
            '    Console.WriteLine("***Press any key to close")
            '    Console.Read()
            '    'Console.ReadLine()
            'Else
            '    Dim dec = Convert.ToInt64(input) 'Convert to 64 bit integer (can use larger integer for binary conversation )
    
            '    MyBinary = Convert.ToString(dec, 2) 'Perform conversation
            '    Console.Write("The binary number is: ") 'Write string
            '    Console.WriteLine(MyBinary) 'Write result with new line
    
            '    Console.WriteLine() 'Create new line
    
            '    'Console.Write("Please enter an integer")
            '    GoTo Day
            'End If
            'Return 0
        End Function
    End Module
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 7, 2019 7:38 AM