You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

JMOODY

Beginner

  • "JMOODY" started this thread

Posts: 7

Date of registration: Mar 24th 2009

  • Send private message

1

Thursday, April 2nd 2009, 8:15am

Communicating between forms and with the internet in Jabaco

Hi,
There are some things that are actually easier in Jabaco than in Basic; usually one finds that a very small change takes some figuring out. Re forms, I had been stuck for a long time in that a program with two forms, in Form1 I had

Form2.text1.text="hello"

and it would give an error message about using class names. I finally realized that you can have lots of copies of Form2 with different names like

Dim A as new Form2
Dim B as new Form2

and then you can say

A.text1.text="Hello"
B.text1.text= "And hello again from over here!"

------------------------------------------

Regarding reading from a URL into a file, the only thing I had trouble with was detecting the end of the URL. Jabaco understands that Nothing is different from the empty string, but when you say

a$=Nothing
b$= ""
if a$=b$ then msgbox ("they are equal")

it says that they are, ie once Nothing is read into a string, it is considered to be the empty string. This means I was having trouble detecting when the URL from the internet was read. Finally I found that Java has something called ready() for buffered readers, analogous to available() for input streams. Here is how to read a website into an array of strings. Much easier than Basic!

dim a as string
dim b as java#net#url
dim c as java#io#InputStream
dim d as java#io#InputStreamReader
dim e as java#io#BufferedReader
dim f(1000) as string
dim n as integer


a="http://www.javaco.org" ' or whatever you want
b= New java#net#url(a$)
c=New java#io#InputStream(a$.openStream)
d=New java#io#InputStreamReader(c$)
e=New java#io#BuffferedReader(d)
n=1

Do while e.ready()
f(n)=e.readline()
n=n+1
loop
d.close()
e.close()



I might have misremembered something, this is just typed from memory, so it you copy and paste it might require an adjustment, but Jabaco was good about explaining errors during compile time and run time; and during compile time it seemed to understand the meaning of all the various java classes...

JMOODY

Beginner

  • "JMOODY" started this thread

Posts: 7

Date of registration: Mar 24th 2009

  • Send private message

2

Thursday, April 2nd 2009, 8:18am

Yes, I already see this line was wrong

c=New java#io#InputStream(a$.openStream)

should of course be

c=New java#io#InputStream(b$.openStream)

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Wednesday, April 14th 2010, 9:42am

load a file from the Internet - 'Constructor io/InputStream not found'

I have been trying to get my App to load a file from the Internet with this. But I keep getting this ErrMsg:

'Constructor for class 'java/io/InputStream' not found with this Parameter'

while starting the sample
The cursor gets stuck right after:

c=New java#io#InputStream(b.openStream)

I am not really fmiliar with java so I would really appreciate some help!
And while I'm at it any one with an idea on how to do a 'ShellExecute' kind of thing to open standard browser with a given url?

Thanks everyone...

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Wednesday, April 14th 2010, 10:23am

Hi,
the following works for me:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Dim a As String
   Dim b As java#net#URL 
   Dim conn As java#net#URLConnection 
   Dim c As java#io#InputStream
   Dim d As java#io#InputStreamReader
   Dim e As java#io#BufferedReader
   Dim f(1000) As String
   Dim n As Integer

   ' in case we are behind a proxy
   System.setProperty("http.proxyHost", "myproxy.xyz")
   System.setProperty("http.proxyPort", "8080")
   System.setProperty("http.proxyUser", "myuser")
   System.setProperty("http.proxyPassword", "mypassword")

   a = "http://www.jabaco.org" ' or whatever you want
   b = New java#net#URL(a)
   conn = b.openConnection()
   c = conn.getInputStream()
   d = New java#io#InputStreamReader(c)
   e = New java#io#BufferedReader(d)
   n = 1

   Debug.Print "before loop"
   Do While (n <= UBound(f)) And e.ready()
      f(n) = e.readLine()
      Debug.Print n & ": " & f(n)
      n = n + 1
   Loop
   d.close()
   e.close()


This is just a crude sample. To use it for any decent purpose, additional error checking is needed.
The sample shows how to access Java library classes.
Please use Google to find out what the various steps are doing in detail.

Success!

A1880

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

5

Wednesday, April 14th 2010, 10:32am

To start the default browser for a given URL you can do the following:

Jabaco Source

1
2
3
4
5
6
Const quote = Chr(34)
   Dim url As String = "http://www.jabaco.org"
   Dim cmd As String = "cmd.exe /c start " & quote & "my window" & quote & " " & url
   
   Debug.Print cmd
   Shell(cmd)


The Chr(34) trick avoids Jabaco's limitation with quote characters within strings.
The code works under Windows.

Cheers

A1880

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

6

Wednesday, April 14th 2010, 10:48am

That was quick!
And it does work just fine, thank you.
The proxy addition helps too.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

7

Wednesday, April 14th 2010, 10:56am

Does anyone come up with a java way to open the browser with a given url so it works on the mac too!?

Thanks again 1880

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

8

Thursday, April 15th 2010, 11:40am

You could use or take some inspiration from external Java libraries like this one.
It might be possible to migrate the Java code to Jabaco rather than using the *.jar file externally.
Please let us know about your findings.

Greetings

A1880

Tobias

Beginner

  • "Tobias" is male

Posts: 12

Date of registration: Mar 31st 2010

Location: Sweden

Occupation: Programmer / Network tech

  • Send private message

9

Thursday, April 15th 2010, 2:43pm

Thanks for this tip! Really neat! :)

Do you know how to ping an address in Jabaco as well?

