Results 1 to 7 of 7

Thread: Stupid string problem I CANNOT figure out!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    3

    Stupid string problem I CANNOT figure out!

    Here's my program so far.

    Code:
    Private Sub cmdGet_Data_Click()
        Dim Inet_Data As String
        Dim Digit As String
        Dim str As String
        
        Dim Index As Integer
        Dim x As Integer
        Dim y As Integer
        Dim Length As Integer
        
        Inet_Data = Inet1.OpenURL("http://finance.yahoo.com/q/ae?s=" & tbTicker.Text)
        
        'Find the price
        x = InStr(Inet_Data, "Script")
           
        tbOutput.Text = Mid(Inet_Data, x, 6)
        
    End Sub
    I'm just trying to pull data off yahoo's stock pages. I know Inet_Data has data, and I know it contains "Script". If the line
    Code:
    x = InStr(Inet_Data, "Script")
    is run as is, it doesn't return anything to the x variable. if I change it so it's not case sensitive, ie.
    Code:
    x = InStr(Inet_Data, "Script",1)
    I get a "type mismatch" error. If I try to put in a starting position, ie.
    Code:
    x = InStr(0,Inet_Data, "Script")
    I get an "invalid procedure call or argument" error. So basically, instr doesn't work for me at all.

    Please help!

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    There's nothing wrong with the way you're using InStr, except that if you specify a starting position it must be greater than zero.

    If Inet_Data does contain 'script', then this line:
    tbOutput.Text = Mid(Inet_Data, x, 6)
    will only return the word 'script'.

    ie. If Inet_Data = "abcdefghijkScriptlmnopqrst", then
    InStr(Inet_Data, "Script") will equal 12, therefore
    Mid$(Inet_Data, 12, 6) will equal 'Script"

    Are you 100% sure there is data in Inet_Data and that it contains the text 'Script'? I can't really see anything wrong other than what I've mentioned.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Just a thought.

    In

    'Find the price
    x = InStr(Inet_Data, "Script")

    tbOutput.Text = Mid(Inet_Data, x, 6)

    What are you trying to do? Unless this is an error tracing section to enable you to find out what is in the string at x (which won't work if the letters "Script" are not there) tbOutput.Text can never be anything else than "Script" or nothing.

    It looks as if you are expecting "Script" to be a price!!!!

    Is it possible that you mean the price is recorded in Script notation? (If that is the correct word).
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    3
    Yeah, it was going to be price info eventually, but then I was running into problems, so I simplified it for now to figure things out.

    I seem to have the code working for now, I reverted to an older save of the program, and took note of pnish's note that starting position must be greater than zero. Suddenly it worked with no other changes. Weird. Must have been some weird windows bug.

    Thanks for the help though

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by Kingstudly
    Yeah, it was going to be price info eventually, but then I was running into problems, so I simplified it for now to figure things out.

    I seem to have the code working for now, I reverted to an older save of the program, and took note of pnish's note that starting position must be greater than zero. Suddenly it worked with no other changes. Weird. Must have been some weird windows bug.

    Thanks for the help though
    Don't blame it on Windows. It was clearly your own fault .
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    But blaming it on windows makes everything so much easier!

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    3
    Yeah, I love it when I exit visual basic and the code doesn't work, then when I start it again later it does work...

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