transfer a table to another form

Post

Posted
Rating:
#1 (In Topic #1412)
Trainee
Good morning
I create a table in a form, then I would like to display this table in another form to display it in a gridview

Whether I declare my variables Public or not in the first form doesn't change anything…?

Is there a method for making a table visible to multiple forms?  Thanks :D
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 If it is "Public" it should be visible from any other class.

Post your code so we can see the problem.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Your question is a little vague, but have a look at the attached program that puts the same data on 2 Forms.

<IMG src="https://www.cogier.com/gambas/TwoForms.png"> </IMG>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#4
Trainee

BruceSteers said

If it is "Public" it should be visible from any other class.

Post your code so we can see the problem.

Public tableau As String[]

Public Sub Button2_Click()

'tableau = New String[25, 7]
  Dim i As Integer
   gridform.Show
    i = 1
  index = 1
 tableau[1.i] = index
 tableau[1, i + 1] = PRA
 tableau[1, i + 2] = Marge
 tableau[1, i + 3] = montva
 tableau[1, i + 4] = result

End
( Fmain.class)

Public Sub GridView1_Data(Row As Integer, Column As Integer)

    GridView1.Data.Text = tableau[Row, column]

End
( Gridform.class )

Error component gb.complex not found !!!
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee

lucien91 said

Good morning
I create a table in a form, then I would like to display this table in another form to display it in a gridview

Whether I declare my variables Public or not in the first form doesn't change anything…?

Is there a method for making a table visible to multiple forms?  Thanks :D

answer DeepSeek !:

' Déclaration des variables globales pour stocker les données
Dim hData As Collection

Public Sub Form_Open()

  ' Initialiser la collection pour stocker les données
  hData = New Collection

  ' Créer les champs de saisie
  Dim hLabelNom As Label
  Dim hTextBoxNom As TextBox
  Dim hLabelPA As Label
  Dim hTextBoxPA As TextBox
  Dim hLabelMarge As Label
  Dim hTextBoxMarge As TextBox
  Dim hLabelPTTC As Label
  Dim hTextBoxPTTC As TextBox
  Dim hButtonAdd As Button
  Dim hGridView As GridView

  ' Positionner les éléments sur le formulaire
  hLabelNom = New Label(Me) As "LabelNom"
  hLabelNom.Text = "Nom :"
  hLabelNom.X = 20
  hLabelNom.Y = 20

  hTextBoxNom = New TextBox(Me) As "TextBoxNom"
  hTextBoxNom.X = 100
  hTextBoxNom.Y = 20
  hTextBoxNom.Width = 150

  hLabelPA = New Label(Me) As "LabelPA"
  hLabelPA.Text = "PA :"
  hLabelPA.X = 20
  hLabelPA.Y = 60

  hTextBoxPA = New TextBox(Me) As "TextBoxPA"
  hTextBoxPA.X = 100
  hTextBoxPA.Y = 60
  hTextBoxPA.Width = 150

  hLabelMarge = New Label(Me) As "LabelMarge"
  hLabelMarge.Text = "Marge :"
  hLabelMarge.X = 20
  hLabelMarge.Y = 100

  hTextBoxMarge = New TextBox(Me) As "TextBoxMarge"
  hTextBoxMarge.X = 100
  hTextBoxMarge.Y = 100
  hTextBoxMarge.Width = 150

  hLabelPTTC = New Label(Me) As "LabelPTTC"
  hLabelPTTC.Text = "pTTC :"
  hLabelPTTC.X = 20
  hLabelPTTC.Y = 140

  hTextBoxPTTC = New TextBox(Me) As "TextBoxPTTC"
  hTextBoxPTTC.X = 100
  hTextBoxPTTC.Y = 140
  hTextBoxPTTC.Width = 150

  ' Bouton pour ajouter les données
  hButtonAdd = New Button(Me) As "ButtonAdd"
  hButtonAdd.Text = "Ajouter"
  hButtonAdd.X = 100
  hButtonAdd.Y = 180
  hButtonAdd.Width = 100

  ' GridView pour afficher les données
  hGridView = New GridView(Me) As "GridView"
  hGridView.X = 20
  hGridView.Y = 220
  hGridView.Width = 300
  hGridView.Height = 150
  hGridView.Columns.Count = 4
  hGridView.Columns[0].Text = "Nom"
  hGridView.Columns[1].Text = "PA"
  hGridView.Columns[2].Text = "Marge"
  hGridView.Columns[3].Text = "pTTC"

End

' Gestionnaire d'événement pour le bouton "Ajouter"
Public Sub ButtonAdd_Click()

  ' Récupérer les valeurs saisies
  Dim sNom As String = TextBoxNom.Text
  Dim fPA As Float = Val(TextBoxPA.Text)
  Dim fMarge As Float = Val(TextBoxMarge.Text)
  Dim fPTTC As Float = Val(TextBoxPTTC.Text)

  ' Ajouter les données à la collection
  hData.Add([sNom, fPA, fMarge, fPTTC])

  ' Ajouter une nouvelle ligne au GridView
  Dim hRow As Row = hGridView.Rows.Add()
  hRow[0] = sNom
  hRow[1] = Str(fPA)
  hRow[2] = Str(fMarge)
  hRow[3] = Str(fPTTC)

  ' Effacer les champs de saisie
  TextBoxNom.Text = ""
  TextBoxPA.Text = ""
  TextBoxMarge.Text = ""
  TextBoxPTTC.Text = ""

End
Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
 from now on only this instruction gives me problems:


Dim hRow As Row = hGridView.Rows.Add()
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
Read the wiki and learn gambas instead of using AI to write code you do not understand ;)

/ - Gambas Documentation
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Expert
Poly is in the usergroup ‘Expert’
OK, that's really not the nicest answer.
But I didn't really understand the problem either.
If it's just a matter of displaying the values of a table created in one form in another form, then I've made a very simple example.
There are two forms here.
In the main form, a TableView was created using code and only two rows were filled with meaningless data.
In the other form, a table field of this table is now simply read out in a text field.
I hope this makes it clear what you need to do in your example.

Less is sometimes more.
It is important to declare the TableView as Public before all other subs.
And then this TableView is addressed by the other data by prefixing the form in which it is created.
For example, FMain.tv1 is the tv1 TableView of FMain that is to be addressed.  

Disroot Cloud
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Expert
Poly is in the usergroup ‘Expert’
In general, the Gambas Wiki is of course the first place where you will find good explanations.
But this source is highly recommended, especially for Grid and TableViews.

Programming Gambas from Zip/Printable version - Wikibooks, open books for an open world
Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘Guru’

Poly said

OK, that's really not the nicest answer.

:lol:

Alas yes,
 Although I do not mean to sound like a cynical old git it is generally what I am so it always comes out like that  :roll:
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’
maybe i see the problem.

to access the tableau that is in Fmain.class from Gridform.class you should do this…

Code (gambas)

  1. Public Sub GridView1_Data(Row As Integer, Column As Integer)
  2.  
  3. GridView1.Data.Text = Fmain.tableau[Row, column]  ' read tableau from Fmain.class
  4.  
  5. ' ( Gridform.class )
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#12
Trainee

Poly said

OK, that's really not the nicest answer.
But I didn't really understand the problem either.
If it's just a matter of displaying the values of a table created in one form in another form, then I've made a very simple example.


Disroot Cloud

Hello, not everyone is kind.
The Wiki is quite poorly done and very confusing for a beginner.
I am well aware that I look like a loser…

and the compressed archive is empty. thank you for your help
Online now: No Back to the top

Post

Posted
Rating:
#13
Trainee

BruceSteers said

Read the wiki and learn gambas instead of using AI to write code you do not understand ;)

/ - Gambas Documentation

