Re: [Gambas-user] Where is the mistake?

2019-04-08 Thread nando_f
I'd like to point out that the five uses of 'Now' in the example all occur at 
different
times - but very close together temporally.
A better test is to use only one 'Now' in the program into a variable and 
format with the
different lines.



--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Benoît Minisini 
To: mailing list for gambas users 
Sent: Mon, 8 Apr 2019 16:47:25 +0200
Subject: Re: [Gambas-user] Where is the mistake?

> Le 08/04/2019 à 16:21, Hans Lehmann a écrit :
> > Hello!
> > 
> > Where is the mistake?
> > 
> > Print "Time-Part:  "; Round(Frac(Now()), -8); " ▸ "; 
> > Format$(Time(Frac(Now())), "hh:nn:ss"); Format$(Time(Frac(Now())), "(t)")
> > Print "Time-Part:  "; Round(Frac(Now()), -8); " ▸ "; 
> > Format$(Time(Now()), "hh:nn:ss"); Format$(Time(Now()), "(t)")
> > 
> > Output:
> > 
> > Time-Part:  0,59328568 ▸ *14*:14:19 (CEST) ' UTC!
> > Time-Part:  0,59328568 ▸ *16*:14:19 (CEST)
> > 
> > Regards
> > 
> > Hans
> >
> 
> Please use the new mailing-list.
> 
> Regards,
> 
> -- 
> Benoît Minisini
> 
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---



___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Class array - Null Object

2018-01-28 Thread nando_f
For TheCounter = 0 To 100   
   TheArray[TheCounter] = New Class1  <--- you need to create a new object at 
each element
   TheArray[TheCounter].I = TheCounter< Your error because no 
object at
the element exists.  You only created the array.


--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Phan Damily via Gambas-user 
To: "gambas-user@lists.sourceforge.net" 
Cc: Phan Damily 
Sent: Mon, 29 Jan 2018 04:53:41 + (UTC)
Subject: [Gambas-user] Class array - Null Object

> Hello everyone. I'm new to Gambas and new to the mailing list. I'm using 
> v3.10.0 
> on Linux.I programmed extensively with VB6 back in the day. So Gambas is 
> pretty 
> straight-forward and I'm excited about switching over from Xamarin's C#.
> 
> But I've ran into a situation with Gambas I can't resolve. I've been testing 
> code ideas, trying to create a working one-dimensional class array. But keep 
> getting "Null object" errors when trying to assign values to fields. ' 
> Class1.class
> Public I As Integer
> Public S As String
> ' FMain.classPublic TheArray As New Class1[]
> 
> Public Sub cmdTest_Click()
> Dim TheCounter As Integer
> TheArray = New Class1[]
> TheArray.Resize(100)For TheCounter = 0 To 100   
>     TheArray[TheCounter].I = TheCounter    < 
> Null object in FMain     TheArray[TheCounter].S = CStr(TheCounter)   
>   Next     For TheCounter = 0 To 100     Print 
> TheArray[TheCounter].I, TheArray[TheCounter].S     NextEnd
> 
> I'm sure the solution is pretty simple. But I haven't been able to find an 
> answer or a working code example for this particular situation. Thanks for 
> reading.
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] SocketServer issue

2017-09-25 Thread nando_f
My first guess would be that a socket server can't listen
on a port without an IP associated with it.
If your network connection is DHCP then the server can't listen.
It you have a hard IP, then it can.



--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Miguel Manso 
To: gambas-user@lists.sourceforge.net
Sent: Thu, 21 Sep 2017 19:41:38 +0100
Subject: [Gambas-user] SocketServer issue

> Hi guys,
> 
> I've an application that starts a SocketServer on port 8088. All works ok
> when I've the network cable inserted on the machine.
> 
> If I boot the machine without the network cable inserted, the SocketServer
> doesn't listen on port 8088 and it doesn't raise the _Error event.
> 
> This happens on a particular machine. On a different one, it behaves ok
> when it starts with no network cable on it.
> 
> The postgres server (port 5432) starts ok in both machines.
> 
> Any clue why this is happening?
> 
> Thanks.
> 
> -- 
> Miguel Manso
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] New domain name for Gambas

2017-09-01 Thread nando_f
Gambas.ca is available
I am in Canada, I will donate purchase it for you on an on-going basis.
-Fernando (in Canada)

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Benoît Minisini via Gambas-user 
To: gambas-user@lists.sourceforge.net
Cc: Benoît Minisini 
Sent: Fri, 1 Sep 2017 22:39:42 +0200
Subject: [Gambas-user] New domain name for Gambas

> Hi,
> 
> As gambas.{org,net,com...} are all unavailable, I'm thinking about 
> buying g4mbas.org (or .net, .com...) as a new domain name for Gambas.
> 
> Another solution would be buying gambashq.org or gambas-something.org... 
> But I find g4mbas more funny.
> 
> What do you think about that, people?
> 
> -- 
> Benoît Minisini
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] reading files

2017-07-17 Thread nando_f
I think
Read #hfile, IDtag, ID3v1_TAG 
should be
Read #hfile, IDtag as ID3v1_TAG


--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Shane 
To: gambas-user@lists.sourceforge.net
Sent: Tue, 18 Jul 2017 10:50:43 +1000
Subject: Re: [Gambas-user] reading files

> i don't know what i am doing wrong
> 
> Public Struct ID3v1_TAG  '(128 bytes)
>   Tag[3] As String   'always TAG
>   Title[30] As String 'title, 30 characters
>   Artist[30] As String   'artist, 30 characters
>   Album[30] As String   'album, 30 characters
>   Year[4] As String  'year, 4 characters
>   Comment[30] As String  'comment, 30 characters (or 28 if 
> track# included)
>   Genre As Byte   'genre, 255 for none defined
> End Struct
> 
> Private Sub GetID3v1(File As String)
>  Dim IDtag As ID3v1_TAG
>  Dim hfile As File
> 
>  hfile = Open File For Read
> 
>  '
>  'read the tag
>  ' seek to end of less tag size
> 
>  Read #hfile, IDtag, ID3v1_TAG
> 
> here i get IDtag is NULL
> 
> On 18/07/17 05:05, nand...@nothingsimple.com wrote:
> > Yes it is possible, I do it.  here is some code (incomplete)
> >
> > -Nando (Canada)
> >
> >
> >
> > ' top of class file
> > Public Struct recstruc
> >_a as integer
> >_b as integer
> >_c as integer
> > end struct
> >
> >
> > ' a function
> > public function openAfile(filename as string) as file
> >
> > dim hfile as file
> > dim arec as recstruc
> >
> > hfile = open filename for read write create
> >
> > with arec   'some values to write.
> >._a = 1
> >._b = 22
> >._c = 333
> > end with
> >
> > write #hfile, arec as recstruc
> >
> > 'if you position the hfile pointer back to zero, you can...
> > read #hfile, arec as recstruc
> >
> > close #hfile
> >
> > end
> >
> >
> >
> >
> >
> >
> > --
> > Open WebMail Project (http://openwebmail.org)
> >
> >
> > -- Original Message ---
> > From: T Lee Davidson 
> > To: gambas-user@lists.sourceforge.net
> > Sent: Sun, 16 Jul 2017 12:42:35 -0400
> > Subject: Re: [Gambas-user] reading files
> >
> >> On 07/16/2017 06:57 AM, Shane wrote:
> >>> given this example
> >>>
> >>> PRIVATE SUB BinaryRead(FilePath AS String)
> >>> DIM binaryFile AS File
> >>> DIM i AS Integer
> >>> DIM b AS Byte
> >>> DIM s AS Short
> >>> DIM s1 AS String
> >>> DIM s2 AS String
> >>> ' Read binary file
> >>> binaryFile = OPEN FilePath FOR READ
> >>> READ #binaryFile, i
> >>> READ #binaryFile, b
> >>> READ #binaryFile, s
> >>> READ #binaryFile, s1
> >>> READ #binaryFile, s2
> >>> CLOSE #binaryFile
> >>> ' Display results
> >>> PRINT i
> >>> PRINT b
> >>> PRINT s
> >>> PRINT s1
> >>> PRINT s2
> >>> END
> >>>
> >>>
> >>> is there a way for gambas to read a struct of all these variables
> >>> in one read ?
> >>>
> >> You may have hinted at the solution within your question. Have you 
> >> considered
> >> using a Structure?
> >>
> >> http://gambaswiki.org/wiki/lang/read :
> >> "... reads the stream Stream as binary data whose type is specified by the
> >> Datatype argument."
> >>
> >> "The returned datatype can be one of the following: NULL, Boolean, Byte, 
> >> Short,
> >>   Integer, Long, Pointer, Single, Float, Date, String, Variant, any Array,
> >>   Collection or structure."
> >>
> >> http://gambaswiki.org/wiki/lang/structdecl
> >>
> >> -- 
> >> Lee
> >>
> >> --
> >> Check out the vibrant tech community on one of the world's most
> >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> >> ___
> >> Gambas-user mailing list
> >> Gambas-user@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
> > --- End of Original Message ---
> >
> >
> > --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on 

Re: [Gambas-user] reading files

2017-07-17 Thread nando_f
Yes it is possible, I do it.  here is some code (incomplete)

-Nando (Canada)



' top of class file
Public Struct recstruc
  _a as integer
  _b as integer
  _c as integer
end struct


' a function
public function openAfile(filename as string) as file

dim hfile as file
dim arec as recstruc

hfile = open filename for read write create

with arec   'some values to write.
  ._a = 1
  ._b = 22
  ._c = 333
end with

write #hfile, arec as recstruc

'if you position the hfile pointer back to zero, you can...
read #hfile, arec as recstruc

close #hfile

end






--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: T Lee Davidson 
To: gambas-user@lists.sourceforge.net
Sent: Sun, 16 Jul 2017 12:42:35 -0400
Subject: Re: [Gambas-user] reading files

> On 07/16/2017 06:57 AM, Shane wrote:
> > given this example
> > 
> > PRIVATE SUB BinaryRead(FilePath AS String)
> >DIM binaryFile AS File
> >DIM i AS Integer
> >DIM b AS Byte
> >DIM s AS Short
> >DIM s1 AS String
> >DIM s2 AS String
> >' Read binary file
> >binaryFile = OPEN FilePath FOR READ
> >READ #binaryFile, i
> >READ #binaryFile, b
> >READ #binaryFile, s
> >READ #binaryFile, s1
> >READ #binaryFile, s2
> >CLOSE #binaryFile
> >' Display results
> >PRINT i
> >PRINT b
> >PRINT s
> >PRINT s1
> >PRINT s2
> > END
> > 
> > 
> > is there a way for gambas to read a struct of all these variables
> > in one read ?
> >
> 
> You may have hinted at the solution within your question. Have you considered 
> using a Structure?
> 
> http://gambaswiki.org/wiki/lang/read :
> "... reads the stream Stream as binary data whose type is specified by the 
> Datatype argument."
> 
> "The returned datatype can be one of the following: NULL, Boolean, Byte, 
> Short,
>  Integer, Long, Pointer, Single, Float, Date, String, Variant, any Array,
>  Collection or structure."
> 
> http://gambaswiki.org/wiki/lang/structdecl
> 
> -- 
> Lee
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Best ways to format float values

2017-07-16 Thread nando_f
Rounding depends on what rounding you want.
Most people think of 5/4 rounding.
I prefer to round manually 5/4... 5 up, 4 down.

Dim n as Float = 26.6601

n = n * 100.  'n = 2666.01   ' 2 decimal points rounding
n = n + 0.5   'n = 2666.51   ' 5/4 rounding*
n = CLong(n)  'n = 2666
n = n / 100.  'n = 26.66


*If you wish to round down, do not add 0.5.  (add 0.0)
*If you wish to round up, add 0.9

If you wish to do 3 digits, then *1000 and /1000.
This works for any type of rounding scheme and any reasonable number of digits.

-Nando(Canada)


--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Gianluigi 
To: mailing list for gambas users 
Sent: Thu, 13 Jul 2017 12:30:23 +0200
Subject: Re: [Gambas-user] Best ways to format float values

> One thing that could be useful?
> 
> Public Sub Main()
> 
>   Dim n As Float = 26.66016
>   Dim b As Byte
> 
>   b = Val(Mid(CStr(Frac(n)), 5, 1))
>   Print Round(n, -2)
>   If b >= 5 Then
> Print Round(n, -2)
>   Else
> Print Round(n + 0.01, -2)
>   Endif
> 
> End
> 
> Regards
> Gianluigi
> 
> 2017-07-13 7:39 GMT+02:00 alexchernoff :
> 
> > Peace to all,
> >
> > this might a bit silly but what is the best way to format float values like
> > 26.66016 into having two digits AND/OR  with rounding them?
> >
> > e.g.
> >
> > 26.66016 becomes 26.66 shortened
> > 26.66016 becomes 26.67 rounded
> >
> > cheers!
> >
> >
> >
> >
> >
> > --
> > View this message in context: http://gambas.8142.n7.nabble.
> > com/Best-ways-to-format-float-values-tp59733.html
> > Sent from the gambas-user mailing list archive at Nabble.com.
> >
> > 
> > --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] I need a hint on how to deleted duplicate items in a array

2017-07-01 Thread nando_f
there are much faster ways...just a little more 
intricate.

Nando

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Fernando Cabral 
To: mailing list for gambas users 
Sent: Sat, 1 Jul 2017 00:18:42 -0300
Subject: Re: [Gambas-user] I need a hint on how to 
deleted duplicate items in a array

> I thank you guys for the hints on counting and 
eliminating duplicates. In
> the end, I resorted to something that is very 
simple and does the trick in
> three steps. In the first step I sort the array.
> In the second step I count the number of 
occurrences and prepend it to the
> word itself (with a separator). In the third step 
I sort the array again,
> so now I have it sorted by the number of 
occurrences from the largest to
> the smallest.
> 
> That is all I need.
> 
> Nevertheless, I am concerned with the performance. 
For 69,725 words, from
> which 8,987 were unique, it took 28 seconds for 
the code below to execute.
> I will survive this 28 seconds, if I have to. But 
I still would like to
> find a faster solution.
> 
> On the other hand, I think I am close to the 
fastest possible solution.
> Basically, the array will be traversed once only, 
no matter how many terms
> and how many repetitions it may have.
> 
> (What do you think about this efficiency, Tobi?)
> 
> *MatchedWords.Sort(gb.ascent + gb.language + 
gb.IgnoreCase) For i = 0 To
> MatchedWords.Maxn = 1For j = i + 1 To 
MatchedWords.Max  If
> (Comp(MatchedWords[i], MatchedWords[j], 
gb.language + gb.ignorecase) = 0)
> Then n += 1  Else Break  
EndifNext
> UniqWords.Push(Format(n, "0###") & "#" & 
MatchedWords[i])i += (n - 1)
> NextUniqWords.Sort(gb.descent + gb.language + 
gb.ignorecase)For i = 0 To
> UniqWords.Max   Print UniqWords[i]Next*
> 
> 2017-06-30 15:10 GMT-03:00 Gianluigi 
:
> 
> > Just for curiosity, on my computer, my function 
(double) processes 10
> > million strings (first and last name) in about 3 
seconds.
> > Very naif measurement using Timers and a limited 
number of names and
> > surnames eg Willy Weber has come up 11051 times
> >
> > To demonstrate the goodness of Tobias' 
arguments, about 1 million 3 cents a
> > second I really understood (I hope) what he 
wanted to say.
> >
> > Sorry my response times but today my modem works 
worse than my brain.
> >
> > Regards
> > Gianluigi
> >
> > 2017-06-30 17:58 GMT+02:00 Gianluigi 
:
> >
> > > Sorry Tobias,
> > > other explanations are not necessary.
> > > I would not be able to understand :-(
> > > I accept what you already explained to me as a 
dogma and I will try to
> > put
> > > it into practice by copying your code :-).
> > >
> > > Thanks again.
> > >
> > > Gianluigi
> > >
> > > 2017-06-30 17:44 GMT+02:00 Gianluigi 
:
> > >
> > >>
> > >> 2017-06-30 17:21 GMT+02:00 Tobias Boege 
:
> > >>
> > >>>
> > >>> I wouldn't say there is anything *wrong* 
with it, but it also has
> > >>> quadratic
> > >>> worst-case running time. You use 
String[].Push() which is just another
> > >>> name
> > >>> for String[].Add(). Adding an element to an 
array (the straightforward
> > >>> way)
> > >>> is done by extending the space of that array 
by one further element and
> > >>> storing the value there. But extending the 
space of an array could
> > >>> potentially
> > >>> require you to copy the whole array 
somewhere else (where you have
> > enough
> > >>> free memory at the end of the array to 
enlarge it). Doing worst-case
> > >>> analysis,
> > >>> we have to assume that this bad case always 
occurs.
> > >>>
> > >>> If you fill an array with n values, e.g.
> > >>>
> > >>>   Dim a As New Integer[]
> > >>>   For i = 1 To n
> > >>> a.Add(i)
> > >>>   Next
> > >>>
> > >>> then you loop n times and in the i-th 
iteration there will be already
> > >>> i-many elements in your array. Adding one 
further element to it will,
> > >>> in the worst case, require i copy operations 
to be performed.
> > 9-year-old
> > >>> C.F. Gauss will tell you that the amount of 
store operations is about
> > >>> n^2.
> > >>>
> > >>>
> > >> Tobias you are always kind and thank you very 
much.
> > >> Is possible for you to explain this more 
elementarily, for me (a poorly
> > >> educated boy :-) )
> > >>
> > >>
> > >>
> > >>> And your function does two jobs 
simultaneously but only returns the
> > >>> result
> > >>> of one of the jobs. The output you get is 
only worth half the time you
> > >>> spent.
> > >>>
> > >>>
> > >> I did two functions in one, just to save 
space, this is a simple
> > example.
> > >> :-)
> > >>
> > >> Regards
> > >> Gianluigi
> > >>
> > >
> > >
> > 

> > --
> > Check out the vibrant tech community on one of 
the world's most
> > engaging tech sites, Slashdot.org! 
http://sdm.link/slashdot
> > 

Re: [Gambas-user] I need a hint on how to deleted duplicate items in a array

2017-06-27 Thread nando_f
Well, there is complicated, then there is simplicity:
I tested this. Works for sorted, unsorted.
Can't be any simpler.

Public Function RemoveMultiple(a As String[]) As String[]

Dim x as Integer
Dim z as NEW STRING[]

For x = 1 to a.count()
  if z.Find(a) = 0 Then z.Add(a[x])
Next

'if you want it sorted, do it here
Return z

END

' - - - - -
use it this way:

myArray = RemoveMultiple(myArray)
  'the z array is now myArray.
  'the original array is destroyed because there are no references.



--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Gianluigi 
To: mailing list for gambas users 
Sent: Tue, 27 Jun 2017 16:52:48 +0200
Subject: Re: [Gambas-user] I need a hint on how to deleted duplicate items in a 
array

> My two cents.
> 
> Public Sub Main()
> 
>   Dim sSort As String[] = ["A", "B", "B", "B", "C", "D", "D", "E", "E",
> "E", "E", "F"]
>   Dim sSame As String[] = sSort
>   Dim bb As New Byte[]
>   Dim sSingle As New String[]
>   Dim i, n As Integer
> 
>   For i = 0 To sSort.Max
> If i < sSort.Max Then
>   If sSort[i] = sSame[i + 1] Then
> Inc n
>   Else
> sSingle.Push(sSort[i])
> bb.Push(n + 1)
> n = 0
>   Endif
> Endif
>   Next
>   sSingle.Push(sSort[sSort.Max])
>   bb.Push(n + 1)
>   For i = 0 To sSingle.Max
> Print sSingle[i]
>   Next
>   For i = 0 To bb.Max
> Print bb[i] & sSingle[i]
>   Next
> 
> End
> 
> Regards
> Gianluigi
> 
> 2017-06-27 16:33 GMT+02:00 :
> 
> > Another very effective and simple would be:
> >
> > You have your array with data
> > You create a new empty array.
> >
> > Loop through each item in your array with data
> > If it's not in the new array, then add it.
> >
> > Destroy the original array.
> > Keep the new one.
> > ...something like (syntax may not be correct)
> >
> > Public Function RemoveMultiple(a As String[]) As String[]
> >
> >   Dim x as Integer
> >   Dim z as NEW STRING[]
> >
> >   For x = 1 to a.count()
> > if z.Find(a) = 0 Then z.Add(a[x])
> >   Next
> >
> >   Return z
> >
> > END
> >
> > -Nando (Canada)
> >
> >
> >
> >
> > --
> > Open WebMail Project (http://openwebmail.org)
> >
> >
> > -- Original Message ---
> > From: Hans Lehmann 
> > To: gambas-user@lists.sourceforge.net
> > Sent: Tue, 27 Jun 2017 15:51:19 +0200
> > Subject: Re: [Gambas-user] I need a hint on how to deleted duplicate items
> > in a array
> >
> > > Hello,
> > >
> > > look here:
> > >
> > > 8<--
> > -
> > > -- Public Function RemoveMultiple(aStringListe As String[]) As
> > String[]
> > >  Dim iCount As Integer   Dim iIndex As Integer   Dim sElement As String
> > >
> > >iIndex = 0 ' Initialisierung NICHT notwendig
> > >While iIndex < aStringListe.Count
> > >  iCount = 0
> > >  sElement = aStringListe[iIndex]
> > >  While aStringListe.Find(sElement) <> -1
> > >Inc iCount
> > >aStringListe.Remove(aStringListe.Find(sElement))
> > >  Wend
> > >  If iCount Mod 2 = 1 Then
> > > aStringListe.Add(sElement, iIndex)
> > > Inc iIndex
> > >  Endif ' iCount Mod 2 = 1 ?
> > >Wend
> > >
> > >Return aStringListe
> > >
> > > End ' RemoveMultiple(...)
> > > 8<--
> > -
> > > --
> > >
> > > Hans
> > > gambas-buch.de
> > >
> > > 
> > --
> > > Check out the vibrant tech community on one of the world's most
> > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > ___
> > > Gambas-user mailing list
> > > Gambas-user@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > --- End of Original Message ---
> >
> >
> > 
> > --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech 

Re: [Gambas-user] I need a hint on how to deleted duplicate items in a array

2017-06-27 Thread nando_f
Another very effective and simple would be:

You have your array with data
You create a new empty array.

Loop through each item in your array with data
If it's not in the new array, then add it.

Destroy the original array.
Keep the new one.
...something like (syntax may not be correct)

Public Function RemoveMultiple(a As String[]) As String[] 

  Dim x as Integer
  Dim z as NEW STRING[]

  For x = 1 to a.count()
if z.Find(a) = 0 Then z.Add(a[x])
  Next

  Return z

END

-Nando (Canada)




--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Hans Lehmann 
To: gambas-user@lists.sourceforge.net
Sent: Tue, 27 Jun 2017 15:51:19 +0200
Subject: Re: [Gambas-user] I need a hint on how to deleted duplicate items in a 
array

> Hello,
> 
> look here:
> 
> 8<---
> -- Public Function RemoveMultiple(aStringListe As String[]) As 
> String[]  
>  Dim iCount As Integer   Dim iIndex As Integer   Dim sElement As String
> 
>iIndex = 0 ' Initialisierung NICHT notwendig
>While iIndex < aStringListe.Count
>  iCount = 0
>  sElement = aStringListe[iIndex]
>  While aStringListe.Find(sElement) <> -1
>Inc iCount
>aStringListe.Remove(aStringListe.Find(sElement))
>  Wend
>  If iCount Mod 2 = 1 Then
> aStringListe.Add(sElement, iIndex)
> Inc iIndex
>  Endif ' iCount Mod 2 = 1 ?
>Wend
> 
>Return aStringListe
> 
> End ' RemoveMultiple(...)
> 8<---
> --
> 
> Hans
> gambas-buch.de
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] usage of too much GOTO can be bad pracitce or make influence in the code?

