[Gambas-user] File opening dialog and one more question

Dmitrij Malkov dima.malkov.russia at ...626...
Sat Jan 7 05:48:11 CET 2012



Now I have modified the code. In CUnits:
-------------------------------------------------------
' Gambas class file

Static Private NumberOfUnits As Integer = 0
Static Private CountOfCreations As Integer = 0
Private Id As Integer 'Identity number

'constructor
Public Sub _new()
  NumberOfUnits += 1
  CountOfCreations += 1
  MakeIdentification()
  'Print "New Unit was created"
End

Static Public Sub HowManyUnits()
  Print "There are "; NumberOfUnits; " objects of class 'CUnit'"
End

Private Sub MakeIdentification()
  Id = CountOfCreations
End

Public Sub PrintIdentification()
  Print "Identity number of the object is "; Id
End
-------------------------------------------------------


In MMain:
-------------------------------------------------------
' Gambas module file

Public Sub Main()
  Dim Unit1, Unit2, Unit3, Unit4 As CUnit 
  Dim i As Integer 'counter
  Dim aUnit As New CUnit[5] 'Array
  
  CUnit.HowManyUnits()
  Unit1 = New CUnit
  Unit2 = New CUnit
  CUnit.HowManyUnits()
  Unit3 = New CUnit
  Unit4 = New CUnit
  CUnit.HowManyUnits()

  'creation in a cycle
  For i = 1 To 100
    SubForCycleCreation()
  Next
  CUnit.HowManyUnits()
  
  'creation to an array
  For i = 0 To 4
    aUnit[i] = New CUnit
  Next
  CUnit.HowManyUnits()
  
  aUnit[0].PrintIdentification()
End

Public Sub SubForCycleCreation()
  Dim Unit5 As CUnit 
  Unit5 = New CUnit
End
-------------------------------------------------------


The output is:
-------------------------------------------------------
There are 0 objects of class 'CUnit'
There are 2 objects of class 'CUnit'
There are 4 objects of class 'CUnit'
There are 104 objects of class 'CUnit'
There are 109 objects of class 'CUnit'
Identity number of the object is 105
-------------------------------------------------------


Why I can't the line "Dim aUnit As New CUnit[5] 'Array" in MMain write
without "NEW"? In the documentation in Array declarations: "DIM Identifier
AS [ NEW ] Datatype [ Array dimensions ... ]" . So, "NEW" is optional here,
but I have a mistake without It.

What interesting tricks we can add to this program? This program could be a
sample. :-)

When I write in MMain "Unit1." an autocomlection window rises with a help
window. My functions in the help window are naked. Maybe it will be nice to
see in a help window first comment lines above my functions. :-)

'--doc--
'comments for
'documenting subs
PUBLIC SUB DocunebtedSub()
END
-- 
View this message in context: http://old.nabble.com/File-opening-dialog-and-one-more-question-tp33085420p33097176.html
Sent from the gambas-user mailing list archive at Nabble.com.





More information about the User mailing list