Computing.Net > Forums > Programming > Graphical 2D Array Display VB.NET

Graphical 2D Array Display VB.NET

Reply to Message Icon

Original Message
Name: AJJ
Date: August 17, 2004 at 07:10:49 Pacific
Subject: Graphical 2D Array Display VB.NET
OS: Windows XP
CPU/Ram: Athlon 2000XP and 512Mb
Comment:

Hi folks,

Using input data from a text (what I've called a *.cdem file) I want to first read this into a 2D array data structure - this works fine. However, I am having problems creating a visualisation of this array. If you go to the GRAPHICAL DISPLAY section of my code I want to create a 10 * 10 pixel for every value in my array (and colour code it respectively - in this case using various levels of blue), therefore I'm using: formGraphics.FillRectangle(rgbBrush, row, col, res, res) where rgbBrush should reflect the colour (i.e. index value), row and col should both be the array coordinates and res, res are the dimensions of the pixel. However I always end up with an array out of bounds exception when I compile and run this on a test input array.

Any suggestions as to where the code is in error would be gratefully received:

Here is the code:

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

'----------- INITIALISATION ---------------------

'Define Primititve Type of Integers for Array Dimensions

Dim NumRows As Integer
Dim NumCols As Integer
Dim CellRes As Integer

'Equate with Windows Form Objects
NumRows = Val(TextBox1.Text)
NumCols = Val(TextBox2.Text)

'Define Primitive Type of Array
Dim rm(NumRows, NumCols) As Double

'Define Primitive Type of Input File
Dim cdemFile As String


'This code section enables the browsing for and opening of input file
OpenFileDialog1.ShowDialog()
cdemFile = OpenFileDialog1.FileName
Dim sr As IO.StreamReader = IO.File.OpenText(cdemFile)

'Define Primitive Types for Individual Array elements
Dim row, col As Integer
For row = 1 To NumRows
For col = 1 To NumCols
rm(row, col) = CDbl(sr.ReadLine)

Next
Next

sr.Close() 'Close Input File

'------------ GRAPHICAL DISPLAY-------------------

Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics

Dim res As Integer
Dim indexvalue As Integer

res = 10

indexvalue = rm(row, col)

Dim rgbBrush As New SolidBrush(Color.FromArgb(0, 0, indexvalue))


formGraphics = Me.CreateGraphics()


For row = 1 To NumRows
For col = 1 To NumCols

formGraphics.FillRectangle(rgbBrush, row, col, res, res)

Next
Next
myBrush.Dispose()
formGraphics.Dispose()


End Sub


Report Offensive Message For Removal

Response Number 1
Name: AJJ
Date: August 19, 2004 at 08:22:20 Pacific
Subject: Graphical 2D Array Display VB.NET
Reply: (edit)

Solved the problem anyway - I set my array dimensions up wrongly. I had forgot that they start from 0 in VB.NET



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Graphical 2D Array Display VB.NET

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software