2017-06-22 Thread nando_f
Sometimes GOTO is needed...especially if you want your code to run faster.

Used properly and judiciously, it can make code reading much easier.

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Cristiano Guadagnino 
To: mailing list for gambas users 
Sent: Thu, 22 Jun 2017 16:24:02 +0200
Subject: Re: [Gambas-user] usage of too much GOTO can be bad pracitce or make 
influence in
the code?

> Based on your example, I would not find the code using GOTO any more
> readable. Quite to the contrary, instead.
> And I don't understand why you cannot use a sub. What's the problem with
> variables that cannot be solved by passing the needed variables or using
> globals?
> 
> Anyway, coding style is a matter of taste, so go with what you prefer.
> Unless the code needs to be read/perused by others, obviously.
> 
> Cris
> 
> On Thu, Jun 22, 2017 at 4:10 PM, PICCORO McKAY Lenz 
> wrote:
> 
> > 2017-06-22 10:00 GMT-04:00 Jussi Lahtinen :
> >
> > > Usually the problem with goto is that it can render the code hard to
> > debug
> > > or read.
> > >
> > AH OK, so in large complex dependences must be avoid..
> >
> > i only use to avoid a similar to this:
> >
> > if isnull(value ) then
> >' amount of 4000 lines of code
> >
> > else
> >' amount of other lot of lines
> > endif
> >
> > so i put
> >
> > if not isnull()
> >   goto codepiecelabel1
> > endif
> >   ' amount of lines
> >
> > codepiecelabel1:
> > ' here the 4000 lines
> >
> >
> > i cannot use a sub procedures due manage some variables
> >
> >
> > >
> > >
> > > Jussi
> > >
> > > On Thu, Jun 22, 2017 at 4:21 PM, PICCORO McKAY Lenz <
> > > mckaygerh...@gmail.com>
> > > wrote:
> > >
> > > > i have some GOTO to avoit large IF-ELSE code blocks and make readable
> > the
> > > > code..
> > > >
> > > > the usage of many GOTO instructions can be bad pracitce or make
> > influence
> > > > in the code?
> > > >
> > > > i remenber that in BASIC always tell me "dont use too much"
> > > >
> > > > of course GAMBAS IS NOT BASIC (umm that sound familiarr... ;-)
> > > >
> > > >
> > > > Lenz McKAY Gerardo (PICCORO)
> > > > http://qgqlochekone.blogspot.com
> > > > 
> > > > --
> > > > Check out the vibrant tech community on one of the world's most
> > > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > > ___
> > > > Gambas-user mailing list
> > > > Gambas-user@lists.sourceforge.net
> > > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > >
> > > 
> > > --
> > > Check out the vibrant tech community on one of the world's most
> > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > ___
> > > Gambas-user mailing list
> > > Gambas-user@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> > 
> > --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread nando_f
My reply to the comment:

