Grid?
Grid?
Grid?
Grid?
Grid?
Grid? Grid? Grid? Grid? Grid? Grid? Grid? Grid?
Grid? Grid?
Grid?
Go Back  Xtreme Visual Basic Talk > > > Grid?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2009, 11:24 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default Grid?


I know how to draw a grid with dots,
System.Windows.Forms.ControlPaint.DrawGrid(e.Graphics, e.ClipRectangle, New Size(NewMap.MapX, NewMap.MapY), Color.Blue)

But what i dont know how to do is make a grid with lines... do i do like a loop and put squares up untell they = a given amount.

Also when that is done how do i make it so if the mouse clicks a square in the grid, that it changes color?

Anyhelp apriciated(Or links)...

Thanks,
HQcool22

Edit: I got a sorta grid working... it makes a good grid for the first like 5 squares then it makes more and they increase in size...

Code:
        For y = 1 To 5
            For x = 1 To 5
                e.Graphics.DrawRectangle(Pens.Red, New Rectangle(x * 30, y * 30, x * 30, y * 30))
            Next
        Next
__________________
I know stuff!

Last edited by HQcool22; 08-12-2009 at 11:45 PM.
Reply With Quote
  #2  
Old 08-13-2009, 03:15 AM
Qua's Avatar
QuaGrid? Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

I would properly draw the grid with lines instead of rectangles, but not sure it makes that much of a difference it just feels more natural to me. As for detecting clicks inside your grid. You will need to handle the mouse click event for the control you're drawing onto. Once the control is clicked, use the mouse location to compute the grid that was clicked.

I think I the following code once for a similar project
Code:
'Inside mouseclick
Dim clickedGrid As New Point(e.Location.X \ rectSize, e.Location.Y \ rectSize)
where rectSize is the size of your rectangles. You could change this to a height and width component instead if you're doing rectangles instead of squares.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 08-13-2009, 10:36 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

okay, im shure i can make that work, thanks Qua
__________________
I know stuff!
Reply With Quote
  #4  
Old 08-14-2009, 01:22 AM
Gruff's Avatar
GruffGrid? Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Key to what Qua is getting at is integer division signified by the back slash instead of the forward slash which signifies full division.

If your vertical lines are 50 twips wide and your mouse up x is anywhere from 0 to 50 then x will always equal 0
x = 29
x = x \ 50
(x is 0)
----
x = 63
x = x \ 50
(x is 1)
----
x = 122
x = x \ 50
(x is 2)
----
Etc...
To create fill your rectangle you multply your converted x back into your rectangle coordinates.
x1 = x
x2 = x+50

do the same with your mouse up y value.
Draw your rectangle.

Of course I pulled the 50 twip rectangle value out of the air. You would use whatever value you like.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #5  
Old 08-14-2009, 07:21 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

ok then, thanks for explaining that in more detail
__________________
I know stuff!
Reply With Quote
  #6  
Old 08-16-2009, 09:11 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

Ive run into another problem... i cant get it to load the image into the grid, but it does get the correct location on the grid, thanks to Qua My code,

Code:
    Public ClickedGridPoint As New Point
    Public Fill As Boolean
    Public Image As Bitmap
    Private Sub Panel1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseClick
        Dim MapX As Integer = 30
        Dim MapY As Integer = 30
        'Inside mouseclick
        Dim clickedGrid As New Point(e.Location.X \ MapX, e.Location.Y \ MapY)
        ClickedGridPoint = clickedGrid
        Image = New Bitmap("C:\Image1.bmp")
        Fill = True
        Me.Invalidate()
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Dim MapX As Integer = 30
        Dim MapY As Integer = 30
        System.Windows.Forms.ControlPaint.DrawGrid(e.Graphics, e.ClipRectangle, New Size(MapX, MapY), Color.Blue)
        If Fill = True Then
            e.Graphics.DrawImage(Image, New Point(ClickedGridPoint.X * 30, ClickedGridPoint.Y * 30))
        End If
    End Sub
Ya so, i click on the grid, it gives me correct location(I know i debugged using a msgbox to relay click position) and then i set a bitmap and tryed to load it at the grid. It does not load the image sam i am!!!! It does not even throw an error, it just does nothing
__________________
I know stuff!
Reply With Quote
  #7  
Old 08-16-2009, 09:14 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

NEVER MIND!!!! i just fixed it, realizing that i am stupide! i set the invalidate statment to invalidate the form not the panel... i feel dumb now...
But now i have a question again, How do i make it remember what grid squares have a image in them when you click on another grid square? Right now if i click on one square, an image shows up there, when i click on another grid square it changes the location of the previous image. How do i make it show image at both places, then more depending on how many grid squares i click on?

Edit: I am having bad, day... i fixed this problem for myself too
__________________
I know stuff!

Last edited by HQcool22; 08-16-2009 at 10:21 PM.
Reply With Quote
  #8  
Old 08-16-2009, 10:26 PM
Qua's Avatar
QuaGrid? Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Quote:
Originally Posted by HQcool22 View Post
NEVER MIND!!!! i just fixed it, realizing that i am stupide! i set the invalidate statment to invalidate the form not the panel... i feel dumb now...
But now i have a question again, How do i make it remember what grid squares have a image in them when you click on another grid square? Right now if i click on one square, an image shows up there, when i click on another grid square it changes the location of the previous image. How do i make it show image at both places, then more depending on how many grid squares i click on?

Edit: I am having bad, day... i fixed this problem for myself too
The way I see it you've two options: Create a multidimensional array (2D) that will represent an image for each grid or have a list of images and their locations. The first solution will properly only be effecient if you plan to have images in several of the grid locations, since it takes up a lot of memory, whereas the second only takes up the memory needed for the actual amount of images being displayed.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #9  
Old 08-16-2009, 11:42 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

I endup using Hashtable to store each grid image and grid position. All the grid squares will be filled up with sometype of image. The images are named with a number so that i could store them to text file, then load the text file later and it uses the tile number to reload the images into apropriate grid square. Im not shure if i can extract the data i need and put it into format like,

0,1,1,1,1,1,1
1,0,1,1,1,1,3
1,1,0,1,1,1,1
1,1,1,0,1,1,1
3,1,1,1,0,1,1

Could i do something like that with the hashtables? or do i need to use an array? As soon as that question is answered... i know how to pull the number of the image out of the hashtables but i dont know how to format it like needed. Any help with that would be apriciated.

And thanks for the help you have currently givin me
__________________
I know stuff!
Reply With Quote
  #10  
Old 08-16-2009, 11:58 PM
Qua's Avatar
QuaGrid? Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Yes it would be possible with a hashtabel, but why would you want to use a hash table for this operation instead of an array? What advantages do you expect to gain from this? It seemes to me, by reading quite a few of your last posts, that you've grown quite the fond eye for hash tabels for some reason. They're great in many cases, but this layout simple screams for a normal array. Take a look at the grid of numbers you've laid out in your posts, it's almost screaming matrix into your head
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #11  
Old 08-17-2009, 12:16 AM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

the reason i like hashtables is that ive well, learned how to use them How would i go about this is an array(I know basics of arrays, but 2d arrays always screw up my stuff)?
__________________
I know stuff!
Reply With Quote
  #12  
Old 08-17-2009, 11:04 AM
AtmaWeapon's Avatar
AtmaWeaponGrid? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

2D arrays aren't really hard to use, but I always prefer to wrap them in a class because usually situations that require 2D arrays have special logic for accessing the array. Here's a code example that demonstrates the two types of 2D array and using a custom class to hide the implementation details of your array; more explanation is in the comments:
Code:
Module Module1

    Sub Main()
        DemonstrateRectangularArray()
        Console.WriteLine()
        DemonstrateJaggedArray()
        Console.WriteLine()
        DemonstrateSquare()
    End Sub

    Private Sub DemonstrateRectangularArray()
        ' Rectangular arrays are technically 1D arrays in memory, but the indexing does special math
        ' to make it look like they have rows and columns.  Here's how to make a 3x3 array:
        Dim square(2, 2) As Integer

        ' To iterate over a 2D array, you usually use row/column terminology.  Here, we assign a
        ' value to each square by iterating over the rows and columns.  Since the Length property
        ' is only useful for 1D arrays, use the GetUpperBound() method to get the largest valid
        ' index for each bound.
        Dim counter As Integer = 0
        For row As Integer = 0 To square.GetUpperBound(0)
            For column As Integer = 0 To square.GetUpperBound(1)
                square(row, column) = counter
                counter += 1
            Next
        Next

        ' This demonstrates that you can pass a 2D array as a parameter with no effort.
        PrintRectangularArray(square)

        ' To index a rectangular array, supply a list of indices.
        Console.WriteLine("The middle square's value is {0}.", square(1, 1))
    End Sub

    ' To pass a 2D array to a method, don't specify any size bounds. (See note 1 at end.)
    Private Sub PrintRectangularArray(ByVal values(,) As Integer)
        For row As Integer = 0 To values.GetUpperBound(0)
            For column As Integer = 0 To values.GetUpperBound(1)
                Console.Write("{0} ", values(row, column))
            Next
            Console.WriteLine()
        Next
    End Sub

    Private Sub DemonstrateJaggedArray()
        ' A "jagged" array is actually an array of arrays.  The syntax makes it clear.  It is saying
        ' that square is a 3-element array where each element is an array of integers.  There is no
        ' way to make a 3x3 jagged array in one go, you can only define the size of the first bound
        ' and then you have to create a new array for each bound.
        Dim square(2)() As Integer

        ' As mentioned above, this loop has to first create the array for each row, then set the
        ' elements of the new array.  Finally, make sure to add the row to the jagged array!
        Dim counter As Integer = 0
        For row As Integer = 0 To square.Length - 1
            Dim thisRow(2) As Integer
            For column As Integer = 0 To thisRow.Length - 1
                thisRow(column) = counter
                counter += 1
            Next
            square(row) = thisRow
        Next

        ' No special syntax for passing a jagged array.
        PrintJaggedArray(square)

        ' You index a jagged array using two sets of indices.  I like to think of this as saying:
        ' "The value of the second array's second element."
        Console.WriteLine("The middle square's value is {0}.", square(1)(1))
    End Sub

    ' As with rectangular arrays, you indicate parameters that are jagged arrays by omitting the
    ' bounds.  (See note 1 at end.)
    Private Sub PrintJaggedArray(ByVal values()() As Integer)
        ' Note that I could have used the Length property of each array instead; since the jagged
        ' array is an array of arrays I found it easier to use For Each.
        For Each row As Integer() In values
            For Each value As Integer In row
                Console.Write("{0} ", value)
            Next
            Console.WriteLine()
        Next
    End Sub

    ' See the comments on the Square class below for an explanation of what the Square class does.
    Private Sub DemonstrateSquare()
        Dim square As New Square(3)

        ' The interface of Square makes it more like a rectangular array, so this should look
        ' familiar.
        Dim counter As Integer = 0
        For row As Integer = 0 To square.Size - 1
            For column As Integer = 0 To square.Size - 1
                square.SetValue(row, column, counter)
                counter += 1
            Next
        Next

        ' You could obviously pass the Square to a PrintSquare() method, but since you have a custom
        ' class you can also provide a Print() method.
        square.Print()

        ' Indexing the Square class is done through GetValue() and works somewhat like a rectangular
        ' array.
        Console.WriteLine("The middle square's value is {0}.", square.GetValue(1, 1))
    End Sub

End Module

' I very much prefer abstracting any multi-dimensional arrays into classes that represent the
' concept.  See note 2 for some ideas of why this is good.  This particular class abstracts a 2D
' array and represents a square of values (always has the same number of rows and columns.)
Public Class Square
    ' Internally the square uses a rectangular array, but users of Square don't have to know that.
    ' You could use a jagged array or some other data structure without changing the interface of
    ' the class.
    Private _data(,) As Integer
    Private _size As Integer

    ' When you create the square, you tell it how big you want it to be.  This is number of elements,
    ' not upper bound.  
    Public Sub New(ByVal size As Integer)
        _size = size
        ReDim _data(size - 1, size - 1)
    End Sub

    Public ReadOnly Property Size() As Integer
        Get
            Return _size
        End Get
    End Property

    Public Function GetValue(ByVal row As Integer, ByVal column As Integer) As Integer
        Return _data(row, column)
    End Function

    Public Sub SetValue(ByVal row As Integer, ByVal column As Integer, ByVal value As Integer)
        _data(row, column) = value
    End Sub

    Public Sub Print()
        For row As Integer = 0 To _data.GetUpperBound(0)
            For column As Integer = 0 To _data.GetUpperBound(1)
                Console.Write("{0} ", _data(row, column))
            Next
            Console.WriteLine()
        Next
    End Sub
