FatboyPat
03-07-2005, 08:51 PM
Hi all, I'm trying to get (what would appear to be) a pretty simple program/module to work, but I'm running into some serious issues...
I'm very inexperienced with VB although my limited knowledge also applies to a few other languages so I'm not completely new to computer programming...
My problem is that I have a perfectly functioning Sub, but I want to turn it into a Function that would return a UDT of all the data created/set in the Function...
here's my code:
Public Type grid ' cant get it to work so that newGrid is a function that returns type grid
TILE_WIDTH As Integer
TILE_HEIGHT As Integer
TILE_GRIDWIDTH As Integer
TILE_GRIDHEIGHT As Integer
TILE_OFFSETX As Integer
TILE_OFFSETY As Integer
End Type
Public Sub newGrid(frm As Form, obj As Object, tWidth As Integer, tHeight As Integer, gWidth As Integer, gHeight As Integer, offSetX As Integer, offSetY As Integer)
tWidth = tWidth
tHeight = tHeight
Dim arrayElem As Object
If obj.Count > 1 Then
For i = 1 To (obj.Count - 1)
Set arrayElem = obj(i)
Unload arrayElem
Next i
End If
Set arrayElem = obj(0)
arrayElem.Left = offSetX
arrayElem.Top = offSetY
arrayElem.Width = 50
arrayElem.Width = tWidth
arrayElem.Height = tHeight
arrayElem.Visible = True
For i = 1 To (gWidth * gHeight) - 1
Load obj(i)
Set arrayElem = obj(i)
arrayElem.Left = (i * tWidth) Mod (tWidth * gWidth) + offSetX
arrayElem.Top = Int(i / gWidth) * tHeight + offSetY
arrayElem.Visible = True
Next i
End Sub
The long and short of what this module does, is it creates a "grid" of objects (cmdButtons, Image Boxes, Picture Boxes, etc...) it works pretty good, but because I can't "store" the information anywhere, it doesn't work exactly as I'd like :(
I'm very inexperienced with VB although my limited knowledge also applies to a few other languages so I'm not completely new to computer programming...
My problem is that I have a perfectly functioning Sub, but I want to turn it into a Function that would return a UDT of all the data created/set in the Function...
here's my code:
Public Type grid ' cant get it to work so that newGrid is a function that returns type grid
TILE_WIDTH As Integer
TILE_HEIGHT As Integer
TILE_GRIDWIDTH As Integer
TILE_GRIDHEIGHT As Integer
TILE_OFFSETX As Integer
TILE_OFFSETY As Integer
End Type
Public Sub newGrid(frm As Form, obj As Object, tWidth As Integer, tHeight As Integer, gWidth As Integer, gHeight As Integer, offSetX As Integer, offSetY As Integer)
tWidth = tWidth
tHeight = tHeight
Dim arrayElem As Object
If obj.Count > 1 Then
For i = 1 To (obj.Count - 1)
Set arrayElem = obj(i)
Unload arrayElem
Next i
End If
Set arrayElem = obj(0)
arrayElem.Left = offSetX
arrayElem.Top = offSetY
arrayElem.Width = 50
arrayElem.Width = tWidth
arrayElem.Height = tHeight
arrayElem.Visible = True
For i = 1 To (gWidth * gHeight) - 1
Load obj(i)
Set arrayElem = obj(i)
arrayElem.Left = (i * tWidth) Mod (tWidth * gWidth) + offSetX
arrayElem.Top = Int(i / gWidth) * tHeight + offSetY
arrayElem.Visible = True
Next i
End Sub
The long and short of what this module does, is it creates a "grid" of objects (cmdButtons, Image Boxes, Picture Boxes, etc...) it works pretty good, but because I can't "store" the information anywhere, it doesn't work exactly as I'd like :(