Something like:

a = pingreply "www.google.com"
if a = True then
msg "site up"
else
msg "no reply"
endif

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

10

Thursday, April 15th 2010, 3:23pm

Try to implement this in Jabaco.
There must be loads of similar Java snippets in the cellars of Google.
You could modify my sample from Wednesday and leave the receive loop after the first line of HTML.

The problem is that you need some sort of timeout or exception which makes it a bit complicated.

Another way might be to shell out, call your OS ping and intercept its results.

Please post your findings here.

Success!

A1880

Tobias

Beginner

  • "Tobias" is male

Posts: 12

Date of registration: Mar 31st 2010

Location: Sweden

Occupation: Programmer / Network tech

  • Send private message

11

Friday, April 16th 2010, 11:54pm

Thanks for your reply A1880!

I'm trying to test Windows clients SMB share to see if they are up'n running because I have built a system where clients on local subnets can copy files from each others to avoid network traffic on the WAN link. The client is written in VB6.

The problem I have is when the clients are turned off, the SMB call have a very long time out in Windows (about 30 seconds). I test several clients (up to 10-20) so the connection test can take several minutes if the clients are turned off.

The solution would be to 'ping' the clients before I try to access the SMB share. So to get a reply from an internet web site wouldn't solve my problem. Sorry if I was unclear in my previous post! ;)

If i use a shell request to ping, how can I read the output from the shell command? And how do I get the shell commands cross platform? Is this even possible? In Windows i would use "cmd /c ping hostname" and in Linux "ping hostname". Maybe there are ways for the Jabaco code to test if the program runs in Windows or Linux?

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

12

Saturday, April 17th 2010, 1:09pm

Lots of questions!

The following ideas come to my mind:

1. You could use Jabaco's multi-threading capability to test the clients in parallel rather than sequentially.
this would reduce the overall time. Be warned: multi-threading is not for the faint-hearted ...

2. It is probably possible to issue a ping by using a Java API.

Jabaco Source

1
2
3
String host = "172.16.0.2"
int timeOut = 3000; // 3 seconds at least int timeout = 3000; 
boolean status = InetAddress.getByName(host).isReachable(timeOut) boolean status = InetAddress.getByName (Host).isReachable (timeOut)


3. You can find out the current operating system via System.getProperty("os.name") as shown here

As always: please post your findings here

Cheers

A1880

Tobias

Beginner

  • "Tobias" is male

Posts: 12

Date of registration: Mar 31st 2010

Location: Sweden

Occupation: Programmer / Network tech

  • Send private message

13

Saturday, April 17th 2010, 9:37pm

Thanks a lot! It seems to work good!

Source code

1
2
3
4
5
6
7
8
Public Sub Form_Load()
   host = "127.0.0.1"
   timeOut = 3000' // 3 seconds at least int timeout = 3000; 
   status = InetAddress.getByName(host).isReachable(timeOut)
   MsgBox status
   
   MsgBox System.getProperty("os.name")
End Sub


Now I'm a step further towards converting my old VB6 program to Jabaco! 8)

Sbleck

Beginner

  • "Sbleck" is male

Posts: 13

Date of registration: May 29th 2010

Location: Santos, Brazil

Occupation: Consultant

Hobbies: Builing some apps for accessing databases and some automation processes

  • Send private message

14

Saturday, May 29th 2010, 8:25pm

What should I need to test this ?

Thanks a lot! It seems to work good!

Source code

1
2
3
4
5
6
7
8
Public Sub Form_Load() 
host = "127.0.0.1" 
timeOut = 3000' // 3 seconds at least int timeout = 3000; 
status = InetAddress.getByName(host).isReachable(timeOut) 
MsgBox status 

MsgBox System.getProperty("os.name") 
End Sub


Now I'm a step further towards converting my old VB6 program to Jabaco! 8)

Hello,

Thanks for leaving some code samples to test this interesting issue. But I wanted to know what class should I have activated in my project, to not having problems like mentioned below:

java.lang.Exception: CallByName 'getByName' failed!
at VBA.Interaction.CallByName(Interaction.java:186)
at VBA.Interaction.CallByName(Interaction.java:184)
at VBA.Interaction.CallByName(Interaction.java:175)
at Form1.Form_Load(Form1.jsrc:15)
at VB.AbstractForm.fireLoaded(AbstractForm.jsrc)
at VB.LoadAdapter.run(LoadAdapter.jsrc)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


Sorry if this message content appear to be so dummy, but I´m now a novice in Jabaco world. Any advice should be greatly appreciated, of course too...

Rgds,

Sven

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

15

Sunday, May 30th 2010, 12:42am

The following works for me:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Option Explicit

Public Sub Form_Load() 
   Dim host As String
   Dim timeOut As Integer 
   Dim status As Boolean

   host = "127.0.0.1" 
   timeOut = 3000' // 3 seconds at least int timeout = 3000; 
   status = java#net#InetAddress.getByName(host).isReachable(timeOut) 
   MsgBox status 

   MsgBox System.getProperty("os.name") 
End Sub


Greetings

A1880

Sbleck

Beginner

  • "Sbleck" is male

Posts: 13

Date of registration: May 29th 2010

Location: Santos, Brazil

Occupation: Consultant

Hobbies: Builing some apps for accessing databases and some automation processes

  • Send private message

16

Sunday, May 30th 2010, 1:41am

Hello,



Yes, it´s working now... :)



I tried in other machine to see that running. I´m looking in previous machine the code to see what could be wrong in the code, also...



Tks,

Sven

Rate this thread
WoltLab Burning Board