End Class

' *** NOTES ***
' 1) You can specify the size of the array you expect, but there's rules.  I don't know them, and
'    have to look them up when I need them.  It's easier to make a class that represents the concept
'    you are expressing.
' 2) Using a custom class means you can bake in a lot of logic and not have to worry about it
'    elsewhere.  For example, what if you wanted to make a tile map for a game?  With a 2D array,
'    you might store a bitmap in each tile.  This wastes a lot of memory, so you'd switch to having
'    two arrays: an array of tiles and a 2D array of indices into the tile array.  If you create a
'    custom tilemap class, you can make those details internal instead of spreading them throughout
'    every form that needs a tilemap.
As note 2 illustrates, if you're making a tilemap for your form it'd be best to use a class that hides the tilemap logic instead of spreading it around your form. For example, if you don't use a class, your form will need a 1D array of tiles, a 2D array of indices, and logic to get/set tiles and indices. If you ever try to change the logic, you have to find all places that have the logic and change them. On the other hand, you could create a class that looks like this:
Code:
Public Class TileMap

    Public Sub New(ByVal tiles As Integer, ByVal rows As Integer, ByVal columns As Integer)
    End Sub

    Public ReadOnly Property Columns() As Integer
    Public ReadOnly Property Rows() As Integer
    Public ReadOnly Property TilePaletteSize() As Integer

    ' Gets or sets tiles in the palette that is used by the tilemap.
    Public Function GetTile(ByVal index as Integer) As Bitmap
    Public Sub SetTile(ByVal index As Integer, ByVal image As Bitmap)

    ' Gets or sets the index of the tile used by a particular position in the tilemap
    Public Function GetTilemapIndex(ByVal row As Integer, ByVal column As Integer) As Integer
    Public Function SetTilemapImage(ByVal row As Integer, ByVal column As Integer, ByVal tileIndex As Integer)

End Class
Now, if you decide on a more efficient algorithm or want to change how you store things, you change one thing, not many.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #13  
Old 08-17-2009, 07:35 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

Ok, Ill work on it in a bit and see if i can get it to work... i hope i can because im tired of hashtables!

Thanks for example 2d array AtmaWeapon. Much apriciated

Edit:
That is all fine and dandy but i want to load the images based on what the grid the user clicked on. yes i have a set grid size of 20 by 20 but wont the array throw an exception if there is a null reference for an image its trying to load?
__________________
I know stuff!

Last edited by HQcool22; 08-18-2009 at 03:00 PM.
Reply With Quote
  #14  
Old 08-17-2009, 09:38 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

The Square example spits out, {0} 8... whats that mean? and also how do i load the tiles onto the form when the user has to click grid squares to determine what type of image goes there. See my problem currently... is that i need it so that it loads the images at the correct grid squares that the user clicked on. I know how to click on the grid and get all the data i need from that to place the image, then i tryed using hashtables to store location of all images. But with hashtables i ran into a few problems, it made dublicate entries when you click on the same tile 2 times. this would cause problems when i go to collect the grid set up... then i could not even think of a way to take the hashtables data and put it into the format i wanted. There for i learned from Qua that arrays might be a better choice, then you posted code. What i think your code does is print out the grid images at correct locations, in the format i gave example of above.

Well im really confused now but its all good because im tired.
__________________
I know stuff!
Reply With Quote
  #15  
Old 08-18-2009, 09:49 AM
AtmaWeapon's Avatar
AtmaWeaponGrid? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Quote:
Originally Posted by HQcool22 View Post
The Square example spits out, {0} 8... whats that mean?
I don't know what this means. All examples work fine and were tested multiple times before I posted. I just copied the text in my post, pasted it in a different application, ran it, and got the results I expected. Are you sure you didn't change something?

Quote:
and also how do i load the tiles onto the form when the user has to click grid squares to determine what type of image goes there. See my problem currently... is that i need it so that it loads the images at the correct grid squares that the user clicked on. I know how to click on the grid and get all the data i need from that to place the image, then i tryed using hashtables to store location of all images. But with hashtables i ran into a few problems, it made dublicate entries when you click on the same tile 2 times. this would cause problems when i go to collect the grid set up... then i could not even think of a way to take the hashtables data and put it into the format i wanted. There for i learned from Qua that arrays might be a better choice, then you posted code. What i think your code does is print out the grid images at correct locations, in the format i gave example of above.

Well im really confused now but its all good because im tired.
Here's your problem statement:
"How do I load images at the correct grid square?"

To define a solution, let's think about what we have:
  • A class that represents a tilemap. It lets us set a tile palette, indicate what image is at what tile, and lets us ask "What image belongs at this tile?"
  • Some code that tells us what tile was clicked by the mouse.
This is all we need! Let's assume you define a helper struct:
Code:
Public Structure TilemapIndex
    ' Example uses fields; use read-only properties in real code
    Public Row As Integer
    Public Column As Integer
End Structure
Now, put the code that tells you what tile the user clicked into a function:
Code:
Private Function GetTilemapIndex(ByVal clickLocation As Point) As TilemapIndex
    ' Be sure to check if the user clicked outside the bounds of your display and return
    ' something appropriate!
End Function
Now, suppose we have loaded 3 images in our tile palette somewhere in our code:
Code:
_tilemap.SetImage(0, image1)
_tilemap.SetImage(1, image2)
_tilemap.SetImage(2, image3)
The following method cycles the image in an indicated tile:
Code:
Private Sub CycleImage(ByVal index as TilemapIndex)
    Dim currentIndex As Integer = _tilemap.GetTilemapIndex(index.Row, index.Column)
    Dim nextIndex As Integer = currentIndex + 1
    If currentIndex = _tilemap.TilePaletteSize Then
        nextIndex = 0
    End If

    _tilemap.SetTilemapIndex(index.Row, index.Column, nextIndex)
End Sub
(This code snippet suggests I should rename TileMap.GetTilemapIndex() and TileMap.SetTileMapIndex() to GetTileIndex() and SetTileIndex() since I defined a TilemapIndex type that is not related to these methods.)

So now, your click handler should look something like this:
Code:
Sub SomeControlClicked(...)
    Dim clickedIndex As TilemapIndex = GetTilemapIndex(e.Location)
    If IsValid(clickedIndex) Then ' You have to decide what IsValid() checks
        CycleImage(clickedIndex)
    End If
End Sub
I assume that the next question is "How do I draw the tiles on the screen?" My first answer is "Spend 10 minutes thinking about it." If you look above, you got a strategy for drawing a grid on a form; it's very similar. The basic algorithm for drawing anything in a gridlike pattern is as follows:
  • Store the width and height of grid cells.
  • Calculate and store the number of rows and columns.
  • For Each Row
    • Calculate the y offset for this row. (Generally cellHeight * rowIndex.)
    • For Each Column
      • Calculate the x offset for this column. (Generally cellWidth * columnIndex.)
      • Get the image that should be displayed at (row, column).
      • Draw the image at (xOffset, yOffset).

The tilemap provides the way to get the image for a particular grid square. GetTileMapIndex() gets an index that you can pass to GetTile() that returns a bitmap.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #16  
Old 08-18-2009, 04:56 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

well i got to start the project over because my stupide vb.net 2008 express glitched my project, if i change code or designer stuff it stays the same and does not recompile the new data!!! So give me some time to redo everything in new project then ill be good to look at what you just posted.

EDIT: i fixed it by deliting the .exe in the programs debug folder . I was also tired last night when i tryed out your square code... i had to remodiffy it a bit to give me the output on my program and i did it wrong so it replaced the text in the textbox everytime the loop ran, i fixed it and it now spits out,

{0} 0 {0} 1 {0} 2 {0} 3 {0} 4 {0} 5 {0} 6 {0} 7 {0} 8
__________________
I know stuff!

Last edited by HQcool22; 08-18-2009 at 08:10 PM.
Reply With Quote
  #17  
Old 08-18-2009, 10:39 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default

nextIndex in CycleImage sub throws an error,
Too many arguments to 'Public Function SetTilemapIndex(row As Integer, column As Integer) As Integer'.


Dim clickedIndex As TilemapIndex = _Tilemap.GetTilemapIndex(ClickedGridPoint.X, ClickedGridPoint.Y)

