Getting numbers from Random.org

Arrow43050

New Member
Joined
Jun 11, 2019
Messages
4
I am trying to use random.org to get a few random numbers (I am not super advanced in writing in VBA so I am just going to get them one at a time). I saw sample code that was written in a reply to a post in 2012 on this site. I tried using the code but I got an error Run-time error '429' ActiveX component can't create object. I admittedly know nothing about objects but was just copying the code that I saw. Can someone please let me know how I can get this to work? I have not finished the code but was just testing that I'd be able to send out the request and get a number back and it failed. I can tell you that if I copy and paste the URL I have below, it does give me one random number between 1 and 6 on random.org's webpage. So I know that isn't the problem at least. What I have so far is:

Rich (BB code):
Sub BattingRoll()


    Dim dsXMLObj As Object
    Dim dsURL As String
    Dim dsRespText
    Dim I As Long
    Dim dsBattingCol As Long
    Dim dsBattingTot As Long


    dsURL = "http://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=plain"
    Set dsXMLObj = CreateObject("MSXML2.ServerXMLHTTP.4.0")
    With dsXMLObj
        .Open "GET", dsURL, False
        .send
        
        dsRespText = .responseText
        dsBattingCol = Val(Split(dsRespText, Chr(10)))
    End With
    
End Sub

The original code posted by the person who replied in 2012 was as follows. I'm not sure if objects or anything way beyond my knowledge level has changed or if I just messed something up.

Rich (BB code):
Option Explicit
Function GetRndNos(NUM As Long, MIN As Long, MAX As Long) As Variant
Dim objXMLHTTP As Object
Dim strURL As String
Dim strResp
Dim I As Long
    strURL = "http://www.random.org/integers/"
    strURL = strURL & "?num=" & NUM & "&min=" & MIN & "&max=" & MAX & "&col=1&base=10&format=plain&rnd=plain"
    Debug.Print strURL
    Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.4.0")
    
    With objXMLHTTP
        .Open "GET", strURL, False
        .send
        
        strResp = .responseText
        
        GetRndNos = Split(strResp, Chr(10))
        
    End With
    
    Set objXMLHTTP = Nothing
End Function

Sub test()
    Range("A1:A100").Value = Application.Transpose(GetRndNos(100, 1, 100))
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You want this:
Code:
Sub BattingRoll()


    Dim dsXMLObj As Object
    Dim dsURL As String
    Dim dsRespText
    Dim I As Long
    Dim dsBattingCol As Long
    Dim dsBattingTot As Long


    dsURL = "https://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=plain"
    Set dsXMLObj = CreateObject("MSXML2.XMLHTTP")
    With dsXMLObj
        .Open "GET", dsURL, False
        .send
        
        dsRespText = .responseText
        dsBattingCol = Val(dsRespText)
    End With
    
End Sub
 
Upvote 0
Thank you for your help. It was able to get past that, but when it gets to ".send" I get another error, a Run-time error that says "Access is denied." Any thoughts? I really have no idea where to go. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top