Click here to Skip to main content
15,885,546 members

VB.net sub not running HELP

Sicppy asked:

Open original thread
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):
VB
Imports System.Drawing
Imports System.IO

Public Class Form2

    'Game Palet
    Dim pWidth As Integer = 750
    Dim pHeight As Integer = 550
    Dim tSize As Integer = 32

    'Graphics Vars
    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

    'Framerate Vars
    Dim tSec As Integer = TimeOfDay.Second
    Dim Tick As Integer = 0
    Dim Max As Integer = 0

    'Game State
    Dim isRunning As Boolean = True
    Public isWaiting As Boolean = False

    'Mouse Mapping
    Dim mouseX As Integer = 15
    Dim mouseY As Integer = 9

    'Mouse Button Handler Vars
    Dim lMouse As Boolean = False
    Dim rMouse As Boolean = False

    'Key Handler Vars
    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

    'Note Mapping
    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

    'Song Vars
    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()

        'Initialize Graphics
        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)

        'Initialize nMapping Vars
        If LoadSong = False Then
            For i As Integer = 0 To 11
                nMap(i, 0) = 0
            Next
        End If

        'Initialize Game Vars
        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
                    'Save song in songs database
                    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

                    'Create .wub file to store notes
                        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)
        'On Error GoTo A
        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()
            'Check for Up/Down arrow events
            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
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900