Sorry but the WIKI is neither simple nor user-friendly, excuse me for being an idiot, but at 65 my understanding is limited
using the AI ​​was not a good idea, but it does not exist, to my knowledge of "Gambas for dummies"
Online now: No Back to the top

Post

Posted
Rating:
#14
Guru
BruceSteers is in the usergroup ‘Guru’

lucien91 said

BruceSteers said

Read the wiki and learn gambas instead of using AI to write code you do not understand ;)

/ - Gambas Documentation

Sorry but the WIKI is neither simple nor user-friendly, excuse me for being an idiot, but at 65 my understanding is limited
using the AI ​​was not a good idea, but it does not exist, to my knowledge of "Gambas for dummies"

Well the wiki is how i learned the gambas basics. (and I'm 53)
The wiki is a reference manual though, not a step by step guide to programming.

Sorry if you and Poly considered my sarcasm unkind.
I did not expect a gen-z modern sensitivity reaction to a little AI mockery.  I mock the AI code not you personally. please do not feel like a victim.

Ps. there is much reading material out there.
/tutorial - Gambas Documentation
/doc/book - Gambas Documentation

https://www.amazon.co.uk/Beginners-Guide-Gambas-Revised-Rittinghouse-ebook/dp/B006C75I66

Asking AI is like asking someone who knows very little but thinks they know everything and will confidently give you many wrong answers.
Online now: No Back to the top

Post

Posted
Rating:
#15
Avatar
Expert
Poly is in the usergroup ‘Expert’

lucien91 said


thank you for your help


Hello, first of all I would like to tell you that I am an absolute beginner myself and not an IT specialist. So there are no questions that are too simple or trivial.

I don't know what your ambitions are. Whether you only need help for a specific project or are really interested in learning Gambas.

If it's the latter, then I'd be happy to help you.
On the one hand with the tips as I have learnt them, because there is so much documentation.

The wiki explains everything, but since not every thing is presented with a useful example, it can sometimes be a bit frustrating.
That's why a forum like this is the best source.

I can also recommend the Greek book Gambas3.
It really explains everything. Of course, it is daunting to read a book in a language where you may not even know the characters. But with the help of the automatic translations it works really well.
I have translated it completely into German for myself and worked through all the examples.
Maybe give it a try.

https://github.com/demosthenesk/the_gambas3_book

lucien91 said


and the compressed archive is empty.


I have just tried it out again. It's not empty. However, it only contains hidden files and folders. So you have to set up your system so that hidden files are also displayed.
Or better. You unzip the folder and then select this unzipped folder with the Gambas IDE.
However, this is really just a very trivial example to show you how to use two different forms and their controls.

And finally, a word about Bruce.
I didn't understand the sarcasm in his words either, but forgive him, he's English. They're known to have a funny sense of humour.
But all I can really say is. He's an absolute crack and has always patiently explained everything to me in the German forum.
And I see that he has already solved your problem.

Have fun with Gambas :)
Online now: No Back to the top

Post

Posted
Rating:
#16
Guru
BruceSteers is in the usergroup ‘Guru’
With your DeepSeek code the GridView and everything else is set up in Form_Open() using Dim instructions.
That makes them all local to the Form_Open() method and not global to access from other forms.

To access Controls like the GridView from another form it must be a global public definition.

More like this..

Code (gambas)

  1.  
  2. Public hGridView As GridView
  3.  
  4. Public Sub Form_Open()
  5.  
  6. ' Dim  hGridView As GridView  ' DO NOT USE THIS LINE
  7.  
  8. ' you can now use the Public hGridView and it will be accessible from other forms.
  9. ' GridView pour afficher les données
  10. hGridView = New GridView(Me) As "GridView"
  11.  
  12.  
  13.  


This code is very wrong.

Code (gambas)

  1. ' Ajouter une nouvelle ligne au GridView
  2. Dim hRow As Row = hGridView.Rows.Add()
  3. hRow[0] = sNom
  4. hRow[1] = Str(fPA)
  5. hRow[2] = Str(fMarge)
  6. hRow[3] = Str(fPTTC)
  7.  

It should be more like this…

Code (gambas)

  1. ' Ajouter une nouvelle ligne au GridView
  2.  
  3. Inc hGridView.Rows.Count ' this adds a new row
  4. hRow = hGridView.Rows.Max  ' .Max is the last index
  5.  
  6. hGridView[hRow,0].Text = sNom
  7. hGridView[hRow,1].Text = Str(fPA)
  8. hGridView[hRow,2].Text = Str(fMarge)
  9. hGridView[[hRow.3].Text = Str(fPTTC)
  10.  

By the way if you use the above method to fill the GridView rows you cannot use the GridView_Data(Row As Integer, Column As Integer) event.

A GridView is "either" filled manually like above or filled using the Data() event.

and Poly is pretty spot on about me there. (thanks Poly)
I really mean no harm and was only joking because i do not really like AI and the confusing code it produces. it is confusing for you and sometimes even for us.

I have learned all i know through my own coding experiences and much much much use of the wiki.
AI's are still in the position of learning and most are not yet very good teachers.

I am also happy and very able to help others (that's why i'm here)
But enough about me, lets get back on the topic of your gambas coding issues.

Hopefully we can still help
Online now: No Back to the top

Post

Posted
Rating:
#17
Trainee

BruceSteers said

I have learned all i know through my own coding experiences and much much much use of the wiki.
AI's are still in the position of learning and most are not yet very good teachers.

I am also happy and very able to help others (that's why i'm here)
But enough about me, lets get back on the topic of your gambas coding issues.

Hopefully we can still help

thank you, admit that it's frustrating for a French person to be forced to translate forums and texts when gambas was invented by a French person!
So I find myself reading videos in German or Spanish to hope to move forward.

I admit that I have difficulty understanding when a procedure is public or private, and I often mix the two
I had done a bit of Qbasic and visual basic programming 20 years ago, and I lost a lot, getting back into it is a long way of the cross
don't worry, I don't blame you at all, thank you for your help :D
Online now: No Back to the top

Post

Posted
Rating:
#18
Trainee
 code complet:

' Gambas class file

'Public hGridView As GridView
Public PRA As Float
Public TVA As Float
Public TMA As Float
Public Marge As Float
Public idex As Integer
Public result As Float
Public montva As Float
Public tableau As String[]
Public sNom As String

Public Sub Form_Open()
hGridView = New GridView(Me) As "GridView"
hGridView.Columns.Count = 4
hGridView.Rows.Count = 5
Me.center
Label2.text = ("Entrer le prix d'achat HT")
  ComboBox1.Add(" TVA 5.5", 0)
  ComboBox1.Add(" TVA 10", 1)
  ComboBox1.Add(" TVA 20", 2)
  ComboBox1.Add(" Pas de TVA", 3)
End



Public Sub ComboBox1_Click()
If ComboBox1.text = " TVA 5.5" Then TVA = 5.5  
If ComboBox1.text = " TVA 10" Then TVA = 10
If ComboBox1.text = " TVA 20" Then TVA = 20
If ComboBox1.text = " Pas de TVA" Then TVA = 0
'Else TVA = 0
'End If
Label1.text = " Tva :" & TVA & " %"
End

Public Sub Button1_Click()
TextArea1.clear

PRA = ValueBox1.value
TMA = ValueBox2.value
Marge = (PRA * (TMA / 100))
montva = ((PRA + marge) * (TVA / 100))
result = PRA + Marge + montva

  TextArea1.Text = PRA & Chr$(10) & "T Marge:" & TMA & "%" & Chr$(10) & " Marge= " & Marge & Chr$(10) & Label1.text & Chr$(10) & " TVA = " & montva & Chr$(10) & result & " TTC " & Chr$(10)
  Wait 0.5
 
End

Public Sub Button2_Click()
' Ajouter une nouvelle ligne au GridView
Dim hRow As Integer
 
Inc hGridView.Rows.Count ' this adds a new row
hRow = hGridView.Rows.Max  ' .Max is the last index
 
hGridView[hRow, 0].Text = sNom
hGridView[hRow, 1].Text = Str(PRA)
hGridView[hRow, 2].Text = Str(Marge)
hGridView[hRow, 3].Text = Str(result)
End

Public Sub hGridView_Click()

  

End

 
Public Sub GridView1_Data(Row As Integer, Column As Integer)
 
hGridView.Data.Text = Fmain.tableau[Row, column]  ' read tableau from Fmain.class
 
End
Everything seems to be working but my gridview is not displaying data
Sorry…
Online now: No Back to the top

Post

Posted
Rating:
#19
Guru
BruceSteers is in the usergroup ‘Guru’
 What data are you expecting it to display?

it looks like you are using tableau

but it looks like you did not fill tableau
Online now: No Back to the top

Post

Posted
Rating:
#20
Guru
BruceSteers is in the usergroup ‘Guru’
 Ps.
In the IDE you can goto "Project / Make project archive" menu and that will make an archive of the source code like what you have downloaded from others here.

we can then look at the whole project and better see your problems.
you will not have to explain so much and will not have to post lots of code that can be hard to put in context.

otherwise we have to try to guess what you are doing from your translated explanations.
It is easiest for everyone of you can post the whole project.
Online now: No Back to the top

Post

Posted
Rating:
#21
Avatar
Administrator
sholzy is in the usergroup ‘unknown’

lucien91 said

BruceSteers said

Read the wiki and learn gambas instead of using AI to write code you do not understand ;)

/ - Gambas Documentation

Sorry but the WIKI is neither simple nor user-friendly, excuse me for being an idiot, but at 65 my understanding is limited
using the AI ​​was not a good idea, but it does not exist, to my knowledge of "Gambas for dummies"

Don't feel bad. I've been using Gambas for about 20 years and the WIKI still gives me fits, so I do a lot of Googling looking for examples. At 63, I don't learn as easy anymore by reading a description so seeing examples of how something is used helps me understand to be able to use it in the project I'm working on.

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#22
Trainee

Got2BeFree said

Don't feel bad. I've been using Gambas for about 20 years and the WIKI still gives me fits, so I do a lot of Googling looking for examples. At 63, I don't learn as easy anymore by reading a description so seeing examples of how something is used helps me understand to be able to use it in the project I'm working on.

thank you, I feel less alone now.
it's true that with age, knowledge becomes less well…
Online now: No Back to the top

Post

Posted
Rating:
#23
Trainee

BruceSteers said

What data are you expecting it to display?

it looks like you are using tableau

but it looks like you did not fill tableau

' Ajouter une nouvelle ligne au GridView
Dim hRow As Integer
 
Inc hGridView.Rows.Count ' this adds a new row
hRow = hGridView.Rows.Max  ' .Max is the last index
 
hGridView[hRow,0].Text = sNom
hGridView[hRow,1].Text = Str(fPA)
hGridView[hRow,2].Text = Str(fMarge)
hGridView[[hRow.3].Text = Str(fPTTC)

this procedure does not enter the data into the table?
I don't understand anymore
Online now: No Back to the top

Post

Posted
Rating:
#24
Trainee

Poly said

https://github.com/demosthenesk/the_gambas3_book

lucien91 said


and the compressed archive is empty.



thank you, thanks to you I found many examples in this book.
for the rest google translate will do the rest…
Online now: No Back to the top

Post

Posted
Rating:
#25
Guru
BruceSteers is in the usergroup ‘Guru’

lucien91 said

this procedure does not enter the data into the table?
I don't understand anymore

probably because you have ALSO used the GridView1_Data() event.

as i explained, you cannot do that.
It's one way or the other

Remove the GridView1_Data() event
Online now: No Back to the top
1 guest and 0 members have just viewed this.