> Gambas Strings are not null-terminated and can
> contain any sequence of bytes, which includes non-printable characters
> (which I think is what you meant by "unreadable" characters).

You should always consider String as an array of bytes.
Just because humans can't read them or because they cannot be displayed,
means nothing to the computer.  It only means something to the human.

While the computer is processing and doing work, we don't need to see it.

I use string exclusively for binary data...especially serial port stuff.
Strings are far easier than a byte array.

If you insist on using a byte array, consider a large fixed-size array.
For example: b[1].
Resizing a dynamic array every time is cpu work.

-Fernando


--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Mike Crean 
To: mailing list for gambas users 
Sent: Mon, 15 May 2017 10:46:01 + (UTC)
Subject: Re: [Gambas-user] Serial I/O with byte data

> If you are talking about a byte the likes of that used in modbusrtu you will 
> need to do some high low bit manipulation on it. RegardsMike
> 
> On Monday, 15 May 2017, 13:19, Alexie  wrote:
> 
>  Following should work for you:
> 
> Public Sub XXX_Read()
> 
>   Dim iLen As Integer
>   Dim aData As Byte[]
> 
>   iLen = Lof(Last)
>   aData = New Byte[]
>   aData.Resize(iLen)
>   Try aData.Read(Last, 0, iLen)
> 
> End
> 
> You need to get the length (lof) first, then resize array ... only then you
> can read it.
> 
> 2017-05-14 21:56 GMT+02:00 Tobias Boege :
> 
> > On Sun, 14 May 2017, alexchernoff wrote:
> > > Good day all,
> > >
> > > Anyone know how to read data received on serial port into an array of
> > bytes
> > > instead of string?
> > >
> >
> > I think that's not possible.
> >
> > > String gets unreadable binary characters, so how can I
> > > put them into byte[] or so?
> > >
> >
> > This shouldn't be a problem. Gambas Strings are not null-terminated and can
> > contain any sequence of bytes, which includes non-printable characters
> > (which
> > I think is what you meant by "unreadable" characters).
> >
> > If you insist on a Byte[], read it into a String and use
> > Byte[].FromString(),
> > but there is no way to go around the String, AFAICT (and that is because
> > there is no need to, as Strings can handle binary data just fine).
> >
> > Regards,
> > Tobi
> >
> > --
> > "There's an old saying: Don't change anything... ever!" -- Mr. Monk
> >
> > 
> > --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-09 Thread nando_f
I have used Gambas serial port for 12 years now without problems.

