只做两个文件而不是 100 个
Only does two files instead of 100
基本上我有这个文件创建程序,它可以帮助我制作一堆文件,但出于某种原因,它只指定 2 个文件而不是 100 个文件。
代码:
Imports System.IO
Public Class Main
Dim CURRENT_NUM As Integer
Dim CONTENT_STRING As String
Dim PATH_STRING As String
Dim FROM_NUM As Integer
Dim TO_NUM As Integer
Public Sub SetupVar()
Try
CONTENT_STRING = tbContent.Text
PATH_STRING = tbPath.Text
FROM_NUM = Integer.Parse(tbFrom.Text)
TO_NUM = Integer.Parse(tbTo.Text)
Catch ex As Exception
End Try
End Sub
Private Sub Make()
tmrMake.Enabled = True
End Sub
Private Sub btnMake_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMake.Click
SetupVar()
Make()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub tmrMake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMake.Tick
'disable quit
'and control box
Me.ControlBox = False
btnQuit.Enabled = False
CURRENT_NUM = FROM_NUM
CURRENT_NUM = CURRENT_NUM + 1
Using sw As New StreamWriter(PATH_STRING & CURRENT_NUM & ".txt")
sw.Write(CONTENT_STRING)
End Using
If CURRENT_NUM = TO_NUM Then
btnQuit.Enabled = True
Me.ControlBox = True
tmrMake.Enabled = False
End If
End Sub
End Class
结果是文件夹中的c1和c2。而不是我在两个 tb 中指定的 1-100。
您需要移动一些代码,然后就可以了。请参阅下面的代码...
Imports System.IO
Public Class Main
Dim CURRENT_NUM As Integer
Dim CONTENT_STRING As String
Dim PATH_STRING As String
Dim FROM_NUM As Integer
Dim TO_NUM As Integer
Public Sub SetupVar()
Try
CONTENT_STRING = tbContent.Text
PATH_STRING = tbPath.Text
FROM_NUM = Integer.Parse(tbFrom.Text)
TO_NUM = Integer.Parse(tbTo.Text)
' Moved code from tmrMake_Tick to here
'disable quit
'and control box
Me.ControlBox = False
btnQuit.Enabled = False
CURRENT_NUM = FROM_NUM
Catch ex As Exception
End Try
End Sub
Private Sub Make()
tmrMake.Enabled = True
End Sub
Private Sub btnMake_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMake.Click
SetupVar()
Make()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub tmrMake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMake.Tick
Using sw As New StreamWriter(PATH_STRING & CURRENT_NUM & ".txt")
sw.Write(CONTENT_STRING)
End Using
' Increment your CURRENT_NUM after you've written the file
CURRENT_NUM = CURRENT_NUM + 1
If CURRENT_NUM = TO_NUM Then
btnQuit.Enabled = True
Me.ControlBox = True
tmrMake.Enabled = False
End If
End Sub
End Class
基本上我有这个文件创建程序,它可以帮助我制作一堆文件,但出于某种原因,它只指定 2 个文件而不是 100 个文件。 代码:
Imports System.IO
Public Class Main
Dim CURRENT_NUM As Integer
Dim CONTENT_STRING As String
Dim PATH_STRING As String
Dim FROM_NUM As Integer
Dim TO_NUM As Integer
Public Sub SetupVar()
Try
CONTENT_STRING = tbContent.Text
PATH_STRING = tbPath.Text
FROM_NUM = Integer.Parse(tbFrom.Text)
TO_NUM = Integer.Parse(tbTo.Text)
Catch ex As Exception
End Try
End Sub
Private Sub Make()
tmrMake.Enabled = True
End Sub
Private Sub btnMake_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMake.Click
SetupVar()
Make()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub tmrMake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMake.Tick
'disable quit
'and control box
Me.ControlBox = False
btnQuit.Enabled = False
CURRENT_NUM = FROM_NUM
CURRENT_NUM = CURRENT_NUM + 1
Using sw As New StreamWriter(PATH_STRING & CURRENT_NUM & ".txt")
sw.Write(CONTENT_STRING)
End Using
If CURRENT_NUM = TO_NUM Then
btnQuit.Enabled = True
Me.ControlBox = True
tmrMake.Enabled = False
End If
End Sub
End Class
结果是文件夹中的c1和c2。而不是我在两个 tb 中指定的 1-100。
您需要移动一些代码,然后就可以了。请参阅下面的代码...
Imports System.IO
Public Class Main
Dim CURRENT_NUM As Integer
Dim CONTENT_STRING As String
Dim PATH_STRING As String
Dim FROM_NUM As Integer
Dim TO_NUM As Integer
Public Sub SetupVar()
Try
CONTENT_STRING = tbContent.Text
PATH_STRING = tbPath.Text
FROM_NUM = Integer.Parse(tbFrom.Text)
TO_NUM = Integer.Parse(tbTo.Text)
' Moved code from tmrMake_Tick to here
'disable quit
'and control box
Me.ControlBox = False
btnQuit.Enabled = False
CURRENT_NUM = FROM_NUM
Catch ex As Exception
End Try
End Sub
Private Sub Make()
tmrMake.Enabled = True
End Sub
Private Sub btnMake_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMake.Click
SetupVar()
Make()
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub tmrMake_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMake.Tick
Using sw As New StreamWriter(PATH_STRING & CURRENT_NUM & ".txt")
sw.Write(CONTENT_STRING)
End Using
' Increment your CURRENT_NUM after you've written the file
CURRENT_NUM = CURRENT_NUM + 1
If CURRENT_NUM = TO_NUM Then
btnQuit.Enabled = True
Me.ControlBox = True
tmrMake.Enabled = False
End If
End Sub
End Class