|
-
Jun 7th, 2006, 05:47 PM
#1
Thread Starter
New Member
[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:
Dim frmB As New frmBrowser
frmB.StartingAddress = "http://api.cgeagles.com/cgsx/buy.php"
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:
On Error Resume Next
Me.Caption = brwWebBrowser.LocationName
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
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.
-
Jun 7th, 2006, 06:05 PM
#2
Re: Substr Help

you sure this is VB6?
SubStr is in .Net - i think you want this forum
-
Jun 7th, 2006, 06:13 PM
#3
Thread Starter
New Member
Re: Substr Help
 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
-
Jun 7th, 2006, 06:24 PM
#4
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:
Const sMatch As String = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol="
Dim frmB As frmBrowser
Me.Caption = brwWebBrowser.LocationName
If LCase$(Left$(brwWebBrowser.LocationURL, Len(sMatch))) = sMatch Then
Set frmB = New frmBrowser
frmB.StartingAddress = sMatch & Mid$(brwWebBrowser.LocationURL, Len(sMatch) + 1)
frmB.Show
Set frmB = Nothing
End If
What event have you got your code in?
Last edited by bushmobile; Jun 7th, 2006 at 06:28 PM.
-
Jun 7th, 2006, 06:26 PM
#5
Thread Starter
New Member
Re: Mid Help
 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:
Const sMatch As String = "http://api.cgeagles.com/cgsx/stock.php?buy=true&symbol="
Dim frmB As frmBrowser
Me.Caption = brwWebBrowser.LocationName
If LCase$(Left$(brwWebBrowser.LocationURL, Len(sMatch))) = sMatch Then
Set frmB = New frmBrowser
frmB.StartingAddress = Mid$(brwWebBrowser.LocationURL, Len(sMatch) + 1)
frmB.Show
Set frmB = Nothing
End If
What event have you got your code in?
Here's the entire event:
VB Code:
Private Sub brwWebBrowser_DownloadComplete()
On Error Resume Next
Me.Caption = brwWebBrowser.LocationName
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
End Sub
-
Jun 7th, 2006, 06:28 PM
#6
Re: Mid Help
there was a slight error with my code - i've edited it (post #4)
-
Jun 7th, 2006, 06:36 PM
#7
Thread Starter
New Member
Re: Mid Help
Thank you so much!
It works!
- k3p7
-
Jun 7th, 2006, 06:39 PM
#8
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.
-
Jun 7th, 2006, 06:43 PM
#9
New Member
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:
l_int_stringposition = INSTR(1, http_address, "=")
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:
l_int_stringposition = INSTR(1, http_address, "=")
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|