If there is nothing in the serial port queue, then that line might block.

I use this:

. . .
L=Lof(Sport) 'how much is there now?
if L>1 then L=L-1'leave at least one byte for next time around.
if L>0 then Read #Sport, Rx, L   'get all less one byte
Rx_all = Rx_all + Rx 'combine this piece into the whole receive 
string.
Rx=""'just in case it loops around, don't re-read 
Rx.
. . .


Most importantly, please do not think that just one READ will
retrieve a whole line or chunk of data from your serial port.
It will get only part of it because your computer reads bytes much faster
and empties the receiver buffer much faster than data send over RS232.

-Fernando

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: alexchernoff 
To: gambas-user@lists.sourceforge.net
Sent: Mon, 8 May 2017 22:45:11 -0700 (MST)
Subject: Re: [Gambas-user] Serial I/O with byte data

> Thanks Mike,
> 
> what I have is pretty much the same, it's this line that causes everything
> to stop.
> 
> *Read #Sport, Rx, Lof(Sport) *
> 
> A very similar program written in Xojo on the same system using same serial
> port works just fine. In Gambas, things just stop executing as soon as I do
> a Read on that port...
> 
> --
> View this message in context: 
> http://gambas.8142.n7.nabble.com/Serial-I-O-with-
> byte-data-tp58933p58939.html Sent from the gambas-user mailing list archive 
> at Nabble.com.
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Arrays of Structs

2016-11-29 Thread nando_f
I use structs to write binary to a file in struct order.
Nice and easy.
Not so easy with a class.

Your example is possible.  I have done similar.

The STRUCT only defines the structure...it doesn't create the memory allocation.
Static Private WorldMap[100, 100] As MapObject  just defines arrays to point to 
objects.
You need to run code to actually create new objects at each array element.
hint:
Loop  x
 Loop  y
   [x][y] = new MapObject  'the new actually creates a memory allocation for it.

-Fernando

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Tony Morehen 
To: gambas-user@lists.sourceforge.net
Sent: Tue, 29 Nov 2016 15:29:03 -0500
Subject: Re: [Gambas-user] Arrays of Structs

> I may just be responding to a typo but your struct is named MapObjec 
> while the code using it refers to MapObject.
> 
> On 28/11/16 10:40 PM, Cam Era wrote:
> > I expect I'm trying to do something that's not possible with Gambas, but
> > I'll ask this anyway.
> >
> > I'm trying to create an n x n array of a STRUCT which itself contains an
> > array of type STRUCT.
> >
> > I have this declaration:
> >
> >  Public Struct MapObjec
> >xPos As Integer
> >yPos As Integer
> >ObjectType As Integer
> >isVisible As Boolean
> >ObjectPicture As Picture
> >  End Struct
> >
> >  Public Struct MapRoom
> >MapObjects[50] As MapObject
> >  End Struct
> >
> >  Static Private WorldMap[100, 100] As MapObject
> >
> >
> > and this code:
> >
> >  WorldMap[5, 10].MapObjects.yPos = 100
> >
> >
> > which generates a "NULL object" error.
> >
> > Any pointers as to whether this is possible and if so, how?
> >
> >
> > Cheers
> >
> > -- Cam
> > --
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> --
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial Port issues and events.

2016-06-30 Thread nando_f
I've done extensive work with the serial port for a dozen years
with 100% success 24 hour operation.

Sometimes people get mixed up with "0x02" thinking it's binary.
That is 4 characters ascii.
I prefer to use chr(2) to create a 1 length string binary 2.
If you're going to use byte[] array
then byte[0] = 2 is the equivalent.
Using escape (like HTML encoding) is the incorrect thinking
-Fernando

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: ML 
To: gambas-user@lists.sourceforge.net
Sent: Thu, 30 Jun 2016 10:51:41 -0300
Subject: Re: [Gambas-user] Serial Port issues and events.

