TextCombobox vers StringGadget impossible

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

TextCombobox vers StringGadget impossible

Message par SpaceMan »

Bonjour à tous
j'essaie d'afficher le nom+l'extension d'un fichier dans le stringGadget mais impossible alors que le debuger me l'affiche correctement.
je voudrais que seule l'extension sois changée

Code : Tout sélectionner

;{- Enumerations / DataSections
;{ Windows
Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Text_0
  #Text_1
  #String_2
  #ComboBox_3
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 375, 325, 230, 66, "Fichier+Extension", #PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    If CreateGadgetList(WindowID(#Window_0))
      TextGadget(#Text_0, 6, 5, 82, 20, "Nom du Fichier")
      TextGadget(#Text_1, 5, 35, 80, 20, "Extension")
      StringGadget(#String_2, 90, 5, 135, 20, "Toto")
      ComboBoxGadget(#ComboBox_3, 90, 35, 135, 100)
      
      Dim item.s(5) 
      item(0) = ".PB" 
      item(1) = ".txt" 
      item(2) = ".doc"
      item(3) = ".xls" 
      item(4) = ".ini"  
      For i = 0 To 4
        AddGadgetItem(#ComboBox_3, -1, item(i)) 
      Next i      
    EndIf
  EndIf
EndProcedure

OpenWindow_Window_0()

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #Text_0
      ElseIf EventGadget = #Text_1
      ElseIf EventGadget = #String_2
      
      ElseIf EventGadget = #ComboBox_3
      Rep$ = GetGadgetText(#String_2)
      Rep2$ = GetGadgetItemText(#ComboBox_3,GetGadgetState(#ComboBox_3),0)
       If Rep$ <> "" And EventType() = #PB_EventType_Change 
       SetGadgetText(#String_2,Rep$+Rep2$): EndIf
      Debug Rep$+Rep2$ ; affiche bien le nom+extension mais impossible de l'afficher dans le stringgadget
      EndIf
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

normal !!
tu confonds AND et OR :D
explication dans le code !! :D

rappel un pour un "and" il faut que les deux condition soit vrais !!
pour un "or" c'est soit l'une des condition soit l'autre ou bien les deux !! :D



Code : Tout sélectionner

;{- Enumerations / DataSections
;{ Windows
Enumeration
    #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
    #Text_0
    #Text_1
    #String_2
    #ComboBox_3
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
    If OpenWindow(#Window_0, 375, 325, 230, 66, "Fichier+Extension", #PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
        If CreateGadgetList(WindowID(#Window_0))
            TextGadget(#Text_0, 6, 5, 82, 20, "Nom du Fichier")
            TextGadget(#Text_1, 5, 35, 80, 20, "Extension")
            StringGadget(#String_2, 90, 5, 135, 20, "Toto")
            ComboBoxGadget(#ComboBox_3, 90, 35, 135, 100)
            
            Dim item.s(5)
            item(0) = ".PB"
            item(1) = ".txt"
            item(2) = ".doc"
            item(3) = ".xls"
            item(4) = ".ini"
            For i = 0 To 4
                AddGadgetItem(#ComboBox_3, -1, item(i))
            Next i     
        EndIf
    EndIf
EndProcedure

OpenWindow_Window_0()

;{- Event loop
Repeat
    Event = WaitWindowEvent()
    Select Event
        ; ///////////////////
        Case #PB_Event_Gadget
            EventGadget = EventGadget()
            EventType = EventType()
            If EventGadget = #Text_0
            ElseIf EventGadget = #Text_1
            ElseIf EventGadget = #String_2
                
            ElseIf EventGadget = #ComboBox_3
                Rep$ = GetGadgetText(#String_2)
                Rep$=StringField(Rep$,1,".") ; <----------------------ajout de Dobro
                Rep2$ = GetGadgetItemText(#ComboBox_3,GetGadgetState(#ComboBox_3),0)  
                If Rep$ <> "" Or EventType() = #PB_EventType_Change 
                    SetGadgetText(#String_2,"")
                SetGadgetText(#String_2,Rep$+Rep2$): EndIf 
            EndIf
            ; ////////////////////////
        Case #PB_Event_CloseWindow
            EventWindow = EventWindow()
            If EventWindow = #Window_0
                CloseWindow(#Window_0)
                Break
            EndIf
    EndSelect
ForEver 
Dernière modification par Backup le mer. 05/sept./2007 21:48, modifié 1 fois.
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

Message par SpaceMan »

Slt Grand Maitre Dobro
normal !!
tu confonds AND et OR :D
explication dans le code !! :D
faut dire que je suis doué pour faire des conneries que pour bien faire :(

le probleme n'est toujours pas resolu puisque l'extension s'ajoute chaque fois qu'on la change au lieu de remplacer la précédente.
Lna
Messages : 181
Inscription : mar. 21/juin/2005 11:11

Message par Lna »

Code : Tout sélectionner

;{- Enumerations / DataSections 
;{ Windows 
Enumeration 
  #Window_0 
EndEnumeration 
;} 
;{ Gadgets 
Enumeration 
  #Text_0 
  #Text_1 
  #String_2 
  #ComboBox_3 
EndEnumeration 
;} 
Define.l Event, EventWindow, EventGadget, EventType, EventMenu 
;} 
Procedure OpenWindow_Window_0() 
  If OpenWindow(#Window_0, 375, 325, 230, 66, "Fichier+Extension", #PB_Window_SizeGadget|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
    If CreateGadgetList(WindowID(#Window_0)) 
      TextGadget(#Text_0, 6, 5, 82, 20, "Nom du Fichier") 
      TextGadget(#Text_1, 5, 35, 80, 20, "Extension") 
      StringGadget(#String_2, 90, 5, 135, 20, "Toto") 
      ComboBoxGadget(#ComboBox_3, 90, 35, 135, 100) 
      
      Dim item.s(5) 
      item(0) = ".PB" 
      item(1) = ".txt" 
      item(2) = ".doc" 
      item(3) = ".xls" 
      item(4) = ".ini"  
      For i = 0 To 4 
        AddGadgetItem(#ComboBox_3, -1, item(i)) 
      Next i      
    EndIf 
  EndIf 
EndProcedure 

OpenWindow_Window_0() 

;{- Event loop 
Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    ; /////////////////// 
    Case #PB_Event_Gadget 
      EventGadget = EventGadget() 
      EventType = EventType() 
      If EventGadget = #Text_0 
      ElseIf EventGadget = #Text_1 
      ElseIf EventGadget = #String_2 
      
      ElseIf EventGadget = #ComboBox_3 
      Rep$ = GetGadgetText(#String_2) 
      Rep2$ = GetGadgetItemText(#ComboBox_3,GetGadgetState(#ComboBox_3),0) 
        If Rep$ <> "" Or EventType() = #PB_EventType_Change 
          len_extension=Len(GetExtensionPart(Rep$))
          If len_extension
            len_extension+1 ; pour le point
          EndIf
          
          Rep$=Left(Rep$,Len(Rep$)-len_extension)
          
          SetGadgetText(#String_2,Rep$+Rep2$)
        EndIf 
        
        Debug Rep$+Rep2$ ; affiche bien le nom+extension mais impossible de l'afficher dans le stringgadget 
      EndIf 
    ; //////////////////////// 
    Case #PB_Event_CloseWindow 
      EventWindow = EventWindow() 
      If EventWindow = #Window_0 
        CloseWindow(#Window_0) 
        Break 
      EndIf 
  EndSelect 
ForEver
Il fallait extraire le nom. :idea:

@ peluche
SpaceMan
Messages : 290
Inscription : mar. 26/oct./2004 19:35
Contact :

Message par SpaceMan »

LNA
Il fallait extraire le nom. :idea:
Ah oui !!

Merci à vous. :D
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

il suffit d'ajouter cette ligne () modifié dans mon exemple ci dessus !!

Code : Tout sélectionner

Rep$=StringField(Rep$,1,".") ; <----------------------ajout de Dobro 
:D

pas besoin d'une usine a gaz ! :lol:
Lna
Messages : 181
Inscription : mar. 21/juin/2005 11:11

Message par Lna »

Dobro a écrit :pas besoin d'une usine a gaz
Mon choix concernant de ladite usine à gaz, passerait avec succès les tests unitaires du style : "C:\dossier.txt\image.jpg" par exemple. :wink:

@ peluche
Répondre