:oops: Trying to play with shapes, but can't get anything to come out. I can do it in a module, but when I try using a class and a module, I get totally lost. This is what I have:

Public Class CSquare
    Inherits Object
    Private mside As Integer
    
    Public Sub New()
        mside = 0

    End Sub

    Public Sub New(ByVal sideValue As Integer)
        mside = sideValue
    End Sub

    Public Function ToSquare() As String
        Dim mrow As Integer = 1
        Dim mcolumn As Integer
        Dim myChar As Char


        If mside <= 20 Then
            While mrow <= mside
                mcolumn = 1
                While mcolumn <= mside

                    Return Console.WriteLine&#40;"*"&#41;
                    mcolumn += 1
                End While
                Console.WriteLine&#40;&#41;
                mrow += 1
            End While

        Else
            Return Console.WriteLine&#40;"Num you entered is too big"&#41;
        End If

            
    End Function

End Class

Module Module1

    Sub Main&#40;&#41;
        Dim myNum As Integer
        Console.WriteLine&#40;"Enter a number less than 20"&#41;
        myNum = Console.ReadLine&#40;&#41;
        Dim side As New CSquare&#40;myNum&#41;
        'Dim row As Integer = 1
        'Dim column As Integer
        Console.WriteLine&#40;side.ToSquare&#41;
    End Sub

End Module

Ok, first off, what extactly are you trying to do with shapes?

Secondly, you can only return something in a function if it has a value, thus you can not return a Console.writeline method. It has no intrinsic value.

Also, when using Console.writeline, or anyother method of the Console object / class you must include the namespace or Import the namespace of System.

i.e.

System.Console.Writeline&#40;"Hello World"&#41;

or

Import System

Console.WriteLine&#40;"Hello world"&#41;

from what the code seems to indicate, you are trying to create a shape (a square) with asteriks. Correct?

I will play around with this and get back too you.

Here is what I came up with I_byte. It was a bit of a logic reminder for me, but I think it will help with the concepts.

Imports System
Public Class CSquare
    Inherits Object

    '   Member Variable
    Private mSide As Integer

    '   Constructor - Overrides the Default Constructor
    Public Sub New&#40;ByVal sideValue As Integer&#41;
        mSide = sideValue
    End Sub

    '   Drawing Method
    Public Sub ToSquare&#40;&#41;   '   Not returning a value, therefore sub not a function

        '   Declare Non-member Variables
        Dim intRow As Integer
        Dim intColumn As Integer
        Dim MyChar As Char
        '   Initiallize
        MyChar = "*"


        For intRow = 0 To mSide '   Outer
            For intColumn = 1 To mSide  '   Inner
                If intColumn = intRow Then
                    Console.WriteLine&#40;MyChar&#41;
                Else
                    Console.Write&#40;MyChar&#41;
                End If
            Next intColumn
        Next intRow

    End Sub

End Class

Module Module1

    Sub Main&#40;&#41;
        Dim myNum As Integer
        Console.WriteLine&#40;"Enter a number less than 20"&#41;
        myNum = CInt&#40;Console.ReadLine&#40;&#41;&#41;  '   Assuming an Integer is passed in
        Dim MySquare As New CSquare&#40;myNum&#41;  '   Instantiate the Object
        MySquare.ToSquare&#40;&#41; '   Call the Member Function to Draw the Square
        'Console.WriteLine&#40;MySquare.ToSquare&#41;   '   A No No.  
        '   Console.Writeline accepts a String, not an Object
    End Sub

End Module

Do read my comments in the code to make more sense of what I did. Not as wordy as I usually am with my comments.

If you want more logic / shape examples or exercises just let me know.

Great! This works, but I cannot see the square because my dos windows closes too fast. Is there a way to make it stay open a bit longer?

Just get input from the user as the last line of the program. This will create a prompt until someone types something and then close.

Easier way is if you are using VS.NET or VB.NET IDE (which I assume you are using) just hit ctrl + F5 to compile. It will pause the window for you

Paladine, you are a genious! It paused it and asked to hit any key to end. That is exactly what I needed. :D

Great! This works, but I cannot see the square because my dos windows closes too fast. Is there a way to make it stay open a bit longer?

In addition to Paladine's sugestion, you could also type this as the last line of code before End Class.

System.Console.ReadLine()

Anything for a fellow programmer! :D

This article has been dead for over six months. Start a new discussion instead.