The User Input Screen
'Please note that there is a flowchart of the algorithms in this code in Appendix A, Figure 5
'For an indented version of the code, see the Printable Final Report.
'The Cancer Modeling Project: Tracking Cancer Development and Movement
'Punit Shah and Karalyn Baca
'Team 004
' Albuquerque Academy
'AiS 2004-2005
'Code written in Microsoft Visual Basic 6.0, line comment charecter is '
'Code for: frmInput
'Purpose of module: Where the data is inputed and then all actions are delt with
Option Explicit 'Force variable declerations
'Dim Modular vars (not project-wide visible)
Private ModelSizeX As Integer 'The height of the model
Private ModelSizeY As Integer 'The width of the model
Private CancerModel() As GraphicCell 'Defines the array which will hold the objects of the GraphicsCell class
Private SweepCounter As Integer
'COMMENTS FOR OUR SELVES:
'-When we finish the program, make frmSplash the starting screen
'This is the main procedure that is called when the user clicks the "Run Simulation" button
Private Sub mnuMain_Click()
'Purpose: to initiate all actions to be taken, project main
'Dim vars that then take user inputs and set themselves equal to the appropriate one
Dim StartX As Integer 'Mole starting position, x coordinate part
StartX = txtStartX.Text - 1
Dim StartY As Integer 'Mole starting position, y coordingate part
StartY = txtStartY.Text - 1
Dim GUIRefreshRate As Integer 'How often program should update the primary model GUI
GUIRefreshRate = txtGUIRefresh.Text
Dim DevCycles As Integer 'How many sweep-sets we should do to develop the cacner
DevCycles = txtDevCycles.Text
ModelSizeX = txtModelSizeX.Text - 1 'Sets the model width to what it should be
ModelSizeY = txtModelSizeY.Text - 1 'Sets the model height to what it should be
'Give a size to the array organizing all of the objects of the model
'Have to do this here instead of above as VB only allows for this assignment to occur
'inside of a procedure
ReDim CancerModel(ModelSizeX + 1, ModelSizeY + 1) As GraphicCell
'Do the modeling
Call InitiateAction(StartX, StartY, DevCycles, GUIRefreshRate)
'Call all closing procedures
Call FinishingActions
End Sub
Private Sub InitiateAction(ByRef MoleStartingX As Integer, ByRef MoleStartingY As Integer, ByRef TotalDevCycles As Integer, ByRef GUIRefreshRate As Integer)
'Purpose: to initiate following the model until the time when the user is done modeling
'For loop Variable Declarations
Dim x As Integer
Dim y As Integer
'Prepare the graph form for the graph
Call SetUpGraph(TotalDevCycles)
'Now create the objects of the class for each cell of the graphics
For x = 0 To ModelSizeX
For y = 0 To ModelSizeY
Set CancerModel(x, y) = New GraphicCell
Next y
Next x
'Create the initial cancer at location specified by user
CancerModel(MoleStartingX, MoleStartingY).IsCancerous = True
'Show Simulation Screens
frmSimulation.Show 'Where the simulation is draws
frmCellCount.Show 'Where the cell count graph will go
'For loop to have development cylces go through specified amount of times
For SweepCounter = 1 To TotalDevCycles
'Go throught the sweeps
Call SweepTabulate 'Sweep #1, Tabulate, see procedure for purpose
Call SweepGrow 'Sweep #2, Grow, see procedure for purpose
Call SweepReset 'Sweep #3, Reset, see procedure for purpose
'Check to see if we need to update the cross section of the skin
If SweepCounter Mod GUIRefreshRate = 0 Then
Call PrepForm 'Clears screen and scales for easier drawing
'Print the cancerous cell data to the screen
For x = 0 To ModelSizeX 'loop through "x"s
For y = 0 To ModelSizeY 'loop through "y"s
If CancerModel(x, y).IsCancerous = True Then
frmSimulation.Line (x, y)-(x + 1, y + 1), vbRed, BF 'Red cancer cells (squares)
Else
frmSimulation.PSet (x, y), QBColor(8) ' Grey health cell (dots)
End If
Next y
Next x
'Draws small circle for the starting point
frmSimulation.FillStyle = 0
frmSimulation.Circle (MoleStartingX, MoleStartingY), 1, vbBlack
'Draw the skin layers and model axises ontop of the cancer model
frmSimulation.Scale (-50, 1000)-(1050, -50) 'Changed scale so that over-diagram looks right
Call DrawAxes
Call DrawLayers
End If
Next SweepCounter
End Sub
Private Sub PrepForm()
'Purpose: to prepare the form for the cancer model cross-section
'clear form
frmSimulation.Cls
'scale form for easier numbers to draw with
frmSimulation.Scale (-(1 / 20) * (2 * (ModelSizeX + 1)), (21 / 20) * (ModelSizeY + 1))-((21 / 20) * (2 * (ModelSizeX + 1)), -(1 / 20) * (ModelSizeY + 1))
End Sub
Private Sub DrawAxes()
'Purpose: to draw x and y axis of the frmSimulation form
'x-axis
frmSimulation.Line (0, 0)-(600, 0)
'y-axis
frmSimulation.Line (0, 0)-(0, 900)
'label the x-axis
Dim x As Integer
For x = 0 To 450 Step 150
frmSimulation.CurrentX = x
frmSimulation.CurrentY = 0
frmSimulation.Print x
Next x
'label the y-axis
Dim i As Integer
For i = 0 To 900 Step 150
frmSimulation.CurrentX = -39
frmSimulation.CurrentY = i - 6
frmSimulation.Print i
Next i
End Sub
Private Sub DrawLayers()
'Purpopse: to draw the layers of the skin onto the model
'Make and set Pi
Dim Pi As Double
Pi = 3.14159265357932
'Sets font/size for the form
frmSimulation.Font = "Arial"
frmSimulation.FontSize = 10
'Below are the lines of code that write the different names of the layers
'and also draw the strait/wavy lines that define these layers
frmSimulation.CurrentX = 15
frmSimulation.CurrentY = 900
frmSimulation.Print "The Outside World"
frmSimulation.Line (0, 810)-(600, 810) 'top of epidermis
frmSimulation.CurrentX = 15
frmSimulation.CurrentY = 750
frmSimulation.Print "Epidermis"
'To make the wavy lines for the layer
frmSimulation.Circle (40, 600), 40, , Pi, 2 * Pi
frmSimulation.Circle (95, 600), 15, , 0, Pi
frmSimulation.Circle (170, 600), 60, , Pi, 2 * Pi
frmSimulation.Circle (280, 600), 50, , 0, Pi
frmSimulation.Circle (390, 600), 60, , Pi, 2 * Pi 'Wavy top of germanal
frmSimulation.Circle (480, 600), 30, , 0, Pi
frmSimulation.Circle (550, 600), 40, , Pi, 2 * Pi
frmSimulation.Circle (605, 600), 15, , 0, Pi
frmSimulation.CurrentX = 15
frmSimulation.CurrentY = 510
frmSimulation.Print "Germinal Layer"
frmSimulation.Line (0, 390)-(600, 390)
frmSimulation.CurrentX = 15
frmSimulation.CurrentY = 300
frmSimulation.Print "Dermis"
'Note for the user that measurements along y-axis are arbitrary
frmSimulation.CurrentX = 0
frmSimulation.CurrentY = 1000
frmSimulation.Print "Note: All axis measures are arbitrary"
End Sub
Private Sub SweepTabulate()
'Purpose: this is the first sweep. It checks which cells are cancerous and notes those which currently
' are. This is so the cells that get cancerous during this development cycle are not further developed
' during this development cycle.
'Variable definitions
'Counters
Dim Counter1 As Integer, Counter2 As Integer
'We will use this information for the graph (counts cancerous cells)
Dim CellCounter As Integer
'Sweep through and check for cancerous cells and notate those cells
For Counter1 = 0 To ModelSizeX 'goes through "x"s
For Counter2 = 0 To ModelSizeY 'goes through "y"s
'Checks to see if the current cell is cancerous
If CancerModel(Counter1, Counter2).IsCancerous = True Then
'If cell is cancerous, notates in "HasBeenSwept" property
CancerModel(Counter1, Counter2).HasBeenSwept = True
'Adds to the counter of how many cancerous cells
CellCounter = CellCounter + 1
End If
Next Counter2
Next Counter1
'Do the gaphing of amount of cells, passing how many cancerous cells
Call UpdateGraph(CellCounter)
End Sub
Private Sub SweepGrow()
'Purpose: this is the second sweep. It develops the cells that were deemed cancerous in the
' previous sweep.
'Variable definitions
'Counters
Dim Counter1 As Integer, Counter2 As Integer
'Goes through model and calls procedure to check and infect neighbors
For Counter1 = 0 To ModelSizeX
For Counter2 = 0 To ModelSizeY
'Checks if this was one of the previously notated cells as notated in sweep 1
If CancerModel(Counter1, Counter2).HasBeenSwept = True Then
'Calls sub to infect neighbors of this cancerous cell
Call InfectNeighbors(Counter1, Counter2)
End If
Next Counter2
Next Counter1
End Sub
Private Sub SweepReset()
'Purpose: this is sweep three. Here, the program changes all of the HasBeenSwept properties
' to false so that next time we do sweep 1, we will have a clean "HasBeenSwept" property
' to work with.
'Variable definitions
'Counters
Dim Counter1 As Integer, Counter2 As Integer
'Sweeps through the model and resets "HassBeenSwep property
For Counter1 = 0 To ModelSizeX
For Counter2 = 0 To ModelSizeY
'If perviously notated cell, only then resets
If CancerModel(Counter1, Counter2).HasBeenSwept = True Then
'Sets property to original value
CancerModel(Counter1, Counter2).HasBeenSwept = False
End If
Next Counter2
Next Counter1
End Sub
Private Sub InfectNeighbors(ByVal LocationX As Integer, ByVal LocationY As Integer)
'Purpose: to check to see if neighbors can be infected and then infects if can be
'variables to use to check new coordinates
Dim CurrentNeighborX As Integer
Dim CurrentNeighborY As Integer
'Goes through the different 8 neighbors checking
'NW location
CurrentNeighborX = LocationX - 1
CurrentNeighborY = LocationY + 1
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'N location
CurrentNeighborX = LocationX
CurrentNeighborY = LocationY + 1
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'NE location
CurrentNeighborX = LocationX + 1
CurrentNeighborY = LocationY + 1
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'E location
CurrentNeighborX = LocationX + 1
CurrentNeighborY = LocationY
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'SE location
CurrentNeighborX = LocationX + 1
CurrentNeighborY = LocationY - 1
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'S location
CurrentNeighborX = LocationX
CurrentNeighborY = LocationY - 1
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'SW location
CurrentNeighborX = LocationX - 1
CurrentNeighborY = LocationY - 1
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
'W location
CurrentNeighborX = LocationX - 1
CurrentNeighborY = LocationY
'Check to see if the points are in range, and if so develop the cancer in this direction
If CurrentNeighborX > -1 And CurrentNeighborX <= ModelSizeX And CurrentNeighborY > -1 And CurrentNeighborY <= ModelSizeY Then
If ShouldIInfect(CurrentNeighborX, CurrentNeighborY) = True Then
'Check to see probabiliy of infection due to location and then infect if probability correct
CancerModel(CurrentNeighborX, CurrentNeighborY).IsCancerous = True
End If
End If
End Sub
Private Function ShouldIInfect(ByVal LocationX As Integer, ByVal LocationY As Integer) As Boolean
'Purpose: This is where many of the factors of the program come together to determine
'if the cell around it should be infected taking into effect probability calculated
'using infromation about the different influencing factors.
Randomize 'Makes the random numbers truly random instead of off of a list for testing
'Variable definitions
'The random number determind later in the sub
Dim RandomNumber As Integer
'Defines counter for adding odds and sets to 1 (1/1 odds initially)
Dim ProbabilityCounter As Integer
ProbabilityCounter = 1
'These following statements will add to the counter which will be used for the probablility
'Skin layer preassure and other primary physical infuelces
If (1 / 10) * ModelSizeY < Abs((ModelSizeY / 2) - LocationY) Then
ProbabilityCounter = ProbabilityCounter + 15
End If
ProbabilityCounter = ProbabilityCounter + 1 'Natural cell growth chance
'Use the counter to determine whether the cancer should grow at current location
RandomNumber = Int(ProbabilityCounter * Rnd)
If RandomNumber = 0 Then
ShouldIInfect = True
Else
ShouldIInfect = False
End If
End Function
Private Sub SetUpGraph(ByVal MaxDevCycles As Integer)
'Purpose: to set up the graph form for taking the graph inputs
frmCellCount.Cls 'Earases form, gives us clean board to draw on
Dim MaxCellCount As Double
MaxCellCount = (ModelSizeX + 1) * (ModelSizeY + 1)
'Scales the form so numbers work out easier when drawing to form
frmCellCount.Scale (-(3 / 20) * MaxDevCycles, (22 / 20) * MaxCellCount)-((22 / 20) * MaxDevCycles, -(6 / 20) * MaxCellCount)
'x-axis label
frmCellCount.CurrentX = (1 / 20) * MaxDevCycles
frmCellCount.CurrentY = 0
frmCellCount.Print "Development Cylces (x-axis)"
'x-axis max value
frmCellCount.CurrentX = (20.5 / 20) * MaxDevCycles
frmCellCount.CurrentY = 0
frmCellCount.Print MaxDevCycles
'y-axis label
frmCellCount.CurrentX = -(1 / 20) * MaxDevCycles
frmCellCount.CurrentY = (21.5 / 20) * MaxCellCount
frmCellCount.Print "Cell Count (y-axis)"
'y-axis max value
frmCellCount.CurrentX = -(3 / 20) * MaxDevCycles
frmCellCount.CurrentY = MaxCellCount
frmCellCount.Print MaxCellCount
'Draw axises
frmCellCount.Line (-(1 / 20) * MaxDevCycles, 0)-(MaxDevCycles, 0) 'x-axis
frmCellCount.Line (0, -(1 / 20) * MaxCellCount)-(0, MaxCellCount) 'y-axis
'Write Description
frmCellCount.CurrentX = -(1 / 20) * MaxDevCycles
frmCellCount.CurrentY = MaxCellCount * -(2.5 / 20)
frmCellCount.Print "Description: This graph shows the exponential growth of the"
frmCellCount.CurrentX = -(1 / 20) * MaxDevCycles
frmCellCount.CurrentY = MaxCellCount * -(4 / 20)
frmCellCount.Print "cancer, which then levels out (called a 'sigmoital curve')."
End Sub
Private Sub UpdateGraph(ByVal CurrentCellCount As Integer)
'Purpose: to update the graph of how many cancerous cells there are
'Variable definitions
'This is the var to track where the previous point was so we know where to
'draw the new line of the graph from
'Don't have to track the old x-coordinate as this is always sweepcounter - 1
'Previous number of cells, set initially to 0 (for firts coordinate)
Static PreviousY As Integer
If SweepCounter = 1 Then
PreviousY = 0
End If
'Graph the new point by drawing line from previous one to new one
frmCellCount.Line (SweepCounter - 1, PreviousY)-(SweepCounter, CurrentCellCount)
'Make the current points the now-previous points
PreviousY = CurrentCellCount
End Sub
Private Sub FinishingActions()
'Purpose: to wrap up the program and do some ending commands
'Make "beep" and come up with a message box notifying user program is done modeling to point specified
Beep
MsgBox ("The propgram has finished modeling the cancer growth to the stage of development you chose to end at. Thank you for using The Cancer Modeling Project. Feel free to enter new values and re-run.") ', , "The Cancer Modeling Project - Simulation Completed")
'Counts the number of cancerous cells
Dim x As Integer, y As Integer
Dim CancerCellCount As Integer
For x = 0 To ModelSizeX
For y = 0 To ModelSizeY
If CancerModel(x, y).IsCancerous = True Then
'Adds to counter if cancerous
CancerCellCount = CancerCellCount + 1
End If
Next y
Next x
'Prints the message of how many cancerous cells there were when the simulation was done running
frmSimulation.CurrentX = 550
frmSimulation.CurrentY = 775
frmSimulation.Print "There were " & CancerCellCount & " cancerous cells"
frmSimulation.CurrentX = 550
frmSimulation.CurrentY = 725
frmSimulation.Print "when the simulation ended. There"
frmSimulation.CurrentX = 550
frmSimulation.CurrentY = 645
frmSimulation.Print "was only 1 cancerous cell initially."
End Sub
'Makes whole program end when the input screen is closed
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
'Other menu bottons procedures that are activated when they are clicked
Private Sub mnuExit_Click()
End 'End program
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show 'Show the About screen
End Sub