Skip to content

Instantly share code, notes, and snippets.

@Maffsie
Created October 28, 2009 20:05
Show Gist options
  • Save Maffsie/220772 to your computer and use it in GitHub Desktop.
Save Maffsie/220772 to your computer and use it in GitHub Desktop.
Option Explicit
Private Type MusicDB
Title As Variant
Artist As Variant
ReleaseYear As Integer
End Type
Dim viewed As Boolean
Dim searchstring As String
Dim path As String
Dim fileopen As Boolean
Dim pos As Integer
Dim greyness As String
Dim music As MusicDB
Private Sub cmdAdd_Click()
If Not viewed Then GoTo DontAdd
If fileopen Then Close
Open path For Random As 1
Dim keepGoing As Boolean
keepGoing = True
Do While keepGoing
Dim ans As String
ans = vbYes
Do While ans = vbYes
music.Title = InputBox("What is the title of the song you are adding?", "Song name?")
music.Artist = InputBox("What is the artist for " & music.Title & "?", "Artist?")
music.ReleaseYear = Val(Int(InputBox("What year was '" & music.Title & "', by '" & music.Artist & "' made?", "Release year?")))
If MsgBox("Artist: " & music.Artist & vbNewLine & "Title: " & music.Title & vbNewLine & "Year: " & music.ReleaseYear & vbNewLine & "Is this correct?", vbYesNo, "Verify info") = vbYes Then
ans = vbNo
End If
Loop
Put #1, pos + 1, music
lstArtist.AddItem music.Artist
lstTitle.AddItem music.Title
lstYear.AddItem music.ReleaseYear
pos = pos + 1
If MsgBox("Want to add another record?", vbYesNo, "Add another record?") = vbYes Then
keepGoing = True
Else
keepGoing = False
End If
Loop
Close
DontAdd:
If Not viewed Then MsgBox ("File ain't open!")
End Sub
Private Sub cmdAmendFile_Click()
If fileopen Then Close
If Not viewed Then GoTo notViewd
Dim amendpos As Integer
Open path For Random As 1
Dim ans As String
ans = vbYes
Do While ans = vbYes
amendpos = Val(Int(InputBox("Which record would you like to amend?")))
Get #1, amendpos, music
If MsgBox("Artist: " & music.Artist & vbNewLine & "Title: " & music.Title & vbNewLine & "Year: " & music.ReleaseYear & vbNewLine & "Is this correct?", vbYesNo, "Verify info") = vbYes Then
ans = vbNo
End If
Loop
ans = vbYes
Do While ans = vbYes
music.Title = InputBox("Input a new song title, or hit enter to skip", "Title?", music.Title)
music.Artist = InputBox("Input a new artist, or hit enter to skip", "Artist?", music.Artist)
music.ReleaseYear = Val(Int(InputBox("Input a new release year, or hit enter to skip", "Year?", music.ReleaseYear)))
If MsgBox("Artist: " & music.Artist & vbNewLine & "Title: " & music.Title & vbNewLine & "Year: " & music.ReleaseYear & vbNewLine & "Is this correct?", vbYesNo, "Verify info") = vbYes Then
ans = vbNo
End If
Loop
Put #1, amendpos, music
pos = 0
lstArtist.Clear
lstTitle.Clear
lstYear.Clear
Do While Not EOF(1)
pos = pos + 1
Get #1, pos, music
lstArtist.AddItem music.Artist
lstTitle.AddItem music.Title
lstYear.AddItem music.ReleaseYear
Loop
Close
notViewd:
If Not viewed Then MsgBox ("You didn't open the file first!")
End Sub
Private Sub cmdCreateFile_Click()
If fileopen Then Close
If Dir(path) <> "" Then
If MsgBox("File already exists. Clear it?", vbYesNo, "Clear file?") = vbYes Then
Kill (path)
Else
GoTo endCreate
End If
End If
Open path For Random As 1
pos = 0
fileopen = True
If viewed Then
lstArtist.Clear
lstTitle.Clear
lstYear.Clear
End If
If MsgBox("File Created. Add data immediately?", vbYesNo, "Add data?") = vbYes Then
Dim ans As String
ans = vbYes
Do While ans = vbYes
music.Title = InputBox("What is the title of the song you are adding?", "Song name?")
music.Artist = InputBox("What is the artist for " & music.Title & "?", "Artist?")
music.ReleaseYear = Val(Int(InputBox("What year was '" & music.Title & "', by '" & music.Artist & "' made?", "Release year?")))
If MsgBox("Artist: " & music.Artist & vbNewLine & "Title: " & music.Title & vbNewLine & "Year: " & music.ReleaseYear & vbNewLine & "Is this correct?", vbYesNo, "Verify info") = vbYes Then
ans = vbNo
End If
Loop
lstArtist.AddItem music.Artist
lstTitle.AddItem music.Title
lstYear.AddItem music.ReleaseYear
Put #1, pos + 1, music
End If
Close #1
fileopen = False
endCreate:
End Sub
Private Sub cmdDelete_Click()
If fileopen Then Close
If Not viewed Then GoTo delFail
Dim tDel As Integer
Dim arreh() As MusicDB
tDel = Int(Val(InputBox("Which record would you like to delete?")))
If fileopen Then Close
Open path For Random As 1
pos = 0
Do While Not EOF(1)
Get #1, pos + 1, music
arreh(pos) = music
pos = pos + 1
Loop
Dim outputTemp As String
for each
outputTemp = outputTemp & music.Title & vbNewLine
Set arreh = Nothing
delFail:
If Not viewed Then MsgBox ("You didn't open a file!")
End Sub
Private Sub cmdViewFile_Click()
If fileopen Then
Close
fileopen = False
End If
If Not viewed Then viewed = True
Open path For Random As 1
fileopen = True
pos = 0
lstTitle.Clear
lstArtist.Clear
lstYear.Clear
Do While Not EOF(1)
pos = pos + 1
Get #1, pos, music
lstArtist.AddItem music.Artist
lstTitle.AddItem music.Title
lstYear.AddItem music.ReleaseYear
Loop
Close #1
End Sub
Private Sub Form_activate()
fileopen = False
path = App.path & "\music.dat"
pos = 0
greyness = txtSearch.ForeColor
End Sub
Private Sub imgCancel_Click()
txtSearch.Text = ""
imgCancel.Visible = False
End Sub
Private Sub imgMagIcon_Click()
txtSearch.SelStart = 0
txtSearch.SelLength = Len(txtSearch.Text)
End Sub
Public Function rtSearch(str As String)
End Function
Private Sub tmrRTSearch_Timer()
If Not txtSearch.Text = searchstring And Not txtSearch.Text = "Search.." And viewed And fileopen Then
lstArtist.Clear
lstTitle.Clear
lstYear.Clear
imgCancel.Visible = True
searchstring = txtSearch.Text
If fileopen Then Close
Open path For Random As 1
pos = 0
Dim count As Integer
count = 0
Do While Not EOF(1)
Get #1, pos + 1, music
If InStr(music.Title, searchstring) <> 0 Or InStr(music.Artist, searchstring) <> 0 Or InStr(music.ReleaseYear, searchstring) <> 0 Then
lstArtist.AddItem music.Artist
lstTitle.AddItem music.Title
lstYear.AddItem music.ReleaseYear
count = count + 1
End If
pos = pos + 1
Loop
Dim srchOut As String
If count = 0 Then srchOut = "NO RESULTS"
If count > 0 Then srchOut = count & " RESULTS"
frmMain.Caption = "SUPER AWESOME SEARCH: SEARCHING FOR '" & searchstring & "' - " & srchOut
ElseIf Not fileopen And Not txtSearch.Text = "Search.." Then
MsgBox ("You can't search for something without opening the file! :(")
txtSearch.Text = "Search.."
imgCancel.Visible = False
frmMain.Caption = "SUPER AWESOME MUSIC LIBRARY"
End If
If frmMain.Caption <> "SUPER AWESOME MUSIC LIBRARY" And (txtSearch.Text = "Search.." Or txtSearch.Text = "") Then frmMain.Caption = "SUPER AWESOME MUSIC LIBRARY"
End Sub
Private Sub txtSearch_GotFocus()
If txtSearch.Text = "Search.." Then
txtSearch.Text = ""
Else
txtSearch.SelStart = 0
txtSearch.SelLength = Len(txtSearch.Text)
End If
txtSearch.ForeColor = vbBlack
End Sub
Private Sub txtSearch_LostFocus()
If txtSearch.Text = "" Then
txtSearch.Text = "Search.."
imgCancel.Visible = False
frmMain.Caption = "SUPER AWESOME MUSIC LIBRARY"
End If
txtSearch.ForeColor = greyness
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment