dim agent as string

I can not find the solution to make Random agents for my 5 webbrowsers, this code work but if i refresh the htmlviewr it not comes as Random and still display same useragent.
So i want that all agents change and turn every refresh of Htmlviewer.

  if PopupMenu1.Text = "Firefox Linux" Then
    dim agent as string
       
agent = "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101  Firefox/28.0"
agent = "Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0"
agent = "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0"
agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"
agent = "Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36"
agent = "Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"
agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
agent = "Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52"
agent = "Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00"
agent = Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031026 Firebird/0.7
agent = Windows; U; Windows NT 6.1; x64; fr; rv:1.9.2.13) Gecko/20101203 Firebird/3.6.13

HTMLViewer1.UserAgent = agent
HTMLViewer2.UserAgent = agent
HTMLViewer3.UserAgent = agent
HTMLViewer4.UserAgent = agent
HTMLViewer5.UserAgent = agent 
  End if

And What if i want 300 useragents they rotate and change every refresh Htmlviewer?
Thanks for any help

Not sure how I can say what I see without offending, but did you read all the intro docs?

Check this page: http://documentation.xojo.com/

Sure I read, there is many Ranom examples BUT NOT for useragents only for Integers not Strings :frowning:
So i dont know

Have you read about Arrays ?

Put your strings in an Array. Generate a random index and get your random string. :wink:

Can you repair my code i posted? Thanks

Yes I can. But I wished you could learn instead of copying.

I can learn from examples, thats why i asked. Then if you will be nice i can ask and you tell me why that and why this :*

You say agent is Mozilla. Then you say agent is Macintosh. Then you say agent is Mozilla.

If I ask you now “what is agent” then what will your answer be?

Please read “Introduction to Programming”. Rick is being very kind to you, but the simple fact of the matter is that you do not even understand what a variable is or how it works. That is a very very basic thing in programming. It is like a maths student not understanding what addition is.

No. That is a very lazy way. The forum is not here to teach you, they are here to help you.

You really have to learn things first. You can’t simply say “I don’t want to learn, just show me and explain what I do not understand”

Sir this all agents are from website useragents, it is not bad things, so please explain, because i wnated to change different useragents not only mozzila, thats why i changed, and yes i’m in the first 7month of learning and started with basic then found realbasic, so i think this forulm should be for help not for judging me.
anyways thx

P.S. Rick already told you: you need to look at arrays and how they work.

Actually the forum is here to teach you AND to help you… but only if you help yourself first.

So…
Create an Array
Add all your agents to the array
use the SHUFFLE function
Take the first element from the resultant array…this will be a random value

Now… that is the METHOD… read the documentation to figure how to implement it…

Come back with what you have tried, and we will point in the the right directioin

and nobody is JUDGING you… but YOU HAVE TO PUT FORTH AN EFFORT … we shall nnot do your work for you… just guide and assist

thx dave i will go to try

What is the answer to my question?

[quote]You say agent is Mozilla. Then you say agent is Macintosh. Then you say agent is Mozilla.

If I ask you now “what is agent” then what will your answer be?[/quote]

Agent can be Mozzila or chrome or any, and i forgot to add before “Mozila” so what is your problem? You want to show me my error but I am asking you not with your tone, you can scream on you wife like that not on me, as i have bad feelings from your messages you are agressor!

[quote=90745:@Dave S]Actually the forum is here to teach you AND to help you… but only if you help yourself first.

So…
Create an Array
Add all your agents to the array
use the SHUFFLE function
Take the first element from the resultant array…this will be a random value

Now… that is the METHOD… read the documentation to figure how to implement it…

Come back with what you have tried, and we will point in the the right directioin

and nobody is JUDGING you… but YOU HAVE TO PUT FORTH AN EFFORT … we shall nnot do your work for you… just guide and assist[/quote]

Ok I try this, not work:

  if PopupMenu1.Text = "Firefox Mac" Then
    dim agent as Random
    
    agent = Array(Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0)
    agent = Array(Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0)
    agent = Array(Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0)
    agent = Array(Mozilla/6.0 (Macintosh; I; Intel Mac OS X 11_7_9; de-LI; rv:1.9b4) Gecko/2012010317 Firefox/10.0a4)
    agent = Array(Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0)

HTMLViewer1.UserAgent = agent
HTMLViewer2.UserAgent = agent
HTMLViewer3.UserAgent = agent
HTMLViewer4.UserAgent = agent
HTMLViewer5.UserAgent = agent
    
  End if

Also I tried this; but not working.

  if PopupMenu1.Text = "Firefox Mac" Then
    dim agent as string
    agent = Array("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0")

HTMLViewer2.UserAgent = agent
HTMLViewer3.UserAgent = agent
HTMLViewer4.UserAgent = agent
HTMLViewer5.UserAgent = agent
    
  End if

And you obviously did NOT read any of the documentation…
If you had I would have seen an ARRAY in your code, I would have seen the word SHUFFLE in your code…

DIM Agent () as string
dim i as integer
agent.append "Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101  Firefox/28.0"
agent.append  "Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0"
agent.append "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0"
agent.append "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"
agent.append "Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36"
agent.append "Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"
agent.append "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
agent.append  "Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52"
agent.append "Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00"
agent.append  "Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20031026 Firebird/0.7"
agent.append "Windows; U; Windows NT 6.1; x64; fr; rv:1.9.2.13) Gecko/20101203 Firebird/3.6.13"

for i=1 to 5
agent.shuffle
select case i
case 1
HTMLViewer1.UserAgent = agent(0)
case 2
HTMLViewer2.UserAgent = agent(0)
case 3
HTMLViewer3.UserAgent = agent(0)
case 4
HTMLViewer4.UserAgent = agent(0)
case 5
HTMLViewer5.UserAgent = agent (0)
end select
next i

I am not saying this “works”, as I typed it off the top of my head… but unless you make an attempt to figure things out, you will not get much further support. Just typing code and saying “it doesn’t work” won’t cut it. You need to make an attempt to figure out why… how else are you going to learn…