Smartgambler
Pro-Punter

Go Back   OZmium Sports Betting and Horse Racing Forums > Public Forums > General Topics
User Name
Password
Register FAQ Search Today's Posts Mark all topics as read

To advertise on these
forums, e-mail us.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 24th July 2011, 01:46 PM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,456
Default Excel Help

I need some help with web query, i am importing pages from Cyberhorse but having issues with formatting, here is a page from today.

http://formguide.cyberhorse.com.au/...=Coffs&raceno=5

When i import the page the formats for some of the Distance,track and going get all messed up, seams if the number of starts is over 10 it changes the format, i have tried a few things with no success so am after some help from more experienced with excel.
Reply With Quote
  #2  
Old 24th July 2011, 06:28 PM
4legs 4legs is offline
Member
 
Join Date: Mar 2009
Posts: 96
Default

Shaun, if you email me your web query I can have have a quick look at it and see if I can spot any problems .. Fred
Reply With Quote
  #3  
Old 24th July 2011, 07:30 PM
The Elk The Elk is offline
Member
 
Join Date: Sep 2008
Posts: 28
Default

Shaun,
Is this the info you are trying to extract? (stats from 1st runner Blinkin Easy)
Quote:
Distance: 13:2-1-3
Track: 3:0-0-0
Good: 31:5-5-3
Dead: 9:3-0-2
...etc
I'm not quite sure what you mean by "it gets all messed up over 10 starts"?

My excel web queries are a bit rusty but vb2010 is pretty close:

1. extract Dis = "13:2-1-3" using Instr()
2. Career()=Split(Dis,":") giving Career(0)="13" & Career(1)="2-1-3"
3. Place()=split(Career(1),"-") so Place(0)="2" Place(1)="1" Place(2)="3"


Is this what you are trying to do and having troubles when runs at distance > 9 , Good=31...etc?

Probably need a little more info to give any further help

cheers
Reply With Quote
  #4  
Old 24th July 2011, 08:00 PM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,456
Default

The extraction is not the problem the problem is it wants to sometimes format the number as a date, even if i have the sheet formatted as text when i import the new sheet it just goes back.
Reply With Quote
  #5  
Old 24th July 2011, 11:14 PM
The Elk The Elk is offline
Member
 
Join Date: Sep 2008
Posts: 28
Default

Aaaaaahhhh, now I understand - can you change the dashes to dots/periods or anything other than dashes so that excel does not recognise it as a date

cheers
Reply With Quote
  #6  
Old 5th August 2011, 12:36 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,456
Default

I have found a solution to this problem thanks to a user on the Gruss forum, he uses some macros to change 10:1-2-0 to 10::1-2-0 the double :: confuses excel and stops it changing to a date format.

I will post the macro but i don't totally understand it but it works, there are 3 parts to the macro.

The part in red in macro 3 is what he has added to my macro.


Forgot to mention what ever he has done has changed the import time from 30 seconds a race to 5 seconds.

Code:
Public Function ExecuteWebRequest(url As String) As String Dim oXHTTP As Object Set oXHTTP = CreateObject("MSXML2.XMLHTTP") oXHTTP.Open "GET", url, False oXHTTP.send ExecuteWebRequest = oXHTTP.responseText Set oXHTTP = Nothing End Function


Code:
Public Function outputtext(text As String) Dim MyFile As String, fnum As String MyFile = ThisWorkbook.Path & "\temp.txt" fnum = FreeFile() Open MyFile For Output As fnum Print #fnum, text Close #fnum End Function


Code:
Sub form() Sheets("Form").Select Sheets("Form").Range("B1:J1000").Select Selection.ClearContents Columns("B:J").Select Selection.NumberFormat = "@" formhtml = ExecuteWebRequest(ThisWorkbook.Sheets("Data").Range("A1").Value) formhtml = Replace(formhtml, ":", "::") outputtext (formhtml) Set temp_qt = ThisWorkbook.Sheets("Form").QueryTables.Add(Connection:= _ "URL;" & ThisWorkbook.Path & "\temp.txt" _ , Destination:=ThisWorkbook.Sheets("Form").Range("B1")) With temp_qt .Name = "test" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlOverwriteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlAllTables .WebFormatting = xlWebFormattingNone .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = True .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With Set temp_qt = Nothing Kill ThisWorkbook.Path & "\temp.txt" If ThisWorkbook.Connections.Count > 0 Then ThisWorkbook.Connections.Item(ThisWorkbook.Connect ions.Count).Delete Columns("B:J").Select Selection.Copy Application.DisplayAlerts = False Sheets("Data").Select Range("AA1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("AA:AA").Select Application.CutCopyMode = False Selection.TextToColumns Destination:=Range("AA1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _ :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _ Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _ ), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1)), _ TrailingMinusNumbers:=True Columns("AC:AC").Select Selection.TextToColumns Destination:=Range("AC1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _ Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _ :=Array(1, 5), TrailingMinusNumbers:=True Application.DisplayAlerts = True Range("A1").Select End Sub

Last edited by Shaun : 5th August 2011 at 12:41 AM.
Reply With Quote
  #7  
Old 5th August 2011, 12:47 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,456
Default

Looking at the code it seams he loads the page in to a temp file first then makes the changes needed then imports to excel, this would results in the speed increase as it does not have to wait for excel to import the page, i have used a similar idea in another program before.
Reply With Quote
  #8  
Old 5th August 2011, 08:22 AM
moeee moeee is offline
Suspended
 
Join Date: Jan 1970
Location: Melbourne
Posts: 5,359
Default

Quote:
Originally Posted by Shaun
I have found a solution to this problem thanks to a user on the Gruss forum, he uses some macros to change 10:1-2-0 to 10::1-2-0 the double :: confuses excel and stops it changing to a date format.



And perhaps a little bit of acknowledgement to Member "The Elk" , who suggested you do just that , wouldn't go astray
Reply With Quote
  #9  
Old 5th August 2011, 09:53 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,456
Default

Although at times i may not acknowledge help i get from others it is always appreciated, this is one of the main reasons i provide as much help as i can with excel sheets and other things.

I visit many forums on my travels and in the past this place has copped some flak over editing of urls and restriction on things we can discuss, but things have changed around here for the better and some may disagree with some of the topics that are posted and other may just brush it off as rubbish but this is still the most informative and useful forum around.
Reply With Quote
  #10  
Old 5th August 2011, 10:32 AM
The Elk The Elk is offline
Member
 
Join Date: Sep 2008
Posts: 28
Thumbs up

Thanks Moeee for that (certainly wasn't expected - but appreciated) and thanks also to Shaun for posting a workable solution to the problem

cheers
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump



All times are GMT +10. The time now is 08:44 PM.


Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2008 OZmium Pty. Ltd. All rights reserved . ACN 091184655