[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 918
  • Last Modified:

Inet Control VB6.0 Please help!

hello experts

i want to use inet control to take just 1 number from " http://www.counterdata.com/details.php?page=98395 " see on "Total Hits      2 " <-- i want only to took the number (2)  and then showing back to my application see below ..

here is my source
=================

ption Explicit

Private Const Ratio  As Double = 39.95

Public Function FormatDollar(arg As Double) As Double
    FormatDollar = Ratio * arg
End Function


Private Function GetIP()
GetIP = Split(Split(Inet.OpenURL("http://www.counterdata.com/details.php?page=98395"), ' <-- HERE I DONT KNOW WHAT TO PUT TO TAKE EXATCLY THE NUMBER IN THIS SIT
End Function
Private Sub Form_Load()
Pending.Text = GetIP
If Pending.Text = "1" Then
Pending.Text = "$39.95"
End If
If Pending.Text = "2" Then
Pending.Text = FormatDollar(2)
End If
........ etc ..
==============================
please try to help me .. thanks a lot experts!
0
KingSencat
Asked:
KingSencat
  • 3
1 Solution
 
blandyukCommented:
Hi KingSencat,

Not sure why your doing it that way! I'd simply request the HTML data and search for a unique reference point in the text like "Total Hits" and then simply get the value in between the "<td>" and "</td>" tag.

---------
Dim sData As String, sValue
Dim iPos As Long, iStart As Long, iEnd As Long, iValue As Long

sData = Inet1.OpenURL("http://www.counterdata.com/details.php?page=98395")
iPos = InStr(1, sData, "Total Hits")
If iPos > 0 Then
  iStart = InStr(iPos, sData, "<td>")
  iEnd = InStr(iStart, sData, "</td>")
  sValue = Mid(sData, iStart + 4, (iEnd - iStart) - 4)
End If

If IsNumeric(sValue) Then iValue = CLng(sValue) Else iValue  = 0
---------
0
 
KingSencatAuthor Commented:




This is all the source ..  and is not working :( . can you modify it and post the correct one please? thanks



================
Option Explicit
Private Const Ratio  As Double = 39.95

Dim sData As String, sValue
Dim iPos As Long, iStart As Long, iEnd As Long, iValue As Long


Public Function FormatDollar(arg As Double) As Double
    FormatDollar = Ratio * arg
End Function


Private Function GetIP()
sData = Inet.OpenURL("http://www.counterdata.com/details.php?page=98395")
iPos = InStr(1, sData, "Total Hits")
If iPos > 0 Then
  iStart = InStr(iPos, sData, "<td>")
  iEnd = InStr(iStart, sData, "</td>")
  sValue = Mid(sData, iStart + 4, (iEnd - iStart) - 4)
End If
If IsNumeric(sValue) Then iValue = CLng(sValue) Else iValue = 0
End Function
Private Sub Form_Load()
Pending.Text = GetIP
If Pending.Text = "1" Then
Pending.Text = "$39.95"
End If
If Pending.Text = "2" Then
Pending.Text = FormatDollar(2)
End If
If Pending.Text = "3" Then
Pending.Text = FormatDollar(3)
End If
If Pending.Text = "4" Then
Pending.Text = FormatDollar(4)
End If
If Pending.Text = "5" Then
Pending.Text = FormatDollar(5)
End If
If Pending.Text = "6" Then
Pending.Text = FormatDollar(6)
End If
If Pending.Text = "7" Then
Pending.Text = FormatDollar(7)
End If
If Pending.Text = "8" Then
Pending.Text = FormatDollar(8)
End If
If Pending.Text = "9" Then
Pending.Text = FormatDollar(9)
End If
If Pending.Text = "10" Then
Pending.Text = FormatDollar(11)
End If
If Pending.Text = "12" Then
Pending.Text = FormatDollar(12)
End If
If Pending.Text = "13" Then
Pending.Text = FormatDollar(13)
End If
If Pending.Text = "14" Then
Pending.Text = FormatDollar(14)
End If
If Pending.Text = "15" Then
Pending.Text = FormatDollar(15)
End If
If Pending.Text = "16" Then
Pending.Text = FormatDollar(16)
End If
If Pending.Text = "17" Then
Pending.Text = FormatDollar(17)
End If
If Pending.Text = "18" Then
Pending.Text = FormatDollar(18)
End If
If Pending.Text = "19" Then
Pending.Text = FormatDollar(19)
End If
If Pending.Text = "20" Then
Pending.Text = FormatDollar(20)
End If
If Pending.Text = "21" Then
Pending.Text = FormatDollar(21)
End If
If Pending.Text = "22" Then
Pending.Text = FormatDollar(22)
End If
If Pending.Text = "23" Then
Pending.Text = FormatDollar(23)
End If
If Pending.Text = "24" Then
Pending.Text = FormatDollar(24)
End If
If Pending.Text = "25" Then
Pending.Text = FormatDollar(25)
End If
If Pending.Text = "26" Then
Pending.Text = FormatDollar(26)
End If
If Pending.Text = "27" Then
Pending.Text = FormatDollar(27)
End If
If Pending.Text = "28" Then
Pending.Text = FormatDollar(28)
End If
If Pending.Text = "29" Then
Pending.Text = FormatDollar(29)
End If
If Pending.Text = "30" Then
Pending.Text = FormatDollar(30)
End If
If Pending.Text = "31" Then
Pending.Text = FormatDollar(31)
End If
If Pending.Text = "32" Then
Pending.Text = FormatDollar(32)
End If
If Pending.Text = "33" Then
Pending.Text = FormatDollar(33)
End If
If Pending.Text = "34" Then
Pending.Text = FormatDollar(34)
End If
If Pending.Text = "35" Then
Pending.Text = FormatDollar(35)
End If
If Pending.Text = "36" Then
Pending.Text = FormatDollar(36)
End If
If Pending.Text = "37" Then
Pending.Text = FormatDollar(37)
End If
If Pending.Text = "38" Then
Pending.Text = FormatDollar(38)
End If
If Pending.Text = "39" Then
Pending.Text = FormatDollar(39)
End If
If Pending.Text = "40" Then
Pending.Text = FormatDollar(40)
End If
If Pending.Text = "41" Then
Pending.Text = FormatDollar(41)
End If
If Pending.Text = "42" Then
Pending.Text = FormatDollar(42)
End If
If Pending.Text = "43" Then
Pending.Text = FormatDollar(43)
End If
If Pending.Text = "44" Then
Pending.Text = FormatDollar(44)
End If
If Pending.Text = "45" Then
Pending.Text = FormatDollar(45)
End If
If Pending.Text = "46" Then
Pending.Text = FormatDollar(46)
End If
If Pending.Text = "47" Then
Pending.Text = FormatDollar(47)
End If
If Pending.Text = "48" Then
Pending.Text = FormatDollar(48)
End If
If Pending.Text = "49" Then
Pending.Text = FormatDollar(49)
End If
If Pending.Text = "50" Then
Pending.Text = FormatDollar(50)


End If
End Sub

'\\Code//
Private Sub Text1_Change()

End Sub
0
 
blandyukCommented:
Go easy on the If statements, no need for all those:

---------
Option Explicit
Private Const Ratio As Currency = 39.95

Public Function FormatDollar(ByRef arg As Long) As Currency
    FormatDollar = Ratio * arg
End Function

Private Function GetIP()
    Dim sData As String, sValue
    Dim iPos As Long, iStart As Long, iEnd As Long
   
    sData = Inet.OpenURL("http://www.counterdata.com/details.php?page=98395")
    iPos = InStr(1, sData, "Total Hits")
    If iPos > 0 Then
      iStart = InStr(iPos, sData, "<td>")
      iEnd = InStr(iStart, sData, "</td>")
      sValue = Mid(sData, iStart + 4, (iEnd - iStart) - 4)
    End If
    If IsNumeric(sValue) Then GetIP = CLng(sValue) Else GetIP = 0
End Function

Private Sub Form_Load()
    Dim iValue As Long
   
    iValue = GetIP
   
    Select Case iValue
    Case 1
      Pending.Text = "$39.95"
    Case 2 To 50
      Pending.Text = CStr(FormatDollar(iValue))
    End Select
End Sub
--------------

You may want to check the output of "sData" to make sure it's getting all the HTML code. If it isn't, then it wont get you value.

Hint: Never declare variables for the whole form if they are only used in one procedure. Can get conflicts in other procedures / functions.
0
 
blandyukCommented:
Thanks :) Did you manage to get it working? Any other issues just let me know.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now