Running code.

S

shapper

Hello,

I have been using VB and C# in Visual Studio for a long time but never
used it with Excel.
I have an Excel sheet with 16 images. Each one in each cell and having
a name of img1, img2, ....

I have some VB code which I want to run. When I run it am I asked for
a Macro name.

Could someone, please, give me some tips on how to run this game code?

Here is the code:

Option Explicit

' TYPES >

' GameType
Type GameType
img(1 To 6, 1 To 6) As String
LastRow As Integer
LastCol As Integer
Score As Integer
End Type ' GameType


' VARIABLES >
Public game As GameType


' METHODS >

' MyWait
Sub MyWait(ByVal wt As Single)
Dim t As Single
t = Timer
Do
Loop Until Timer - t > wt
End Sub ' MyWait

' Positioning
Sub Positioning(ByRef game As GameType, ByVal r As Integer, ByVal c As
Integer)
Dim hc As Single, hf As Single, wc As Single, wf As Single
Dim nf As String
On Error GoTo fim
With Range("tabuleiro")
hc = .Cells(r, c).Height
wc = .Cells(r, c).Width
nf = game.img(r, c)
hf = ActiveSheet.Shapes(nf).Height
wf = ActiveSheet.Shapes(nf).Width
ActiveSheet.Shapes(nf).Top = .Cells(r, c).Top + (hc - hf) / 2
ActiveSheet.Shapes(nf).Left = .Cells(r, c).Left + (wc - wf) / 2
End With
fim:
End Sub ' Positioning

' Hide
Sub Hide(ByRef game As GameType, ByVal r As Integer, ByRef c As
Integer)
With game
ActiveSheet.Shapes(.img(r, c)).Visible = False
End With
DoEvents
End Sub ' Hide

' Show
Sub Show(ByRef game As GameType, ByVal r As Integer, ByRef c As
Integer)
With game
ActiveSheet.Shapes(.img(r, c)).Visible = True
End With
DoEvents
End Sub ' Show

' IsVisible
Function IsVisible(ByRef game As GameType, ByVal r As Integer, ByRef c
As Integer) As Boolean
With game
IsVisible = ActiveSheet.Shapes(.img(r, c)).Visible
End With
End Function ' IsVisible

Thanks,
Miguel
 
J

Jim Thomlinson

All of the code that you posted requires arguments in order to run. Where are
you calling your subs from. Ultimately it must be called from something that
does not require any arguments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top