Results 1 to 9 of 9

Thread: [RESOLVED] Mid Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Resolved [RESOLVED] Mid Help

    Hello,

    I am trying to make a program where the users of my site can buy shares of different companies through VB6.

    I wrote a program in PHP that will be viewed through the Web Browser in VB 6 (the web browser that comes in the wizard).

    Here's my problem:
    The stock url is:
    http://api.cgeagles.com/cgsx/stock.php?symbol=<stock symbol here>

    I need to open a new window with this url in it:
    http://api.cgeagles.com/cgsx/buy.php?symbol=<stock symbol here>

    The code to open a new browser window is:

    VB Code:
    1. Dim frmB As New frmBrowser
    2. frmB.StartingAddress = "http://api.cgeagles.com/cgsx/buy.php"
    3. frmB.Show

    First I need a way to check if the page is:
    http://api.cgeagles.com/cgsx/stock.p...ue&symbol=XXXX

    Second, I need to seperate the XXXX from the URL and add it to the new browser window opening code

    Here's what I've tried:

    VB Code:
    1. On Error Resume Next
    2.     Me.Caption = brwWebBrowser.LocationName
    3.     Dim s As Long
    4.     Dim ss As Long
    5.     Dim sss As Long
    6.     s = brwWebBrowser.LocationURL
    7.     sss = Mid(s, 56, 60)
    8.     ss = Mid(s, 0, 55)
    9.     If ss = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol=" Then
    10.     Dim frmB As New frmBrowser
    11.     frmB.StartingAddress = "http://api.cgeagles.com/cgsx/buy.php?symbol=" + sss
    12.     frmB.Show
    13.     End If

    But, when I run it, it just opens up thousands of windows pointing to buy.php?symbol=
    (it still lacks a symbol)

    Can someone tell me what I'm doing wrong??

    Thanks,
    - k3p7
    Last edited by k3p7; Jun 7th, 2006 at 06:15 PM.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Substr Help



    you sure this is VB6?

    SubStr is in .Net - i think you want this forum

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: Substr Help

    Quote Originally Posted by bushmobile


    you sure this is VB6?

    SubStr is in .Net - i think you want this forum
    Sorry,

    Someone told me to use substr, but I learned to use mid... it still doesn't work though

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Mid Help

    ok, first get rid of the On Error Resume Next - it's not really considered v. good programming practice to use it unless you really need to and it makes debugging nigh on impossible. Try this:
    VB Code:
    1. Const sMatch As String = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol="
    2.     Dim frmB As frmBrowser
    3.  
    4.     Me.Caption = brwWebBrowser.LocationName
    5.     If LCase$(Left$(brwWebBrowser.LocationURL, Len(sMatch))) = sMatch Then
    6.         Set frmB = New frmBrowser
    7.         frmB.StartingAddress = sMatch & Mid$(brwWebBrowser.LocationURL, Len(sMatch) + 1)
    8.         frmB.Show
    9.         Set frmB = Nothing
    10.     End If
    What event have you got your code in?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: Mid Help

    Quote Originally Posted by bushmobile
    ok, first get rid of the On Error Resume Next - it's not really considered v. good programming practice to use it unless you really need to and it makes debuggin nigh on impossible. Try this:
    VB Code:
    1. Const sMatch As String = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol="
    2.     Dim frmB As frmBrowser
    3.  
    4.     Me.Caption = brwWebBrowser.LocationName
    5.     If LCase$(Left$(brwWebBrowser.LocationURL, Len(sMatch))) = sMatch Then
    6.         Set frmB = New frmBrowser
    7.         frmB.StartingAddress = Mid$(brwWebBrowser.LocationURL, Len(sMatch) + 1)
    8.         frmB.Show
    9.         Set frmB = Nothing
    10.     End If
    What event have you got your code in?
    Here's the entire event:

    VB Code:
    1. Private Sub brwWebBrowser_DownloadComplete()
    2.     On Error Resume Next
    3.     Me.Caption = brwWebBrowser.LocationName
    4.     Dim s As Long
    5.     Dim ss As Long
    6.     Dim sss As Long
    7.     s = brwWebBrowser.LocationURL
    8.     sss = Mid(s, 56, 60)
    9.     ss = Mid(s, 0, 55)
    10.     If ss = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol=" Then
    11.     Dim frmB As New frmBrowser
    12.     frmB.StartingAddress = "http://api.cgeagles.com/cgsx/buy.php?symbol=" + sss
    13.     frmB.Show
    14.     End If
    15. End Sub

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Mid Help

    there was a slight error with my code - i've edited it (post #4)

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: Mid Help

    Thank you so much!

    It works!

    - k3p7

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Mid Help

    no probs

    you can now mark this thread resolved using the thread tools above your first post - that'll let everyone know you've got your answer.

  9. #9
    New Member
    Join Date
    May 2006
    Posts
    7

    Re: Mid Help

    Dim s As Long
    Dim ss As Long
    Dim sss As Long
    s = brwWebBrowser.LocationURL
    sss = Mid(s, 56, 60)
    ss = Mid(s, 0, 55)
    If ss = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol=" Then
    Dim frmB As New frmBrowser
    frmB.StartingAddress = "http://api.cgeagles.com/cgsx/buy.php?symbol=" + sss
    frmB.Show
    End If
    Personally, I would replace the 'if ss = "http..." line with an INSTR() function. This is fast and effective. That would take care of part one.

    For part two: I would use another INSTR() search for the '=', INSRT will return the location then you can use a MID() to capture the stock symbol.

    VB Code:
    1. l_int_stringposition = INSTR(1, http_address, "=")
    2. l_str_Stocksymbol = Mid(http_address, l_int_stringposit + 1, 4)

    Where the 'l_int_stringposition is the location of the '=' sign and l_str_strocksymbol stores your symbol.

    Another way to have a more dynamic query string is to include the LEN() function like:

    VB Code:
    1. l_int_stringposition = INSTR(1, http_address, "=")
    2. l_str_Stocksymbol = Mid(http_address, l_int_stringposit + 1, (LEN(Http_address) - (l_int_stringpostion + 1)))

    This way you could capture 2, 3, 4 or more charaters stock symbols, like the 5 digit Mutal fund codes, all with the same code.

    I noted that in your code you are storing the string '=XXXX' instead of 'XXXX' as desired. The reason is in your mid statement 56 to 60 is 5 steps, not 4 like your symbol.
    I dont know what you are doing with the variable after you try to capture it, so I can only assume you are keeping it as a string.

    I don't honestly see how the code after; 'if ss = ' exectues though;

    DOES NOT Equal

    That is way you should use the INSTR() function mentioned earlier.

    Hope it helps.

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