|
-
Sep 20th, 2007, 07:26 PM
#1
Thread Starter
Member
[2005] help me avoid freezeups!
im running this code..
Code:
Dim DOMAIN As String = InputBox("what domain are you building on?", "swaybox", "http://spam.info")
Do Until ListBox1.Items.Count = 0
Dim myStreamReader As System.IO.StreamReader
myStreamReader = System.IO.File.OpenText(Application.StartupPath & "\keywords\" & ListBox1.Items.Item(0))
'Me.ListBox1.Items.Add(myStreamReader.ReadToEnd())
While myStreamReader.Peek <> -1
Me.ListBox2.Items.Add(myStreamReader.ReadLine)
End While
myStreamReader.Close()
Dim newnamesitefolder() As String = Split(ListBox1.Items.Item(0), ".")
CopyFiles(Application.StartupPath & "\template", Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0), True)
Do Until ListBox2.Items.Count = 0
'read the template
Dim load As New IO.StreamReader(Application.StartupPath & "\template\page.html")
Dim eek As String = load.ReadToEnd
load.Close()
Dim sRandom As New Random
Dim x As Long = sRandom.Next(100, base.TextLength)
Dim newcontent As String = Microsoft.VisualBasic.Strings.Left(base.Text, x)
Dim x2 As Long = sRandom.Next(3000, 5000)
newcontent = Microsoft.VisualBasic.Strings.Right(newcontent, x2)
'inject keywords
'TextBox1.Text = Replace(TextBox1.Text, " for ", " KEYWORD ")
'inject keywords
Dim ikw As Integer = 0
Dim pcountkw As Long = sRandom.Next(5, 10)
Do Until ikw = pcountkw
ikw = ikw + 1
Dim x3kw As Long = sRandom.Next(100, newcontent.Length)
newcontent = Microsoft.VisualBasic.Strings.Left(newcontent, x3kw) & ListBox2.Items.Item(0) & Microsoft.VisualBasic.Strings.Right(newcontent, newcontent.Length - x3kw)
Loop
'inject random paragraph headers
Dim i As Integer = 0
Dim pcount As Long = sRandom.Next(7, 12)
Do Until i = pcount
i = i + 1
Dim x3 As Long = sRandom.Next(100, newcontent.Length)
newcontent = Microsoft.VisualBasic.Strings.Left(newcontent, x3) & "</p><p>" & "A" & Microsoft.VisualBasic.Strings.Right(newcontent, newcontent.Length - x3)
Loop
'replace things
eek = Replace(eek, "<swaybox_keyword>", ListBox2.Items.Item(0))
eek = Replace(eek, "<swaybox_content>", newcontent)
Dim eekdomain() As String = Split(DOMAIN, ".")
eek = Replace(eek, "<swaybox_domain>", eekdomain(0))
'write the new page
Dim pagetowrite As String = Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & ListBox2.Items.Item(0) & ".shtml"
Dim writer As New IO.StreamWriter(pagetowrite)
writer.WriteLine(eek)
writer.Close()
'loop
'read the sitemap file
Dim loadsitemap As New IO.StreamReader(Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & "sitemap.txt")
Dim eeksitemap As String = loadsitemap.ReadToEnd
loadsitemap.Close()
'write to the sitemap file
Dim pagetowritesitemap As String = Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\sitemap.txt"
Dim writersitemap As New IO.StreamWriter(pagetowritesitemap)
writersitemap.WriteLine(eeksitemap & "<li><a href=""" & ListBox2.Items.Item(0) & ".shtml" & """>" & ListBox2.Items.Item(0) & "</a></li>")
writersitemap.Close()
ListBox2.Items.RemoveAt(0)
Loop
'create categories(take the first 10 keywords and make them into category pages and fill up cats.txt)
'populate listbox2
Dim catreader As System.IO.StreamReader
catreader = System.IO.File.OpenText(Application.StartupPath & "\keywords\" & ListBox1.Items.Item(0))
'Me.ListBox1.Items.Add(myStreamReader.ReadToEnd())
While catreader.Peek <> -1
Me.ListBox2.Items.Add(catreader.ReadLine)
End While
catreader.Close()
Do Until ListBox3.Items.Count = 10
ListBox3.Items.Add(ListBox2.Items.Item(0))
ListBox2.Items.RemoveAt(0)
Loop
Dim numberofpagespercat() As String = Split(ListBox2.Items.Count / 10, ".")
Do Until ListBox3.Items.Count = 0
'create a page with numberofpagespercat() number of pages linked off it
Dim pagelinks As String = ""
If ListBox2.Items.Count >= numberofpagespercat(0) Then
Dim pagecount As Integer = 0
Do Until pagecount = numberofpagespercat(0)
pagelinks = pagelinks & "<li><a href=""" & ListBox2.Items.Item(0) & ".shtml" & """>" & ListBox2.Items.Item(0) & "</a></li>"
ListBox2.Items.RemoveAt(0)
pagecount = pagecount + 1
Loop
Else
End If
'replace things. write map page
Dim loadcat As New IO.StreamReader(Application.StartupPath & "\template\cat.html")
Dim eek2 As String = loadcat.ReadToEnd
loadcat.Close()
If ListBox2.Items.Count > 1 Then
eek2 = Replace(eek2, "<swaybox_keyword>", ListBox2.Items.Item(0) & " categories and subpages")
eek2 = Replace(eek2, "<swaybox_content>", pagelinks)
'remove .info =D
Dim eekdomain() As String = Split(DOMAIN, ".")
eek2 = Replace(eek2, "<swaybox_domain>", eekdomain(0))
Dim pagetowrite As String = Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & ListBox2.Items.Item(0) & "-map.shtml"
Dim writer As New IO.StreamWriter(pagetowrite)
writer.WriteLine(eek2)
writer.Close()
'add that page to cats.txt
Dim loadcats As New IO.StreamReader(Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & "cats.txt")
Dim cats As String = loadcats.ReadToEnd
loadcats.Close()
Dim cattowrite As String = Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & "cats.txt"
Dim catwriter As New IO.StreamWriter(cattowrite)
catwriter.WriteLine(cats & vbCrLf & "<li><a href=""" & ListBox2.Items.Item(0) & "-map.shtml" & """>" & ListBox2.Items.Item(0) & "</a></li>")
catwriter.Close()
End If
ListBox3.Items.RemoveAt(0)
Loop
Dim loadindex As New IO.StreamReader(Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & "index.shtml")
Dim index As String = loadindex.ReadToEnd
loadindex.Close()
Dim newkw() As String = Split(ListBox1.Items.Item(0), ".")
index = Replace(index, "<swaybox_keyword>", newkw(0))
Dim newdomain As String = Replace(DOMAIN, ".info", "")
index = Replace(index, "<swaybox_domain>", newdomain)
Dim indexpath As String = Application.StartupPath & "\output\" & DOMAIN & "\" & newnamesitefolder(0) & "\" & "index.shtml"
Dim indexwriter As New IO.StreamWriter(indexpath)
indexwriter.WriteLine(index)
indexwriter.Close()
'im done with this keyword, remove from the first listbox and start over
TextBox1.Text = "created pages for """ & ListBox1.Items.Item(0) & """" & vbCrLf & TextBox1.Text
ListBox1.Items.RemoveAt(0)
Loop
however whenever i execute this code, or codes like it that loop in a similar fashion, my application appears to freeze until it is completed -_-. is there any way i could implement a progressbar to start when listbox1 is full and end at 100% when listbox1 is empty (when this code is completed it is emptied) and also avoid the application going into "not responding"
any help appreciated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|