Get variable value from online stored txt file

rickrack

Member
Licensed User
Longtime User
Hi all B4A developers!
I'm developing an application with a countdown for a football match that every week should be updated. I made it in PHP and I change the variables values (stadium, time, team names) from some online stored txt files: the PHP page get that values and update itself.
I would like to do the same with Basic4Android. I have no problems for layout, but I would like to know how can I assign a string or a number value from an online stored txt file's content to a B4A variable.

I would be very glad if you help me.
Sorry for some English grammar errors eheh

Regards,
Riccardo
 

rickrack

Member
Licensed User
Longtime User
Thanks a lot for your reply but I'm a noob... could you help me?
I think I know how to download the .txt file but I don't know how to read it to assign the content to a variable..
 
Upvote 0

rickrack

Member
Licensed User
Longtime User
for example, if I would display in a label "ROMA", the .txt should contain just ROMA

Thank for your assistance
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I really don't understand what you mean by that, but if the .txt contains only the word "Roma" for example, then you should do something like this:
B4X:
Sub hc_ResponseSuccess(Response As HttpResponse, TaskId As Int)

    Label1.Text = Response.GetString("UTF8")

...

But then again, without having more details it will be very hard to explain and understand.
 
Upvote 0

rickrack

Member
Licensed User
Longtime User
friend, there aren't other details

what I would like to do is:
- download a txt file from the web
- make the content of this txt file the value of a variable

Probably it's my English, it isn't very good, I'm sorry

let me know if you understood
 
Upvote 0

johnB

Active Member
Licensed User
Longtime User
Hi NJDude

I'm trying to load a txt (or csv) file from my server in B4A and can't get this to work

I'm using

req.InitializeGet("http://johnb9999.xxxx/WIN-KA57JNPJAAS/Server C/B4A_TestText.txt") - where WIN-KA57JNPJAAS is my server. I've tried numerous variations of this but none seem to work

But I get an error message "Error in app" "Document Error: Site or Page Not Found" and "Cannot open URL"

Does it need a particular port opened

http://www.johnb9999.xxxx doesn't load in a web browser where as http://johnb9999.xxxx does

johnb9999.xxxx is working with RDC and Don Manfred's MySQL Library
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Hi @johnB

I'm going to go way out on a limb here but, I'm noticing a space in the URL. If your using a unix/Linux based server then my past experience is that spaces tend to break the URL. You may need to changed the directory name on the server to remove the space and/or replace it with a hyphen '-'.

On the issue of the URL with the 'www' not working this may be due to a missing DNS entry for your site.
 
Upvote 0

johnB

Active Member
Licensed User
Longtime User
Ed, Sorex, thanks for your help. It's a Windows Server but I've also tried putting the file in the root (C:\) directory but that didn't work either.

I got the www. problem sorted but this didn't help either.

What I'm confused about is the web address, "xxxxxx.com". I'm using is a No-IP address and it's working fine with RDC and Don Manfred's Library but they point to a device attached to the router by port forwarding, 17178 for RDC and 3306 for MySql, so by running this command without a port, I don't know how it knows how to find the file.

Sorry for my ignorance, but I'm a business app person so am a bit of a noob when it comes to this stuff - it seemed simple enough but ???????
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
Hi @johnB

After reading your post again I realised that it seems that you are wanting to programmatically retrieve a file from your web server. If my assumption on this is correct then using HttpUtils2 might be a better solution for you.

A GET, simply stated, is a constructed request (via the URL) to a web service where a response of some type is expected from the service. A GET request will have a structure like 'www.mywebservice.com/service?param1=value1&param2=value2'. The 'service' part is quite often a script like PHP or javascript but can also be a web app. The '?' is the separator between the web service URL and the beginning of the parameter/argument list. Each parameter/argument is constructed as a name=value pair and each pair is separated by an ampersand '&'.

So, if the URL you are using is the path to the file directly then you using the HttpUtils2 library is what you'll be wanting to use.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…