Results 1 to 5 of 5

Thread: I need help with this please?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    25

    I need help with this please?

    I am trying to make a console application that when you press the number for the planet it displays its info, but i can't get it to display the info?
    Code:
    Module Module1
    
        Sub Main()
            Dim menuSelection As Integer
            DisplayMenu(menuSelection)
    
            Select Case menuSelection
                Case 1
                    Mercury()
                Case 2
                    Venus()
                Case 3
                    Earth()
                Case 4
                    Mars()
            End Select
    
        End Sub
    
        Private Sub Mercury()
            Console.WriteLine(" ------------------------------- ")
            Console.WriteLine("Mercury:")
            Console.WriteLine("Average Distance from the Sun: 57.9 million kilometers")
            Console.WriteLine("Mass: 3.31 x 10^23 kg")
            Console.WriteLine("Surface Temperture: -173 to 430 degrees Celsius")
    
    
        End Sub
    
        Private Sub Venus()
            Console.WriteLine(" ------------------------------- ")
            Console.WriteLine("Venus:")
            Console.WriteLine("Average Distance from the Sun: 108.2 million kilometers")
            Console.WriteLine("Mass: 4.87 x 10^24 kg")
            Console.WriteLine("Surface Temperture: 472 degreees Celsius")
        End Sub
    
        Private Sub Earth()
            Console.WriteLine("Earth:")
            Console.WriteLine("Average Distance from the Sun: 149.6 million kilometers")
            Console.WriteLine("Mass: 5.967 x 10^24 kg")
            Console.WriteLine("Surface Temperture: -50 to 50 degrees Celsius")
        End Sub
    
        Private Sub Mars()
            Console.WriteLine("Mars:")
            Console.WriteLine("Average Distance from the Sun: 227.9 million kilometers")
            Console.WriteLine("Mass: 0.6424 x 10^24 kg")
            Console.WriteLine("Surface Temperture: -140 to 20 degrees Celsius")
        End Sub
    
        Private Sub DisplayMenu(ByVal menuSelection As Integer)
            Console.WriteLine(" Select a Planet")
            Console.WriteLine("1. Mercury")
            Console.WriteLine("2. Venus")
            Console.WriteLine("3. Earth")
            Console.WriteLine("4. Mars")
            Console.WriteLine("5. End The Program")
            Console.WriteLine()
            Console.WriteLine("Enter your selection: ")
            menuSelection = CInt(Console.ReadLine())
    
            Do While menuSelection < 1 Or menuSelection > 5
                Console.WriteLine("Invalid Selection.")
                Console.Write("Please Enter 1 2, 3, or 4: ")
                menuSelection = CInt(Console.ReadLine())
            Loop
    
        End Sub
    
    
    End Module

  2. #2

  3. #3
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: I need help with this please?

    I dont see how CICATRIX's reference is going to help you?

    He has identified the lack of parameters in your code and therefore the scope problem that persists in your approach to the problem.

    he would have been better telling you that byval simply copies the value into the routine and that the scope of the variable is in the routine and not back to the variable you think it does..

    you can change your scope by using byref and that way the variable value being passed in will be chaged and change the extaernal (now in scope) variable.

    This is not a good way to handle variables...

    you would be better adviced to use functions... these are designed to return some value back to the calling routine and you would then act on the value returned.

    The reason for using functions ifs that in complex systems you do not want to rely on side effects for your processes's integrity.

    hope that helped

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: I need help with this please?

    cicatrix did the right thing. He needs to understand that DisplayMenu's menuSelection parameter needs to be passed ByRef for his code to work the way he expects.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: I need help with this please?

    Quote Originally Posted by incidentals View Post
    I dont see how CICATRIX's reference is going to help you?
    That... and below you write:

    Quote Originally Posted by incidentals View Post
    you can change your scope by using byref and that way the variable value being passed in will be chaged and change the extaernal (now in scope) variable.
    The link I posted tells exactly what should be changed in the code.

    Quote Originally Posted by incidentals View Post
    This is not a good way to handle variables...
    Why is that? If there was some 'bad way' why would the language developers leave it there? Passing parameters by reference is perfectly 'legal' and it's generally faster than passing them by value. What's good and what's bad is determined by the overall design approach. Granted, I would have done it through a function call, but that's up to the OP. He asked for help with the code he's got and I told him exactly why his code did not work according the approach he chose.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width