Results 1 to 5 of 5

Thread: Associate the Zodiac with Your Day Horoscope Extract from an Internet Page in VBA

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    77

    Associate the Zodiac with Your Day Horoscope Extract from an Internet Page in VBA

    Good morning to all my name is A.Maurizio
    And my question and this: Time ago I was able to create a program entirely in VBA
    Using an Excel sheet, where I was looking for the zodiac sign I wanted through a ComboBox, and then pressing a button I called my Horoscope.
    Everything using this Code:

    Code:
    Private Sub Cmd_AvviaOroscopo_Click()
    On Error Resume Next
    Range("F2").Value = "" & ListBox1.Text
      'vSegno = Target
        vSegno = Range("J2").Value & ""
          Range("F2").Value = "" & Oroscopo(vSegno)
    End Sub
    And then in the Module I wrote this:
    Code:
    Public Function Oroscopo(ByVal vSegno As Variant) As String
      Dim sSource As String
      Dim aSegni As Variant
      Dim j As Integer
      Dim sSegno As String
      Dim nSegno As Integer
      Dim sOroscopo As String
      Dim Http1 As Object
      Dim sUrl As String
      Dim nAtH2 As Long
      Dim nAtP As Long
      Dim nAtCP As Long
      On Error GoTo Oroscopo_Error
     
      aSegni = Split("Ariete Toro Gemelli Cancro Leone Vergine Bilancia Scorpione Sagittario Capricorno Acquario Pesci")
      If IsNumeric(vSegno) Then
        nSegno = vSegno
        sSegno = aSegni(nSegno - 1)
      Else
        sSegno = vSegno
        For j = 0 To 11
          If aSegni(j) = sSegno Then
            nSegno = j + 1
          End If
        Next
      End If
      Set Http1 = CreateObject("MSXML2.XMLHTTP")
      
      sUrl = "http://oroscopo.donnad.it/oroscopo/settimanale/segno/s/" & nSegno
      Http1.Open "GET", sUrl, False
      Http1.Send
      sSource = Http1.ResponseText
      Set Http1 = Nothing
      
      nAtH2 = InStr(1, sSource, "</h2>", vbTextCompare)
      nAtP = InStr(nAtH2, sSource, "<p>", vbTextCompare) + 3
      nAtCP = InStr(nAtP, sSource, "</p>", vbTextCompare) - nAtP
      sOroscopo = VBA.Mid(sSource, nAtP, nAtCP)
      sOroscopo = sSegno & vbCrLf & VBA.Trim(Replace(Replace(Replace(sOroscopo, vbLf, ""), vbCr, ""), vbTab, ""))
      
    Oroscopo_Error:
      If Err.Number <> 0 Then
        Set Http1 = Nothing
        sOroscopo = "Non disponibile!"
      End If
      Oroscopo = sOroscopo
    End Function
    Now All That Worked Well Up To Some Years ago; Then nothing happens to me since then.
    I also tried to change the Address of the Connected Internet Site, thinking that the page with Time was Expired; But nothing to do.
    Here is my question and this: There would not be another way more to view it all without adopting my Criterion.
    Thank you for all the help you want to give me, Sincerely greetings from A.Maurizio

    (P.S) Anyway For More Information I Insert My Test Project
    Attached Files Attached Files
    Last edited by A.Maurizio; May 12th, 2017 at 10:54 AM.

  2. #2
    gibra
    Guest

    Re: Associate the Zodiac with Your Day Horoscope Extract from an Internet Page in VBA

    1) vSegno hasn't declared, so add declaration

    Code:
    Dim vSegno As String
    2) the url you use is wrong, also the sintax of url is wrong. Because vSegno is a variable while you use as a string. Should be correct :
    Code:
      'sUrl = "http://www.oggi.it/oroscopo/oroscopo-di-oggi/vSegno/s/" & nSegno
      sUrl = "http://www.oggi.it/oroscopo/oroscopo-di-oggi/" & vSegno & "-oggi.shtml"
    3) in the loop For j = 0 to 11 add a Exit For after the value is found:
    Code:
      If IsNumeric(vSegno) Then
        nSegno = vSegno
        sSegno = aSegni(nSegno - 1)
      Else
        sSegno = vSegno
        For j = 0 To 11
          If aSegni(j) = sSegno Then
            nSegno = j + 1
            Exit For ' <---------------------------------
          End If
        Next
      End If

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    77

    Re: Associate the Zodiac with Your Day Horoscope Extract from an Internet Page in VBA

    Hi gibra You Are Fantastic, Now That Works Well; But there is only one problem that only you can solve.
    And the problem is this: If you look at this

    you see that while working well in the discussion, there are Codes that have nothing to do with The Horoscope itself.
    Here's how to overcome this.

    Plus if you're not in weight, you might get me the date (Zodiac Name) the dates that came up that month

    Crazie. Greetings from A.Maurizio

    (p.S) Again see Attachment
    Attached Files Attached Files

  4. #4
    gibra
    Guest

    Re: Associate the Zodiac with Your Day Horoscope Extract from an Internet Page in VBA

    Character entity references in HTML 4
    http://www.w3.org/TR/html4/sgml/entities.html

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2015
    Posts
    77

    Re: Associate the Zodiac with Your Day Horoscope Extract from an Internet Page in VBA

    I thank you gibra but first I still understand something with this link I absolutely do not understand anything.
    But that's fine.
    Thanks anyway, Sincere greetings from A.Maurizio

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