Results 1 to 6 of 6

Thread: Have Visual Studio search text documents

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    19

    Have Visual Studio search text documents

    I'm brand new to programming, but this summer decided to make a program that would notify virtual pilots about who's airspace they are in.

    In my program, the user will enter their ID, and then Visual Studio will search a document for their ID, and come back with their callsign listed in the document.

    The documents are these:
    url0=http://vatsim-data.hardern.net/vatsim-data.txt
    url0=http://wazzup.flightoperationssystem.com/vatsim/vatsim-data.txt
    url0=http://vatsim.aircharts.org/vatsim-data.txt
    url0=http://info.vroute.net/vatsim-data.txt

    The rules state that I have to put ALL these sites in to read, and just let my program choose a server randomly. How would I set that up in Visual Basic? Sorry if this is a stupid question, I couldn't find anything that relates to what I really need.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Have Visual Studio search text documents

    Visual Studio is the development environment. It is your program that will be doing the searching. You write the program in Visual Studio, but that's all the involvement that VS has in the whole thing. Once the program is written, VS is no longer involved.

    What's the point behind choosing a server randomly? You can certainly do that, but it doesn't seem like a good way to do things. I suppose that you might get different response times from different servers on different days, or from different locations, but if the response time differs by day, you'd never know unless you hit each server each time and kept comparing response times. You could do that, but there's little reason for it. What might be better would be to try the first one first, if that fails try the second, and so on. In other words, not random, but sequential. If you have a need for it to be random, I'd be curious as to why, but it can be done. You could put the four into an array and choose a random number between 0 and 3 and use the server in that location.

    How often do the documents change? How big are they? If they change infrequently, you could cache the document locally, which would speed up search considerably, since there'd no longer be a need for a download step to start things out. If the documents change frequently, then that won't work at all.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    19

    Re: Have Visual Studio search text documents

    Quote Originally Posted by Shaggy Hiker View Post
    Visual Studio is the development environment. It is your program that will be doing the searching. You write the program in Visual Studio, but that's all the involvement that VS has in the whole thing. Once the program is written, VS is no longer involved.

    What's the point behind choosing a server randomly? You can certainly do that, but it doesn't seem like a good way to do things. I suppose that you might get different response times from different servers on different days, or from different locations, but if the response time differs by day, you'd never know unless you hit each server each time and kept comparing response times. You could do that, but there's little reason for it. What might be better would be to try the first one first, if that fails try the second, and so on. In other words, not random, but sequential. If you have a need for it to be random, I'd be curious as to why, but it can be done. You could put the four into an array and choose a random number between 0 and 3 and use the server in that location.

    How often do the documents change? How big are they? If they change infrequently, you could cache the document locally, which would speed up search considerably, since there'd no longer be a need for a download step to start things out. If the documents change frequently, then that won't work at all.

    I've designed the UI in Visual Studio, but I was assuming I write all the code in Visual Basic (the .vb of my program). The point in choosing a random server is because it was part of the rules for using the API. It frees up bandwidth I guess. It's required if I want to make this program.

    The documents update every 2 minutes, and are long.

    Could you explain how I would put them in VB as an array? I'm very new to this.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Have Visual Studio search text documents

    Visual Studio is a development environment for a variety of languages. VB is one of the languages, but there are MANY of them. All of the languages create stand alone programs (there are actually so many languages that there may be one that doesn't, but most do).

    You can create the array pretty simply, and will probably want this at form scope (outside of any method):

    Private myURLs as String() = {"http://vatsim-data.hardern.net/vatsim-data.txt", "http://wazzup.flightoperationssystem.com/vatsim/vatsim-data.txt", "http://vatsim.aircharts.org/vatsim-data.txt", "http://info.vroute.net/vatsim-data.txt"}

    You'd also want a Random object, which is what you will use to pick a random URL:

    Private myRand as New Random

    When you want to choose a random URL, you could do something like this:

    Dim chosenURL = myURLs(myRand.Next(0,4))
    My usual boring signature: Nothing

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Have Visual Studio search text documents

    Edit: What he said above...

    I'll just add this for the record, since you mentioned that an API exists for what you are doing, it seems odd to me that this "Rand" robin approach isn't just built into the API.
    Last edited by OptionBase1; May 28th, 2018 at 12:52 PM.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2018
    Posts
    19

    Re: Have Visual Studio search text documents

    Quote Originally Posted by Shaggy Hiker View Post
    Visual Studio is a development environment for a variety of languages. VB is one of the languages, but there are MANY of them. All of the languages create stand alone programs (there are actually so many languages that there may be one that doesn't, but most do).

    You can create the array pretty simply, and will probably want this at form scope (outside of any method):

    Private myURLs as String() = {"http://vatsim-data.hardern.net/vatsim-data.txt", "http://wazzup.flightoperationssystem.com/vatsim/vatsim-data.txt", "http://vatsim.aircharts.org/vatsim-data.txt", "http://info.vroute.net/vatsim-data.txt"}

    You'd also want a Random object, which is what you will use to pick a random URL:

    Private myRand as New Random

    When you want to choose a random URL, you could do something like this:

    Dim chosenURL = myURLs(myRand.Next(0,4))
    Okay, how does this look:
    Code:
    Public Class Form1
        Private Sub Connect_Click(sender As Object, e As EventArgs) Handles Connect.Click 'Connect function
            If Connect.Text = "Connect" And IsNumeric(CIDBox.Text) = True Then 'Checks if it's numbers in the box
                Dim chosenURL = myURLs(myRand.Next(0, 4))
                Connect.Text = "Disconnect"
                callsignbox.Text = "VIR12E"
            ElseIf Trim(CIDBox.Text & vbNullString) = vbNullString Then 'Checks if CID box is empty then shows instructions
                Instructions.Visible = True
            ElseIf IsNumeric(CIDBox.Text) = False Then 'Checks if CID box has letters then shows instructions
                NumberInfo.Visible = True
            ElseIf Connect.Text = "Disconnect" Then 'Disconnects them
                Connect.Text = "Connect"
                callsignbox.Text = vbNullString
            End If
        End Sub
        Private myURLs As String() = {"http://vatsim-data.hardern.net/vatsim-data.txt", "http://wazzup.flightoperationssystem.com/vatsim/vatsim-data.txt", "http://vatsim.aircharts.org/vatsim-data.txt", "http://info.vroute.net/vatsim-data.txt"}
        Private myRand As New Random
    End Class
    Let me just show a picture as well so it can make more sense:

    Name:  x6vkOEx.jpg
Views: 69
Size:  11.9 KB

    The user will enter their CID Number, and when they click "Connect", the program will search ONE of the 4 websites for their CID, and then return with their callsign in the box "Connected As". Did I put the code in their right? How would I say "Get CID number from the textbox and search one of the websites?"

    Sorry for all of these questions, I just want to make sure I'm doing this right.

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