Results 1 to 21 of 21

Thread: Read Content From Page and Put into TextBox's

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Read Content From Page and Put into TextBox's

    Hi Guys,

    Im working on a application that will read content in a certain format from a custom php page that will echo out SQL Info. The PHP Page will echo in the following format;

    FlightID=UAL001;
    DEPICAO=KMCI;
    ARRICAO=KLAX;
    Route=WLDCAT1-ART-Loop4;
    Comments=Enjoy;

    And in my visual basic application, I have the following Text Box's

    Flight ID
    Departure ICAO
    Arrival ICAO
    Route
    Comments

    When the user presses the button "Load Flight", I want the info from FlightID to go in Flight ID, The info in DEPICAO to go in Departure ICAO, And so on. Can someone provide me the easiest way to do this? Thanks a bunch!

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    If your information consists entirely of key=value pairs then the easiest way is to use Split method of the String object:

    Code:
    Dim TestString As String = "FlightID=UAL001"
    Dim KeyAndValue() As String ' it's an array
    
    ' The Split method will return a 2 element array with "FlightID" and "UAL001"
    KeyAndValue = TestString.Split(New Char() {"="c})
    The rest depends on what else do you want to know.
    Your task now consists of actually reading the source stream (a php page or a file or something else - basically you will need an IO.StreamReader class).

    Then you just need to perform 'splitting' to each key and value pair and put values to according text boxes. It would probably be easier if you name each of your textboxes to match exactly the names of fields in the source stream. This way you could skip tedious process of selecting the right textbox for putting a value into it - your Key part will hold the name of the textbox you need.

    Also, if your source information looks like this instead:
    "FlightID=UAL001;DEPICAO=KMCI;ARRICAO=KLAX;Route=WLDCAT1-ART-Loop4;Comments=Enjoy;" (i.e. without line breaks) you will need to perform split twice.
    Firstly you should use ";" as a separator - to get an array of "Key=Value" strings and then perform split using "=" to get keys and values.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    UGh, Ill see what it does lol.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Could you reference me to what i need to do exactly. Im no visual basic nerd at all. I do php only, But Im creating this app, and this is the only part i need help on. How do i identify everything. How do i know where to put it all, Im quite confused.

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Ok. Once you press the Load Flight Button, The following Code goes into work;

    vb Code:
    1. 'Dim req As Net.WebRequest = Net.WebRequest.Create("http://simual.com/acars/bids.php?username=" + txtUsername.Text + "&password=" + txtPassword.Text)
    2.         'Dim resp As Net.WebResponse = req.GetResponse()
    3.         'Dim s As IO.Stream = resp.GetResponseStream()
    4.         'Dim sr As IO.StreamReader = New IO.StreamReader(s, System.Text.Encoding.ASCII)
    5.         'Dim doc As String = sr.ReadToEnd()

    On that PHP Page called Bids.php the code will select from the database where login is = login and password = password; From their, If the pilot has bidded on a flight, It will echo out the flight infomation in the exact format; "FlightID=UAL001;DEPICAO=KMCI;ARRICAO=KLAX;Route=WLDCAT1-ART-Loop4;Comments=Enjoy;" just as you said. From their is where all the visual basic coding will come to work. I need to be able to put the content after the '=' into textbox's, And im not quite sure on how to.

  7. #7
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    Your textboxes should be named EXACTLY like this:
    txtFlightID, txtDEPICAO, txtARRICAO, txtRoute, txtComments

    vb.net Code:
    1. ' For the sake of example - you don't need the following line
    2. Dim doc As String = "FlightID=UAL001;DEPICAO=KMCI;ARRICAO=KLAX;Route=WLDCAT1-ART-Loop4;Comments=Enjoy;"
    3.  
    4. ' Splitting doc into individual key/value pairs
    5. Dim tokens() As String = doc.Split(";"c)
    6.  
    7. For Each token As String In tokens
    8.     ' Splitting KeyValue into Key and Value
    9.     Dim KeyValue() As String = token.Split("="c)
    10.     ' You should name your textboxes EXACTLY as I said for this to work
    11.     ' Some error checking might be in order
    12.     DirectCast(Me.Controls("txt" & KeyValue(0)), TextBox).Text = KeyValue(1)
    13. Next

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    One slight problem, Can we accommodate for 3 Combo Boxes. DepAirport, ArrAirport, and Aircraft Type are all combo boxes. Can we put those in?

  9. #9
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    Yes, but the code will be different.
    You will need to populate your textboxes with possible values of airports and aircraft types and then, having found the value on your web page, to find the corresponded value in the relevant combobox item collection and select it.

    This code line won't work:
    DirectCast(Me.Controls("txt" & KeyValue(0)), TextBox).Text = KeyValue(1)

    You're going to manually check each Key and then check the correspondent combobox item collection, find the needed one and select it.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Ok ill do that. One more question. I have a text file with about 5000 lines that contain all the info about the airports. Here is an example of each line;

    KOJC:Olathe Johnson County Exec KS:+038.847603-094.737586:OJC:KZKC:67
    KOKC:Oklahoma City Will Rogers World OK:+035.393089-097.600733:OKC:KZFW:67

    Where it says "Olathe Johnson Country Exec KS" and "Oklahoma City Will Rogers World OK", How do i Add only those contents into a Combo Box. So basically, I only want the names of the airports added into the ComboBoxes. As you can see it is all seperated by : . Please let me know on how i can do this and I will leave yah alone lol. Thanks

  11. #11
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    Again, use split method and use ":" as a delimeter.
    The returned array will be:
    (0)KOJC
    (1)Olathe Johnson County Exec KS
    (2)+38.847603-094.737586
    (3)OJC
    (4)KZKC
    (5)67

    Guess what? You'll need the element with index 1 )))

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's



    I did exactly as you said. The Text Box Names are in this format;


    txtFlightID
    txtDepICAO
    txtArrICAO
    txtAircraft
    txtRoute
    txtComments

    And i get that error. Pic is http://i44.tinypic.com/2nlecux.jpg

  13. #13
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    if you look closely at my code you'll notice this little comment:

    ' Some error checking might be in order

    The last semicolon is causing troubles resulting the last token to be an empty string.


    Change the code like this:
    Code:
    Dim tokens() As String = doc.Split(";"c, StringSplitOptions.RemoveEmptyEntries)

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Ok, I replaced the code, But once I did, I got this error;



    Error 1 Overload resolution failed because no accessible 'Split' can be called with these arguments:
    'Public Function Split(separator() As String, options As System.StringSplitOptions) As String()': Value of type 'Char' cannot be converted to '1-dimensional array of String'.
    'Public Function Split(separator() As Char, options As System.StringSplitOptions) As String()': Value of type 'Char' cannot be converted to '1-dimensional array of Char'.
    'Public Function Split(separator() As Char, count As Integer) As String()': Value of type 'Char' cannot be converted to '1-dimensional array of Char'.
    'Public Function Split(ParamArray separator() As Char) As String()': 'System.StringSplitOptions' values cannot be converted to 'Char'. Use 'Microsoft.VisualBasic.ChrW' to interpret a numeric value as a Unicode character or first convert it to 'String' to produce a digit. I:\random\Acars_Source\Form1.vb 272 34 Acars

    http://i44.tinypic.com/2nuhzsg.jpg

  15. #15
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    Code:
    Dim tokens() As String = doc.Split(New Char() {";"c}, StringSplitOptions.RemoveEmptyEntries)

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Its still highlighting
    Code:
    DirectCast(Me.Controls("txt" & KeyValue(0)), TextBox).Text = KeyValue(1)
    in yellow. Not sure why. If you have teamviewer, I can let you connect to my pc to take a look at it.

  17. #17

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Changed that and still happens.


  19. #19
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    Check your textboxes names:
    Just copy and paste them from here:
    • txtFlightID
    • txtDepICAO
    • txtArrICAO
    • txtAircraft
    • txtRoute
    • txtComments


    I tried your code and everything works except for the possibility that you mistyped some textbox name. Try to match character case too. Re-check every name.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    79

    Re: Read Content From Page and Put into TextBox's

    Checked it all and its not working. Can you connect to my computer via teamviewer and check it out?

    All you do is download teamviewer from http://teamviewer.com and install it for personal use. It would mean a ton because i want to get this done. Thanks

  21. #21
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Read Content From Page and Put into TextBox's

    OK PM me your personal ID and pass

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