$include "include\rapidq2.inc"
$typecheck on
DECLARE SUB cherche_click (Sender AS QBUTTON)
declare sub enreg_grille2 (sender as qmenuitem)
declare sub efface_grille2
CREATE Form AS QFORM
Caption = "Chercheur"
Width = 494
' Borderstyle = -4
Height = 433
Center
CREATE grille1 AS QSTRINGGRID ' listing
Left = 8
Top = 8
Height = 192
Width = 472
Hint = "grille1"
Separator = ";"
addoptions (goediting) ' pour pouvoir copier un nom, une reférence ...
FixedCols = 0
DefaultColWidth = 74
DefaultRowHeight = 16
Colcount = 3
Rowcount = 2
align = 1
END CREATE
CREATE Panel1 AS QPANEL
Left = 8
Top = 208
Width = 473
align = 1
Height = 65
TabOrder = 2
CREATE Label1 AS QLABEL
Caption = "Chercher :"
Left = 8
Top = 16
Width = 49
Transparent = 1
END CREATE
CREATE Label2 AS QLABEL
Caption = "Dans :"
Left = 8
Top = 40
Width = 31
Transparent = 1
END CREATE
CREATE Edit1 AS QEDIT
Left = 64
Top = 8
Width = 225
END CREATE
CREATE ComboBox1 AS QCOMBOBOX
Left = 64
Top = 32
Width = 225
style=3 '--- Pas d'entrée manuelle
TabOrder = 1
END CREATE
CREATE Btn_cherch AS QBUTTON
Caption = "Chercher"
Left = 336
Top = 8
Width = 131
Height = 49
TabOrder = 2
OnClick = cherche_click
END CREATE
END CREATE
CREATE grille2 AS QSTRINGGRID ' résultat de la recherche
Left = 8
Top = 280
Width = 472
Hint = "grille2"
TabOrder = 1
separator = ";"
FixedCols = 0
DefaultColWidth = 74
DefaultRowHeight = 16
align = 5 '--- A revoir...
create menu as qpopupmenu
create mnu_enreg as qmenuitem
caption = "Enregistrer la recherche"
onclick = enreg_grille2
end create
end create
END CREATE
create statusbar as qstatusbar
simpletext = true
end create
END CREATE
'--- Charger la grille des données
grille1.loadfromfile("fichier.csv",0,0,9999)
'--- Effacer le combobox
dim I as integer
for I = 0 to grille1.colcount-1
combobox1.additems grille1.cell(I,0)
next
combobox1.itemindex=0
'--- Afficher la fenêtre principale
setfocus(Btn_cherch)
Form.ShowModal
'--------- Subroutines ---------
SUB cherche_click (Sender AS QBUTTON)
dim nbre as integer : nbre = 0 '--- Variable pour le nombre de ligne trouvée
call efface_grille2 '--- Appel de la fonction d'éffacement de la grille2 a chaque nouvelle recherche.
dim lign_cherche as integer, colo_cherche as integer '--- Variables pour la boucle de recherche
dim colo as integer, lign as integer '--- Variables pour la boucle d'envoi des donnée dans grille2
'--- Afficher un message d'information
showmessage "a chercher " & chr$(34) & edit1.text & chr$(34) & "dans la colonne "& chr$(34) & combobox1.text
'--- La boucle de recherche
for lign_cherche = 1 to grille1.rowcount-1
if ucase$(grille1.cell(combobox1.itemindex,lign_cherche)) = ucase$(edit1.text) then
'--- Vérifier qu'il y ait plus de deux ligne pour en ajouter une.
if grille2.rowcount >=2 then grille2.rowcount = grille2.rowcount +1
'--- La boucle d'injection des données dans grille2
for colo = 0 to grille2.colcount
grille2.cell(colo,grille2.rowcount-1) = grille1.cell(colo,lign_cherche)
next
nbre++ '--- Ajouter 1
end if
next
'--- Effacer la seconde ligne car non utilisée (Débrouille pour avoir quelquechose de beau)
grille2.deleterow(1)'--- N'oublie pas que les ligne ou colonnes commencent par zéro ! d'ou le (1) pour la seconde ligne
statusbar.simpletext = str$(nbre) & " lignes trouvée(s)"
'--- FIN de la boucle de recherche
END SUB
sub enreg_grille2 (sender as qmenuitem)
dim savedial as qsavedialog
if savedial.execute then
grille2.savetofile(savedial.filename,0,0,grille2.rowcount)
end if
end sub
sub efface_grille2
dim efface_lign as integer, efface_col as integer
'--- Boucle d'effacement de la grille
'--- Attention toutes les données serons perdue !
for efface_lign = 0 to grille2.rowcount
for efface_col = 0 to grille2.colcount
grille2.cell(efface_col,efface_lign) = ""
next
next
'--- Affichage de deux lignes seulement
grille2.rowcount = 2
'--- Mise a jour des entêtes
'--- déterminer le nombre de colonne dans grille2 (selon le fichier ouvert)
'--- Ici cette valeur est statique car on n'a pas de menu ouvrir une grille.
'--- je te la met au cas ou.
dim maj_colo as integer '--- Variable pour metre à jour les colonnes
grille2.colcount = grille1.colcount
for maj_colo = 0 to grille1.colcount
grille2.cell(maj_colo,0)= grille1.cell(Maj_colo,0)
next
end sub
mardi 27 avril 2010
jeudi 25 mars 2010
recherche dans une grille
$APPTYPE GUI
$typecheck on
$include "include/rapidq2.inc"
DECLARE SUB cherche_click
DECLARE SUB ouvre_click
DECLARE SUB remplir_combobox
DECLARE SUB Quit_click
DECLARE SUB efface_grille
CREATE Form AS QFORM
Caption = "test de recherche"
Width = 728
Height = 394
Center
CREATE mainmenu as QMAINMENU
CREATE men_file as qmenuitem
caption = "Fichier"
create mnu_file_ouvre as qmenuitem
caption = "Ouvrir"
onclick = ouvre_click
end create
create mnu_file_brek as qmenuitem
caption = "-"
end create
create mnu_file_quit as qmenuitem
caption = "Quitter"
onclick = Quit_click
end create
end create
END CREATE
CREATE Panel1 AS QPANEL
Width = 720
Align = 1
visible = false
CREATE Label1 AS QLABEL
Caption = "Chercher :"
Left = 16
Top = 12
Width = 64
Transparent = 1
END CREATE
CREATE Label2 AS QLABEL
Caption = "Dans :"
Left = 200
Top = 12
Transparent = 1
END CREATE
CREATE Edit1 AS QEDIT
Text = "texte a chercher"
Left = 72
Top = 8
END CREATE
CREATE ComboBox1 AS QCOMBOBOX
AddItems "reprendre les entête de la grille"
Text = "ComboBox1"
Left = 240
Top = 8
END CREATE
CREATE BTN1 AS QBUTTON
Caption = "Chercher"
Left = 400
Top = 8
Height = 21
OnClick = cherche_click
END CREATE
END CREATE
CREATE Grille AS QSTRINGGRID
'Left = 0
'Top = 41
'Height = 320
'Width = 720
Align = 5
DefaultColWidth = 80
DefaultRowHeight = 16
FixedCols = 0
ColCount = 3
editormode=true
addoptions(7,10,13)
visible = false
END CREATE
END CREATE
Form.ShowModal
SUB cherche_click
if edit1.text = "" then
showmessage "Aucun texte à chercher !"
exit sub
end if
if combobox1.text = "" then
showmessage "Aucune colonne de recherche déterminée !"
exit sub
end if
' deux option celle ci (plus facile)
' ou celle avec INSTR
DIM ligne_grille as integer
showmessage "chercher le texte " & chr$(34) & edit1.text & chr$(34) & " dans la colonne intitulée : " & grille.cell(val(combobox1.text),0)
for ligne_grille = 1 to grille.rowcount-1
if grille.cell(val(combobox1.text),ligne_grille)= edit1.text then
showmessage "Le texte à été trouvé !" &chr$(10) & "Dans la ligne n° : " &chr$(34) & str$(ligne_grille) & chr$(34)
grille.col = val(combobox1.text)
grille.row = ligne_grille
'grille.selectedcell(combobox1.text)
exit sub
end if
next
showmessage "Le terme " & chr$(34) & edit1.text & " Ne figure pas dans cette colonne."
END SUB
SUB ouvre_click
DIM nombre_ligne as integer
dim opendial as qopendialog
opendial.filter = "*.csv et *.ini |*.csv;*.ini|Tous (*.*)|*.*"
opendial.filterindex = 0
opendial.initialdir = application.path
if opendial.execute then
call efface_grille
grille.loadfromfile(opendial.filename,0,0,99999)
Showmessage "ouvrir une grille"
combobox1.clear
call remplir_combobox
end if
panel1.visible = true
grille.visible = true
END SUB
sub remplir_combobox
dim i as integer
for I = 0 to grille.colcount-1
combobox1.additems(grille.cell(I,0))
next
end sub
sub effacer_grille
dim lign as integer, colo as integer
for colo = 0 to grille.colcount-1
for lign = 0 to grille.rowcount-1
grille.cell(colo,lign)=""
next
next
end sub
SUB Quit_click
application.terminate
END SUB
$typecheck on
$include "include/rapidq2.inc"
DECLARE SUB cherche_click
DECLARE SUB ouvre_click
DECLARE SUB remplir_combobox
DECLARE SUB Quit_click
DECLARE SUB efface_grille
CREATE Form AS QFORM
Caption = "test de recherche"
Width = 728
Height = 394
Center
CREATE mainmenu as QMAINMENU
CREATE men_file as qmenuitem
caption = "Fichier"
create mnu_file_ouvre as qmenuitem
caption = "Ouvrir"
onclick = ouvre_click
end create
create mnu_file_brek as qmenuitem
caption = "-"
end create
create mnu_file_quit as qmenuitem
caption = "Quitter"
onclick = Quit_click
end create
end create
END CREATE
CREATE Panel1 AS QPANEL
Width = 720
Align = 1
visible = false
CREATE Label1 AS QLABEL
Caption = "Chercher :"
Left = 16
Top = 12
Width = 64
Transparent = 1
END CREATE
CREATE Label2 AS QLABEL
Caption = "Dans :"
Left = 200
Top = 12
Transparent = 1
END CREATE
CREATE Edit1 AS QEDIT
Text = "texte a chercher"
Left = 72
Top = 8
END CREATE
CREATE ComboBox1 AS QCOMBOBOX
AddItems "reprendre les entête de la grille"
Text = "ComboBox1"
Left = 240
Top = 8
END CREATE
CREATE BTN1 AS QBUTTON
Caption = "Chercher"
Left = 400
Top = 8
Height = 21
OnClick = cherche_click
END CREATE
END CREATE
CREATE Grille AS QSTRINGGRID
'Left = 0
'Top = 41
'Height = 320
'Width = 720
Align = 5
DefaultColWidth = 80
DefaultRowHeight = 16
FixedCols = 0
ColCount = 3
editormode=true
addoptions(7,10,13)
visible = false
END CREATE
END CREATE
Form.ShowModal
SUB cherche_click
if edit1.text = "" then
showmessage "Aucun texte à chercher !"
exit sub
end if
if combobox1.text = "" then
showmessage "Aucune colonne de recherche déterminée !"
exit sub
end if
' deux option celle ci (plus facile)
' ou celle avec INSTR
DIM ligne_grille as integer
showmessage "chercher le texte " & chr$(34) & edit1.text & chr$(34) & " dans la colonne intitulée : " & grille.cell(val(combobox1.text),0)
for ligne_grille = 1 to grille.rowcount-1
if grille.cell(val(combobox1.text),ligne_grille)= edit1.text then
showmessage "Le texte à été trouvé !" &chr$(10) & "Dans la ligne n° : " &chr$(34) & str$(ligne_grille) & chr$(34)
grille.col = val(combobox1.text)
grille.row = ligne_grille
'grille.selectedcell(combobox1.text)
exit sub
end if
next
showmessage "Le terme " & chr$(34) & edit1.text & " Ne figure pas dans cette colonne."
END SUB
SUB ouvre_click
DIM nombre_ligne as integer
dim opendial as qopendialog
opendial.filter = "*.csv et *.ini |*.csv;*.ini|Tous (*.*)|*.*"
opendial.filterindex = 0
opendial.initialdir = application.path
if opendial.execute then
call efface_grille
grille.loadfromfile(opendial.filename,0,0,99999)
Showmessage "ouvrir une grille"
combobox1.clear
call remplir_combobox
end if
panel1.visible = true
grille.visible = true
END SUB
sub remplir_combobox
dim i as integer
for I = 0 to grille.colcount-1
combobox1.additems(grille.cell(I,0))
next
end sub
sub effacer_grille
dim lign as integer, colo as integer
for colo = 0 to grille.colcount-1
for lign = 0 to grille.rowcount-1
grille.cell(colo,lign)=""
next
next
end sub
SUB Quit_click
application.terminate
END SUB
Inscription à :
Commentaires (Atom)