?
Solved

how to declare the function below

Posted on 2005-03-03
5
Medium Priority
?
187 Views
Last Modified: 2010-04-23
Hi Experts,

May I know how to declare the function below.
Thanks,

Turbot

    Function BuildTable(ByVal RowsNumber As Integer, ByVal ColumnsNumber As Integer)
        Dim i, j As Integer
        Me.Table1.Rows.Clear()
        For j = 1 To RowsNumber
            Dim row As New TableRow
            For i = 1 To ColumnsNumber
                Dim Cell As New TableRow
                'Cell.t = Rnd()
                Cell.BorderColor = Color.Blue
                Cell.BorderWidth = Unit.Pixel(1)
                row.Cells.Add(Cell)
            Next
            Me.Table1.Rows.Add(row)
        Next
        Me.Table1.BorderColor = Color.AliceBlue
        Me.Table1.BorderStyle = BorderStyle.Groove
        Me.Table1.BorderWidth = Unit.Pixel(1)
    End Function
0
Comment
Question by:turbot_yu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Assisted Solution

by:saleek
saleek earned 200 total points
ID: 13447603
I dont understand, you have declared it!
0
 
LVL 25

Assisted Solution

by:RonaldBiemans
RonaldBiemans earned 200 total points
ID: 13447660
I agree with saleek, the only thing I can see wrong with it, is that the function doesn't return anything
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 200 total points
ID: 13447735
I agree with the 2 others.
Another little remark is: is it a private or public function ?
Why use a function and not a sub if it returns nothing ?
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 800 total points
ID: 13448656
If by declare you actually mean call, then you can run use the following line:

BuildTable(5, 3)

... but as the others have said, the function doesn't return anything so either change it to a Sub, or add the lines to return something whether it be a reference to the table created or a boolean expression saying whether it was a success or not:

==================

DECLARE AS A SUB:

    Sub BuildTable(ByVal RowsNumber As Integer, ByVal ColumnsNumber As Integer)
        Dim i, j As Integer
        Me.Table1.Rows.Clear()
        For j = 1 To RowsNumber
            Dim row As New TableRow
            For i = 1 To ColumnsNumber
                Dim Cell As New TableRow
                'Cell.t = Rnd()
                Cell.BorderColor = Color.Blue
                Cell.BorderWidth = Unit.Pixel(1)
                row.Cells.Add(Cell)
            Next
            Me.Table1.Rows.Add(row)
        Next
        Me.Table1.BorderColor = Color.AliceBlue
        Me.Table1.BorderStyle = BorderStyle.Groove
        Me.Table1.BorderWidth = Unit.Pixel(1)
    End Sub

---
    Call the sub:      BuildTable(5, 3)

==================

DECLARE AS FUNCTION WITH REFERENCE TO A TABLE:

    Function BuildTable(ByVal RowsNumber As Integer, ByVal ColumnsNumber As Integer) As Table
        Dim i, j As Integer
        Me.Table1.Rows.Clear()
        For j = 1 To RowsNumber
            Dim row As New TableRow
            For i = 1 To ColumnsNumber
                Dim Cell As New TableRow
                'Cell.t = Rnd()
                Cell.BorderColor = Color.Blue
                Cell.BorderWidth = Unit.Pixel(1)
                row.Cells.Add(Cell)
            Next
            Me.Table1.Rows.Add(row)
        Next
        Me.Table1.BorderColor = Color.AliceBlue
        Me.Table1.BorderStyle = BorderStyle.Groove
        Me.Table1.BorderWidth = Unit.Pixel(1)
        Return Me.Table1
    End Function

---
    Call the function:
          Dim myTable as Table
          myTable = BuildTable(5, 3)
          ' Then do something with myTable, which is a reference to Table1

*I'm assuming the type is TABLE and not something else here


DECLARE AS FUNCTION WITH REFERENCE TO A SUCCESS OR FAILURE:

    Function BuildTable(ByVal RowsNumber As Integer, ByVal ColumnsNumber As Integer) As Boolean
        Dim i, j As Integer
        Try
            Me.Table1.Rows.Clear()
            For j = 1 To RowsNumber
                Dim row As New TableRow
                For i = 1 To ColumnsNumber
                    Dim Cell As New TableRow
                    'Cell.t = Rnd()
                    Cell.BorderColor = Color.Blue
                    Cell.BorderWidth = Unit.Pixel(1)
                    row.Cells.Add(Cell)
                Next
                Me.Table1.Rows.Add(row)
            Next
            Me.Table1.BorderColor = Color.AliceBlue
            Me.Table1.BorderStyle = BorderStyle.Groove
            Me.Table1.BorderWidth = Unit.Pixel(1)
            Return True
        Catch
            Return False
        End Try
    End Function

---
    Call the function:
          If BuildTable(5, 3) = True Then
               'Table was rebuilt correctly
          Else
               ' Something went wrong
          End If
          ' Then do something with myTable, which is a reference to Table1
=========================

One thing to note is the because you've used the "Me" operator, you can only use this code, and call this code within the document class you are working in (or within other classes that at least contain an object called Table1).

If I'm running ahead of myself here, it's because as the others say, you have declared it, and I'm just taking a guess what you actually meant
0
 
LVL 12

Assisted Solution

by:farsight
farsight earned 600 total points
ID: 13451404
S-Twilley: Good, thorough answer!  I'm following up on your comment "because you've used the "Me" operator ...".

Here's another variation.  I renamed to FormatTable because I think of "Build" as creating from nothing.  This routine doesn't create the table, it uses the existing table Me.Table1.  What it does is resize the table (row & columns) and apply some color/border formatting.

Also, I passed in Me.Table1 to the TheTable parameter.  Now the routine can be used on ANY existing table.

==================

DECLARE AS A SUB:

    Sub FormatTable(ByVal TheTable As Table, ByVal RowsNumber As Integer, ByVal ColumnsNumber As Integer)
        Dim i, j As Integer
        TheTable.Rows.Clear()
        For j = 1 To RowsNumber
            Dim row As New TableRow
            For i = 1 To ColumnsNumber
                Dim Cell As New TableRow
                'Cell.t = Rnd()
                Cell.BorderColor = Color.Blue
                Cell.BorderWidth = Unit.Pixel(1)
                row.Cells.Add(Cell)
            Next
            TheTable.Rows.Add(row)
        Next
        TheTable.BorderColor = Color.AliceBlue
        TheTable.BorderStyle = BorderStyle.Groove
        TheTable.BorderWidth = Unit.Pixel(1)
    End Sub

---
    Call the sub:      FormatTable(Me.Table1, 5, 3)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question