이게 어쩌다 이렇게 된건지는 모르겠지만 이번에도 자세한 설명은 생략한다. 아무튼, 원하는대로 프로그램을 만들었다. 이것으로 레이저 한번 쏠 때마다 몇번 쐈는지 기록해 주는 프로그램을 작동시킬 사람 1명을 "절약"할 수 있게 되었다. 날림으로 만든 코드이며 매우 쉬우므로 소스코드 분석은 각자 해보기 바란다. 이런 프로그램을 다른데서 쓸 사람이 있을지는 모르겠지만 만약 사용하고 싶다면, 개인적인 용도로는 마음껏 써도 되지만 어딘가에 공표할 때에는 snowall의 명시적 허락을 받고 사용하길 바란다. (저작권료를 따로 청구하지는 않을 것이다.)


Public Class frmMain
    Private c As Integer = 0
    Private today As Integer = 0
    Private beginning As Integer = 0
    Private autoflag As Boolean = False
    Private diaflag As Boolean = False
    Private remoteFlag As Boolean = False
    Private filenumber As Integer = 0
    Private file As String()

    Public Property intcount() As Integer
        Get
            Return c
        End Get
        Set(ByVal value As Integer)

            If value < 0 Then
                c = 0
            Else
                c = value
            End If
            counting()
        End Set
    End Property

    Private Sub counting()
        txtCount.Text = intcount.ToString
        txtPresent.Text = (intcount - 1).ToString
        'txtToday.Text = today.ToString
        System.IO.File.WriteAllText(My.Application.Info.DirectoryPath & "\APRICounter.txt", txtCount.Text)
    End Sub

    Private Sub up()
        intcount += 1
        txtToday.Text = CInt(txtToday.Text) + 1
    End Sub

    Private Sub down()
        intcount -= 1
        txtToday.Text = CInt(txtToday.Text) - 1
    End Sub

    Private Sub reset()
        intcount = 0
        beginning = intcount
        txtToday.Text = 0
    End Sub

    Private Sub setting()
        Try
            intcount = CInt(txtSetCount.Text)
            beginning = intcount
            txtToday.Text = 0
        Catch
        End Try
    End Sub


    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        reset()
    End Sub

    Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
        up()
    End Sub

    Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
        down()
    End Sub

    Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click
        setting()
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            intcount = System.IO.File.ReadAllText(My.Application.Info.DirectoryPath & "\APRICounter.txt")
            beginning = intcount
            txtToday.Text = "0"
        Catch
            intcount = 0
        End Try
        txtDate.Text = System.DateTime.Today
    End Sub

    Private Sub btnFontSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFontSize.Click
        Dim fnt As Font
        fnt = New Font(System.Drawing.FontFamily.GenericSansSerif, CInt(txtFontSize.Text))
        txtCount.Font = fnt
    End Sub

    Private Sub btnAuto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAuto.Click
        If diaflag Or remoteFlag Then
            If autoflag Then
                btnAuto.Text = "Auto" & vbCr & "count"
            Else
                btnAuto.Text = "Stop" & vbCr & "count"
            End If

            autoflag = Not (autoflag)
            Timer1.Enabled = autoflag
            Exit Sub
        End If

        If Not diaflag Then
            MsgBox("First, Select auditing folder!")
            Exit Sub
        End If

        If Not remoteFlag Then
            MsgBox("First, Select auditing file!")
            Exit Sub
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If diaflag Then

            If filenumber <> System.IO.Directory.GetFiles(diaFolder.SelectedPath).Length Then
                file = System.IO.Directory.GetFiles(diaFolder.SelectedPath)
                txtCount.Text = CInt(filenameWashing(file, diaFolder.SelectedPath.Length)) + 1
                Me.txtPresent.Text = CInt(filenameWashing(file, diaFolder.SelectedPath.Length))
                txtToday.Text = CInt(txtToday.Text) + 1

            Else
                Exit Sub
            End If
            filenumber = System.IO.Directory.GetFiles(diaFolder.SelectedPath).Length
        End If
        If remoteFlag Then
            Dim n As New System.IO.StreamReader(OpenFileDialog1.FileName)
            Dim k As String
            k = n.ReadLine
            If txtToday.Text <> k Then
                txtPresent.Text = txtCount.Text
                txtCount.Text = CInt(txtCount.Text) + 1
                txtToday.Text = k 'CInt(txtToday.Text) + 1
            End If
            n.Close()
            n.Dispose()

        End If

        System.IO.File.WriteAllText(My.Application.Info.DirectoryPath & "\APRICounter.txt", txtCount.Text)
    End Sub

    Private Sub btnDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDir.Click
        If diaFolder.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            flagClean()
            diaflag = True
        End If
    End Sub

    Private Sub btnSetToday_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetToday.Click
        txtToday.Text = txtSetCount.Text
    End Sub

    Private Function filenameWashing(ByVal filename() As String, ByVal baseLength As Integer) As String
        'Dim f As String
        Dim files As Integer()
        ReDim files(filename.Length)
        Dim i As Integer

        Dim regexPattern As String = "[^0-9]"
        Dim regex As New System.Text.RegularExpressions.Regex(regexPattern)
        For i = 0 To filename.Length - 1
            files(i) = CInt(regex.Replace(filename(i).Substring(baseLength, filename(i).Length - 4 - baseLength), regexPattern, "")) 'CAUTION!!! This code will work WRONG
        Next
        Array.Sort(files)
        Return files(files.Length - 1)
    End Function

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnRemote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemote.Click
        If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            flagClean()
            remoteFlag = True
            txtToday.Text = 0

        End If

    End Sub

    Private Sub flagClean()
        remoteFlag = False
        diaflag = False
        autoflag = False
    End Sub
End Class


by snowall 2010.07.03 18:59
  • 꽃마조 2010.07.03 19:54 신고 ADDR EDIT/DEL REPLY

    빅뱅이론이 떠올랐으쇼 쉘든이 만든 프로그램이 일을 다해서 라쉬는 실직위기로 ㅋㅋ

    • snowall 2010.07.03 19:57 신고 EDIT/DEL

      원래 없던 사람이라서 짜를 사람도 없어요 ㅋㅋ

  • goldenbug 2010.07.03 23:23 ADDR EDIT/DEL REPLY

    빅뱅이론 지금도 계속 나오나요? 23편 이후가 궁금해지는데.....
    그나저나 생각보다 소스코드가 짧은데, 베이직의 위력이라 할 수 있을까요?

    • snowall 2010.07.03 23:28 신고 EDIT/DEL

      쓸데없는 부분을 다 쳐내면 50%정도 더 줄일 수 있습니다.
      위의 코드의 대부분은 임시로 때우려고 만든 부분들이 많아서 대부분은 쓰레기예요. 정리하기 귀찮아서 그냥 다 올렸습니다. 공부하고자 하는 학생이라면 알아서 정리해서 보겠죠 뭐. 고수라면 이런 소스는 볼 필요가 없구요.
      VB의 위력이라기보다는 원래 별로 할게 없는 프로그램이라서 -_-;