Is there a way to simplify this?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Is there a way to simplify this code?
Code: Select all
    Sub New(ByVal width As Integer, ByVal height As Integer)
        Dim result(width, height) As Integer
        valueBoard = result
    End Sub
I want to set the value of valueBoard to an integer array with a specified width and height and have all values set to zero.

Thanks!
http://www.megaapps.tk/
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

This is already simple and I am not sure exactly what you wanted. Is this what you want?
Code: Select all
Public ValueBoard As Array

    Public Sub Example(ByVal width As Array, ByVal height As Array)
        Dim result() As Array = {width, height}
        ValueBoard = result
        width = {0}
        height = {0}
        result = {width, height}
    End Sub

That is the same as what you have but it's using arrays instead of integers
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

I'm wondering if there is a way to put everything in the sub on one line instead of two. It seems like there should be a way, but I don't know how...
http://www.megaapps.tk/
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

I cannot figure out a way to put your code into one line though it doesn't mean it is impossible. Maybe need to try something completely different. Sorry I couldn't help though if I come up with something I'll be sure to let you know.

EDIT:

You're allowed to set valueBoard's value like this:
Code: Select all
Public valueBoard As Integer
    Public Sub Example(ByVal width As Integer, ByVal height As Integer)
        Dim result(width, height) As Integer, valueboard = result(width, height)
        
    End Sub
But you still need to set the values back to 0 like you wanted but your first two lines are now one.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
4 posts Page 1 of 1
Return to “Coding Help & Support”