Results 1 to 3 of 3

Thread: Text file as database??? Maybe! [2005]

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Text file as database??? Maybe! [2005]

    Ok here's the situation. Want to control if certain websites are accessed. I can put in a name such as "yahoo" or "vbcity" or whatever in the code and it works. But I want to be able to add name to the list without rewriting the program everytime I want to add a site. Is this possible with a simple text file?
    The code below seems to retrieve the info that I need, but it puts 2 little squares between each name in the text file, I think then it looks for the site name with those 2 little suares added. If I just type one name in the text file it works, but when I type more than one, it doesn't. Thanks in advance.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         For Each proc As Process In Process.GetProcessesByName("iexplore") 'calls internet explorer process
    3.  
    4.             Dim intex As String = proc.MainWindowTitle.ToLower 'changes MainWindowTitle text to lower case
    5.            
    6.             Dim fileContents As String
    7.  
    8.             fileContents = My.Computer.FileSystem.ReadAllText("C:\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\textfile1.txt") 'reads text file
    9.  
    10.             If intex.Contains(fileContents) Then
    11.                 MsgBox("Found Window!")
    12.  
    13.             Else : MsgBox("Could not find window")
    14.             End If
    15.              
    16.         Next
    17.  
    18.     End Sub

    Thank You,
    Michael Ifland
    Visual Basic.NET 2005

  2. #2
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: Text file as database??? Maybe! [2005]

    Well first of all you should have all the strings you're comparing do so in lower case, because you may not know the exact casing of each website title.

    Second, you're loading a COMPLETE text file, and then checking the process caption against the WHOLE thing, which is a no-no. It won't work, because if you have two sites(i.e. "Yahoo!" and "Google"), it's going to check the process's caption for "Yahoo! Google", and not each individually.

    What you could do, is have the text file containing the website titles SEPARATE each title you wish to look for by a line break(VbCrLF) and then scan through the text file line by line and check for each title individually. For example(I'm just modifying your code in the reply window as I don't have VS open at the moment):

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         For Each proc As Process In Process.GetProcessesByName("iexplore") 'calls internet explorer process
    3.  
    4.             Dim intex As String = proc.MainWindowTitle.ToLower 'changes MainWindowTitle text to lower case
    5.            
    6.             Dim fileContents() As String
    7.  
    8.             fileContents = Split(My.Computer.FileSystem.ReadAllText("C:\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\textfile1.txt"), VbCrLf) 'reads text file
    9.  
    10.  
    11.             For i As Integer = 0 To UBound(fileContents)
    12.             If intex.ToLower.Contains(fileContents(i).ToLower) Then
    13.                 MsgBox("Found Window!") : Exit Sub
    14.  
    15.             Else : MsgBox("Could not find window")
    16.             End If
    17.              Next
    18.         Next
    19.  
    20.     End Sub
    God put me on this earth to do many great things, and I'm so far behind that I'm going to live forever.

    I'm programming for Windows using a Apple Mac Mini, 1.5Ghz with 512MB DDR RAM. I feel like I'm committing a crime :P

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: Text file as database??? Maybe! [2005]

    BrendanDavis,
    Thank you so much for your help, that works great. I was also talking with some other folks and they had me doing a "streamread". the only problem was this program was running on a timer every second. It wouldn't let me make any changes to the textfile because it was being used by another process(my program). This configuration allows me to add or take away from the textfile database. Thank you so much.
    Thank You,
    Michael Ifland
    Visual Basic.NET 2005

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width