html.loadurl problem

Hi, I have a problem I can’t figure out. (I’m on Xojo 2017 r3)
I googled for this but can’t find it.
I have a listbox, populated with url’s
I do the following:
get the index for the selected row, pass it to the listbox to get the content and load the selected url
but it doesn’t work

[code]dim theIndex as integer
theIndex = listURL.ListIndex

dim theURL as string
theURL = listURL.List(theIndex)

msgbox(theURL) '===> this shows the selected URL just fine

HTML.LoadURL(“https://mywebsitehere.com”) '===> this does work
HTML.LoadURL(theURL) '===> this however doesn’t work[/code]

does anyone have a clue what I’m doing wrong,

HTML.LoadURL( EncodeURLComponent( theURL ) ) '===> this sould work

Source: http://documentation.xojo.com/api/text/encoding_text/encodeurlcomponent.html

Unfortunately that (EncodeURLComponent) does not work either …

Try this. It works for me on 2019 R1.1.

HTML.LoadURL(theURL).ToText

Edit:

Tested working on 2017 R3.

Please, provide a real URL and then we will start to do a good job.

Why ?

Some URLs are relocated and will not work as is (error 301 if I recall correctly)

Please, try this url: https://www.example.com/

[code]dim theIndex as integer
theIndex = listURL.ListIndex

dim theURL as string
theURL = listURL.List(theIndex)

msgbox(theURL) '===> this shows the selected URL just fine

HTML.LoadURL(“https://mywebsitehere.com”) '===> this does work
HTML.LoadURL(theURL) '===> this however doesn’t work[/code]

you should do check if the ListIndex <> -1

[quote]
If no item is selected, ListIndex returns -1. If the ListBox is in multiple-row selection mode, then the number of the lowest selected row is returned. For example, if rows 1, 3, and 4 are selected, ListIndex returns 1.

You can put the ListBox into multiple-row selection mode by changing the SelectionType property.[/quote]
see:
http://documentation.xojo.com/api/deprecated/listbox.html#listbox-listIndex

So try :

[code]
dim theIndex as integer
theIndex = listURL.ListIndex

If theIndex = -1 Then
MsgBox “Please Select an item”
return
End If

dim theURL as string
theURL = listURL.List(theIndex)

msgbox(theURL) '===> this shows the selected URL just fine

HTML.LoadURL(“https://mywebsitehere.com”) '===> this does work
HTML.LoadURL(theURL) '===> this however doesn’t work[/code]

The comment from Emile Schwarz defines the problem exactly …
example.com works perfectly …
on of my links is https://www.imagicasa.be/nl/stories and that doesn’t work …

Then how do I get this to load ?

Sample file here:

https://cp.sync.com/dl/30032dd50/qt4zchq3-4h7resnj-xs2qptza-uprtwnwq

Thank you SO much :slight_smile:

[quote=462417:@Tanner Lee]Sample file here:

https://cp.sync.com/dl/30032dd50/qt4zchq3-4h7resnj-xs2qptza-uprtwnwq[/quote]

Really? This is NOT the answer… Please tell us what went wrong and prevent others from running into the same issue. :slight_smile:

The pointed solution says that there is/was a bug with HTML.LoadURL( aStringValue ) but it works with HTML.LoadURL( aTextValue )

So the proposed workaround was HTML.LoadURL( aString.ToText() )

[quote=462440:@Rick Araujo]The pointed solution says that there is/was a bug with HTML.LoadURL( aStringValue ) but it works with HTML.LoadURL( aTextValue )

So the proposed workaround was HTML.LoadURL( aString.ToText() )[/quote]

Strange (because a String should work just fine). But thank you :slight_smile:

Try converting the encoding to UTF8

OK, I’m sorry: I had marked the demofile as answer, but it was too soon. I saw it in action, and believed the “ToText” (inside the brackets, as opposed to the earlier answer with ToText outside the brackets) was the solution. I couldn’t test it out though as I really needed to work on something else. Now that I have tested it, it isn’t the solution …
However, the sample code did point me in the right direction.
I saw the code from Tanner Lee, and he populated the listbox row with a literal string. And everything worked …
I didn’t notice huge differences with my code, so I guessed the problem wasn’t my code, but my variable string.
I get the strings from reading each line in a textfile and adding them to the listbox as a row.
Adding — before and after the string showed me there was a line ending I wasn’t aware of.
In the shell I now trim the line ending with " tr -d ’
’ " before passing it to listbox and all works fine …
So a big thanks for all the help, I really appreciate it. I just started with Xojo (after years of Applescripting everything), I’m totally excited, and it’s great to see there is a nice community with friendly people who are willing to help each other out :slight_smile:

That’s what I thought at first too. The debugger showed a simple UTF8 string without any gremlins. But the htmlviewer wouldn’t open it. Added .ToText to the variable and it worked.

In light of Chris’ comment above I removed the .ToText call, and now it worked as documented.

Chalking this up to a cache issue. Have 9 versions of RS/Xojo installed. :frowning: