I am creating an open source video game called "WubStar"(Like guitar hero for electronic music). I got a good portion through and then encountered an error. The Write sub-routine isn't running, AT ALL! Here's the code for the form I encountered the error on, please take a look, I'm hoping that if someone looks at it with a fresh set of eyes they'll be able to catch a (probably small) error that I wasn't able to catch, thanks in advance,
Jordan
VB.net code(Somewhat annotated):
Imports System.Drawing
Imports System.IO
Public Class Form2
Dim pWidth As Integer = 750
Dim pHeight As Integer = 550
Dim tSize As Integer = 32
Dim G As Graphics
Dim BBG As Graphics
Dim BBI As Bitmap
Dim pTile As Bitmap
Dim S1 As Bitmap
Dim S2 As Bitmap
Dim sRect As Rectangle
Dim dRect As Rectangle
Dim tSec As Integer = TimeOfDay.Second
Dim Tick As Integer = 0
Dim Max As Integer = 0
Dim isRunning As Boolean = True
Public isWaiting As Boolean = False
Dim mouseX As Integer = 15
Dim mouseY As Integer = 9
Dim lMouse As Boolean = False
Dim rMouse As Boolean = False
Dim Key1 As Boolean = False
Dim Key2 As Boolean = False
Dim Key3 As Boolean = False
Dim Key4 As Boolean = False
Dim Key5 As Boolean = False
Dim Key6 As Boolean = False
Dim Key7 As Boolean = False
Dim Key8 As Boolean = False
Dim Up As Boolean = False
Dim Down As Boolean = False
Dim mLength(tSize * 4, 0) As Integer
Dim nMap(11, 0) As Integer
Dim nMapSave(11, 0) As Integer
Dim nMax As Integer = 0
Dim Count As Integer = 0
Dim inc As Integer = 8
Dim gMax As Integer
Dim dCount As Integer = 0
Dim nMapSize As Integer = tSize / 4
Public Song As String
Dim Path As String
Dim Browse As OpenFileDialog
Public LoadSong As Boolean = False
Private Sub Form2_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
MsgBox("nMap 0,0: " & nMap(0, 0))
MainMenu.Show()
End Sub
Private Sub Form2_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.Show()
Me.Focus()
G = Me.CreateGraphics
BBI = New Bitmap(pWidth, pHeight)
pTile = New Bitmap(Sprites.BG.Image)
S1 = New Bitmap(Sprites.S1.Image)
S2 = New Bitmap(Sprites.S2.Image)
If LoadSong = False Then
For i As Integer = 0 To 11
nMap(i, 0) = 0
Next
End If
If LoadSong = False Then
Browse = New OpenFileDialog
Browse.Filter = "Audio Wave Files|*.wav"
Browse.Title = "Open Song"
If Browse.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Path = Browse.FileName()
Else
MsgBox("Couldn't open file", MsgBoxStyle.Critical, "Error")
End
End If
Song = InputBox("Song Name:", "Name")
If Not Song = "" Then
Try
MkDir(CurDir() & "\Data\" & Song)
Catch ex As Exception
End
MsgBox(ex, MsgBoxStyle.Critical, "Error")
End Try
Try
If My.Computer.FileSystem.FileExists(CurDir() & "\Data\Songs.slst") Then
Using Write As StreamWriter = New StreamWriter(CurDir() & "\Data\Songs.slst", True)
Write.WriteLine(Song)
Write.Close()
Write.Dispose()
End Using
Else
Using Write As StreamWriter = New StreamWriter(CurDir() & "\Data\Songs.slst")
Write.Write(Song & vbNewLine)
End Using
End If
Using Write As StreamWriter = New StreamWriter(CurDir() & "\Data\" & Song & "\" & Song & ".wub")
Write.WriteLine("#Generated: " & DateAndTime.Now)
Write.Close()
Write.Dispose()
End Using
Catch ex As Exception
MsgBox(ex, MsgBoxStyle.Critical, "Error")
End
End Try
Try
FileCopy(Path, CurDir() & "\Data\" & Song & "\" & Song & ".wav")
Catch ex As Exception
MsgBox(ex, MsgBoxStyle.Critical, "Error")
End Try
End If
ElseIf LoadSong = True Then
Me.Hide()
LoadForm.Show()
isWaiting = True
Do While isWaiting = True
Application.DoEvents()
Loop
LoadForm.Hide()
Me.Show()
End If
Designer(Song)
End
End Sub
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.A
Key1 = True
Case Keys.S
Key2 = True
Case Keys.D
Key3 = True
Case Keys.F
Key4 = True
Case Keys.H
Key5 = True
Case Keys.J
Key6 = True
Case Keys.K
Key7 = True
Case Keys.L
Key8 = True
Case Keys.Escape
isRunning = False
End Select
End Sub
Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Select Case e.KeyCode
Case Keys.A
Key1 = False
Case Keys.S
Key2 = False
Case Keys.D
Key3 = False
Case Keys.F
Key4 = False
Case Keys.H
Key5 = False
Case Keys.J
Key6 = False
Case Keys.K
Key7 = False
Case Keys.L
Key8 = False
End Select
End Sub
Private Sub Designer(ByVal Name As String)
G.DrawImage(pTile, 0, 0)
MsgBox("Song load/creation successfull, going to designer", MsgBoxStyle.Information, "Success")
Do While isRunning = True
Application.DoEvents()
Write()
Draw()
Save()
If Up = True & Count = 0 Then Else If Up = True Then Count -= 1
If Down = True & Count = nMax Then
nMapSave = nMap
nMax += 1
ReDim nMap(11, nMax)
nMap = nMapSave
ReDim nMapSave(11, nMax)
Count += 1
ElseIf Down = True Then
Count += 1
End If
Loop
End Sub
Private Sub Write()
If Key1 = True & nMap(0, Count) = 0 Then
nMap(0, Count) = 1
ElseIf Key1 = True Then
nMap(0, Count) = 0
End If
End Sub
Private Sub Draw()
End Sub
Private Sub Save()
End Sub
End Class