Hi.
I use a function to look up a currency value from a webpage to do some realtime calculation. It needs to be realtime, and this restricts possible sources online.
I have a function that works alright, but it has some flaws I would like to address.
The class changes names depending on if the last change is a positive or negative.
The code I use today is at the bottom.
For "no change" it has the name "ftqbb ftqw2 pid-59-bid" This is the one I use.
for positive change it has the name "ftqbb ftqw2 pid-59-bid greenBg" No result for me.
for negative change it has the name "ftqbb ftqw2 pid-59-bid redBg" no result for me.
Of these three classes, only ONE exists, and I would like my code to choose the one that actually works.. How may I build up an IF or Case statement here?
I use a function to look up a currency value from a webpage to do some realtime calculation. It needs to be realtime, and this restricts possible sources online.
I have a function that works alright, but it has some flaws I would like to address.
The class changes names depending on if the last change is a positive or negative.
The code I use today is at the bottom.
For "no change" it has the name "ftqbb ftqw2 pid-59-bid" This is the one I use.
for positive change it has the name "ftqbb ftqw2 pid-59-bid greenBg" No result for me.
for negative change it has the name "ftqbb ftqw2 pid-59-bid redBg" no result for me.
Of these three classes, only ONE exists, and I would like my code to choose the one that actually works.. How may I build up an IF or Case statement here?
Code:
Private Sub cmdValuta_Click()
On Error GoTo Err_cmdValuta
Me.txtLys = "X"
DoCmd.Hourglass True
Dim IE As Object
'Lag InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
IE.Navigate "http://fxrates.forexpros.com/index.php?pairs_ids=59"
Do While IE.Busy
Loop
'Time for code to loop to "find" the class.
Dim dd As String
Dim oNow As Date
oNow = DateAdd("s", 5, Now())
Do
DoEvents
Loop Until Now() > oNow Or Not IE.Document.getElementsByClassName("ftqbb ftqw2 pid-59-bid")(0) Is Nothing
dd = IE.Document.getElementsByClassName("ftqbb ftqw2 pid-59-bid")(0).innerText
Me.txtValuta.Value = dd
Me.txtLys.Value = "V"
IE.Quit
Set IE = Nothing
DoCmd.Hourglass False
Exit Sub
Err_cmdValuta: MsgBox Err & " " & Error$
Exit Sub
End Sub