Also throws an error,
Value of type 'Integer' cannot be converted to 'Map_Editor.Form1.TilemapIndex'.


other than that i got all code working.
__________________
I know stuff!
Reply With Quote
  #18  
Old 08-19-2009, 09:51 AM
AtmaWeapon's Avatar
AtmaWeaponGrid? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

The code you are using and the code that I posted are not the same thing. I had intended to add the paragraph below in an earlier post but decided to give you the benefit of the doubt. You are removing said doubt and losing the benefit.

Programming is a thinking activity. Imagine you have to teach a child to sort a list of numbers, but the child only speaks Esperanto. Do you think you'll find a handy "How to teach children to sort numbers in Esperanto" book? No. You first have to study Esperanto and become conversational. Then you have to decide how to teach a child to sort numbers. Then you have to explain this concept to the child in Esperanto.

This is how programming works. The computer's a kid that speaks VB .NET. If you want the computer to do anything, you have to figure out how to tell the computer what to do in VB .NET. This is where your brain comes in. It's admirable that you obviously typed my examples in rather than copying and pasting, but if you don't read through the implementation and try to *comprehend* what you are typing you aren't really doing anything different. All of the errors you are describing seem to be explained by "User typed code hastily and didn't try to understand what it's doing." I can throw example code at you, but if you don't use your brain you won't get anywhere.

Re: Post #16
Based on your description, it seems like for some reason you removed the call to WriteLine() and erroneously translated this line:
Console.Write("{0} ", _data(row, column))
into something like this:
Console.Write("{0} " & _data(row, column))There is no other explanation for the behavior you explain. Please post the entirety of the code that doesn't work so it can be examined.

RE: Post #17
You did not copy my code correctly. In my code, SetTilemapIndex() has three arguments. In your code, it has two arguments. How do I know this? The error message says so:
Too many arguments - This means there are too many arguments

to 'Public Function SetTilemapIndex(row As Integer, column As Integer) As Integer' compare this to my code:
Public Function SetTilemapImage(ByVal row As Integer, ByVal column As Integer, ByVal tileIndex As Integer)

Notice how my code is a Function with 3 arguments but yours is a Function with two arguments? Your brain. Use it.

Here's a chance to get back at me though. What would a function named SetTilemapImage return? I should have made it a Sub, because there's no logical return value. Feel free to make fun of my mistake.

Compare your next failing line to my line:
Code:
' Yours
Dim clickedIndex As TilemapIndex = _Tilemap.GetTilemapIndex(ClickedGridPoint.X, ClickedGridPoint.Y)
' Mine
Dim currentIndex As Integer = _tilemap.GetTilemapIndex(index.Row, index.Column)
Here's how the error message is telling you this is the problem:
Value of type 'Integer' cannot be converted to 'Map_Editor.Form1.TilemapIndex'.
"I expected a Map_Editor.Form1.TilemapIndex. You are using Integer". Your brain. Use it.

Dim clickedIndex As TilemapIndex = <-- This is why the compiler expects a TilemapIndex
_tilemap.GetTilemapIndex(...) <-- This is returning Integer.

Do you see how Dim something As TilemapIndex = 3 might fail? This code fails for the same reason. Types must be equivalent on both sides of the equals sign.

If my harshness offends you, I'm sorry. I spent a lot of time producing examples and explanations in the hopes that you'd learn from them, and it hurts my feelings when a user responds with "doesn't work" and no other explanation. I generally compile and run my examples multiple times, even if code I post is pseudocode. So I take offense when someone implies there's an obvious error that I can prove is not there.

At least 50% of the errors in my code turn out to be lines of code that don't do what I think they do. When there is a bug in my code, the first thing I do is find the code that causes the bug and ask myself, "What *should* this code be doing?" I compare that to "What *is* this code doing." It's a very helpful exercise, and would have helped you through these errors. Get in this habit early, and you'll look a lot smarter to all of your friends. I'm not a particularly smart programmer, but over the years I've learned tricks for catching my stupid mistakes before exposing them to others
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Grid?
Grid?
Grid? Grid?
Grid?
Grid?
Grid? Grid? Grid? Grid? Grid? Grid? Grid?
Grid?
Grid?
 
Grid?
Grid?
 
-->