> Alexie,
> 
> Not really. This is my first attempt at a binary-exchange over serial in
> Gambas. Can't also find out the old G3 examples that might have existed
> about this and my web searches were unsuccessful.
> So, if you could point me to some example code to read a Byte[], I'll be
> grateful. My attempts to read to a Byte[] failed with SEGFAULT, or
> errors with no text.
> 
> On the other hand, I just realized -again, happened to me in the past
> and I forgot it did- that the list does not send text inside RAW tags...
> The code can be seen only on Nabble's site, so I'm reinserting it here.
> Please excuse my notation; I know it's not Gambas standard. It's what I
> used for eons on QB45, VB3, VB4, VB5 VB6 and even .Net for my day to day
> work; (really) old habits die hard.
> 
> Declarations:
> 
>   Private Const TEST_TX As String = "ø1" '0x02-0xF8-0x31-0x03 -
> Nabble's RAW TEXT tags removed some data from the string
>   Private Const TEST_RX As String = "" '0x02-0x15-0x03 - Nabble's RAW
> TEXT tags removed some data from the string
>   Private m_tty As SerialPort
>   Private m_rxBuff As String = Null
> 
> Instancing and setting the port up:
> 
> 'Instance serial port and set properties
> m_tty = New SerialPort As "myTty"  'This should call myTty_Read()
> when there is data to read from the port, but it does not seem to
> trigger. Wonder why.
> m_tty.PortName = "/dev/" & m_port
> m_tty.Speed = m_speed
> Select Case m_parity
>   Case "No/Space"
> m_tty.Parity = SerialPort.None
>   Case "Even"
> m_tty.Parity = SerialPort.Even
>   Case "Odd"
> m_tty.Parity = SerialPort.Odd
> End Select
> m_tty.DataBits = m_bits
> m_tty.StopBits = m_stop
> 
> 'Encoder use hardware handshake (RTS/CTS)
> m_tty.FlowControl = SerialPort.Hardware
> 
> 'Try opening the port
> m_tty.Open()
> m_tty.Blocking = False
> m_tty.DTR = True
> 
> Then, I send TEST_TX and expect for either TEST_RX or a timeout:
> 
>   Public Function Test() As Boolean
> 
> Dim tOut As Date = DateAdd(Now, gb.Second, 2)
> 
> 'Reset RX Buffer, send test command and check for timeout/response
> m_tty.Drop  'Kill remaining send data
> m_tty.Begin()   'Start buffering
> Write #m_tty, TEST_TX   'Add to send buffer
> m_rxBuff = Null 'Kill RX buffer
> m_tty.Send()'Send buffer
> 
> While (Now < tOut) And (m_rxBuff <> TEST_RX)
>   Sleep 0.1
>   'This IF below should not be needed, but myTty_Read() never fires
> otherwise!
>   If m_tty.InputBufferSize > 0 Then
> myTty_Read()
>   Endif
> Wend
> 
> Finally
>   Return (m_rxBuff = TEST_RX)
> 
> Catch
>   Message.Error("Error '" & Error.Text & "' occurred in " & Error.Where)
> 
>   End
> 
> Finally, this next is the problem code. It does not fire as expected
> when data arrives, and when I call it by hand in the IF above, if I try
> to READ #m_tty As String it chops off the leading 0x02 byte, and I could
> not figure out how to READ #m_tty As Byte[] or As Object (I get a null
> error; nothing on the message.error text, and no OK button on it either):
> 
>   Public Sub myTty_Read()
> 
> Dim dLen As Integer = m_tty.InputBufferSize
> Dim sgmnt As Byte[] 'String = Null  'This here is my desperate
> attempt to read As String or As Object...
> 
> 'Data should be available in the serial port buffer
> 'sgmnt = Read #m_tty As String
> 'm_rxBuff &= sgmnt
> sgmnt = Read #m_tty As Object
> m_rxBuff &= sgmnt.ToString
> Debug "Rx: (" & CStr(dLen) & ") " & sgmnt
> 
> Catch
>   'This is triggered when reading As Object or As Byte[]. But the
> text is NULL and has no OK button!
>   Message.Error("Error '" & Error.Text & "' occurred in " & Error.Where)
> 
>   End
> 
> A breakpoint in the "sgmnt = Read #m_tty As ..." line show that the
> value of "dLen" is three, which is OK. But when I try to READ As String,
> the leading 0x02 is missing from the string, leaving only 0x15-0x03
> (quick tooltip shows the string to be "\x15\x03"). When this is later
> compared to TEST_RX in Test(), the comparison obviously fails.
> 
> TIA,
> zxMarce.
> 
> --
> Attend Shape: An AT Tech