Hi.
Is there any way to copy all items in a ListViewGadget to a text file on separate lines? Doing it the other way around is no problem but I don't see a way of doing this. The documentation gives these commands:
- AddGadgetItem(): Add an item.
- RemoveGadgetItem(): Remove an item.
- ClearGadgetItemList(): Remove all the items
- CountGadgetItems(): Returns the number of items currently in the #Gadget.
- GetGadgetState(): Get the index of the selected item or -1 if there is no selected item.
- GetGadgetItemText(): Get the content of the given item.
- GetGadgetText(): Get the content of the selected item.
- SetGadgetState(): Change the selected item. If -1 is specified, the selection will be removed.
All of them appear to require an item to be selected, but I am trying to copy the entire contents without any selections. Any help would be appreciated. Thanks.
ListViewGadget to text file
David, what about this?...
You Can't expect the language to have a function for everyones needs...
Code: Select all
;/
Procedure.s GatherListViewItems(GadgetID.l, AddCRLF=#True)
Define.l lItems, n
Define.s sTempStr
lItems = CountGadgetItems(GadgetID)
If AddCRLF = #True
For n=0 To lItems
sTempStr + GetGadgetItemText(GadgetID,n,0) + #crlf$
Next
Else
For n=0 To lItems
sTempStr + GetGadgetItemText(GadgetID,n,0)
Next
EndIf
ProcedureReturn sTempStr
EndProcedure
;/
Procedure.s CreateJunk(HowLong)
Define.s sTempJunk
Define.l n
For n=0 To HowLong-1
sTempJunk + Chr( 32+Random( 94 ) )
Next
ProcedureReturn sTempJunk
EndProcedure
;/
OpenWindow(0, 0, 0, 320, 240, "" )
CreateGadgetList( WindowID( 0 ) )
ListViewGadget( 0, 5, 5, 310, 230 )
;/ Lets fill the gadget with some junk...
For n=0 To 99
AddGadgetItem( 0, -1, Str(n) + " " + CreateJunk(40))
Next
;/ Lets just debug all contents, no need for saving...
Debug GatherListViewItems(0)
;/
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Last edited by dagcrack on Sat Aug 12, 2006 7:11 pm, edited 1 time in total.
Hi.
I have been looking at GetGadgetItemText() for most of the day but I've not been able to find a way, so you are saying I am missing something Trond? I'll look again, thanks.
Thanks dagcrack, I'll give that a try. No, I certainly wouldn't expect PB to have a function for everyones needs. I just couldn't find a way of doing something so I thought ask others who are more experienced than myself. I appreciate your help, thanks.
BTW, what is a helper routine?
I have been looking at GetGadgetItemText() for most of the day but I've not been able to find a way, so you are saying I am missing something Trond? I'll look again, thanks.
Thanks dagcrack, I'll give that a try. No, I certainly wouldn't expect PB to have a function for everyones needs. I just couldn't find a way of doing something so I thought ask others who are more experienced than myself. I appreciate your help, thanks.
BTW, what is a helper routine?
David, no problem!.
About your question: A helper routine is simply a routine that serves a "helping" purpose, like this one does.
It helps you from writing lots of code, providing you an instant output of what you needed.
It could of been a macro though, but as you wish...
With time, you'll write lots of useful helper routines which you might include on your programs all the time.
A stupid example:
In a program where you'd need to perform X actions all the time, on different parts of the program, you might want a helper routine (either as proc or macro, depending on the case). Instead of having to write the same thing all the time, I guess this is obvious even for the beginner...
As helpers, Macro do a better job, but we cant globalize anything when we talk about programming, since every single case is special and needs to be treated in a different way most of the times.
By the way, I assumed you were on Windows, thats why I used CRLF, else, you'll have to change to suit your needs. Since *nix uses LF !.
About your question: A helper routine is simply a routine that serves a "helping" purpose, like this one does.
It helps you from writing lots of code, providing you an instant output of what you needed.
It could of been a macro though, but as you wish...
With time, you'll write lots of useful helper routines which you might include on your programs all the time.
A stupid example:
Code: Select all
Procedure.s hFixSentence(sInputStr.s) ; our helper routine.
;
While FindString(sInputStr," ",0)
sInputStr = ReplaceString(sInputStr," ", " ", 1)
Wend
sInputStr = ReplaceString(sInputStr, " ? ", "?",1)
ProcedureReturn Trim(sInputStr)
;
EndProcedure
;/
Define.s sIn
sIn = " Hey hows going ? "
sIn = hFixSentence(sIn)
Debug sIn
As helpers, Macro do a better job, but we cant globalize anything when we talk about programming, since every single case is special and needs to be treated in a different way most of the times.
By the way, I assumed you were on Windows, thats why I used CRLF, else, you'll have to change to suit your needs. Since *nix uses LF !.