Hi,
I am writing a small program to read a CSV file. It's basically a phone book. I want to give the user the option to choose a name. I will them extract the email address, and email that user. I'm having a hard time extracting the item from the list. What am I doing wrong? Here is the code I am playing with. It's code from your support page. Thank you.
filename = "C:\phonelist.csv"
names_array = ArrayFileGetCSV( filename, 0)
MyDialogFormat=`WWWDLGED,6.2`
MyDialogCaption=`phonebook`
MyDialogX=002
MyDialogY=059
MyDialogWidth=510
MyDialogHeight=118
MyDialogNumControls=005
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,154|203|252`
MyDialogConfig=0
MyDialog001=`461,101,026,012,PUSHBUTTON,"PushButton_Close",DEFAULT,"Close",1,10,@csFlat|@csDefButton,DEFAULT,DEFAULT,"255|255|255"`
MyDialog002=`223,101,062,012,PUSHBUTTON,"PushButton_editspreadsheet",DEFAULT,"Edit Excell Spreadsheet",2,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`129,101,036,012,PUSHBUTTON,"PushButton_email",DEFAULT,"Email User",3,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`011,101,036,012,PUSHBUTTON,"PushButton_skype",DEFAULT,"Skype User",4,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`007,001,494,094,REPORTVIEW,"ReportView_1",names_array,DEFAULT,DEFAULT,20,@csAsort|@csFirstHeader|@csFullSel|@csGrid|@csColEdit|@csSingleSel,DEFAULT,DEFAULT,DEFAULT`
ButtonPushed=Dialog("MyDialog")
;check to see if the user wants to email the selection
If Buttonpushed == 3 then
; Get Selected Items
; The array variable defined in the Reportview
; will contain the selected rows once the dialog returns
selected = ""
For row = 0 To ArrInfo(names_array, 1)-1
data = ""
For col = 0 To ArrInfo(names_array, 2)-1
item = names_array[row,col]
If data == '' Then data = item
Else data = data:'|':item
Next
If selected == '' Then selected = data
Else selected = selected:@TAB:data
Next
;checked = StrTrim(checked)
userdata=AskItemlist('Selected items', selected, @TAB, @UNSORTED, @SINGLE )
;;;; Here is where I am having issues. How do I extract the 4 item from the list, which is an email address?
;now get email which is the fourth item in the list
useremail=ItemExtract(4,userdata, @TAB )
display(2,"email",useremail)
endif
;check to see if user wants to update phone book
If Buttonpushed == 2 then run("excel","C:\phonelist.csv")
Would recommend that you change your script so that it uses a dynamic dialog and skip using AskItemList.
But to answer your immediate question you are attempting to extract an item from vertical bar delimited list but specifying a tab character as the delimiter. That is not going to fly.
Thanks for the input. The Tab as opposed to the vertical bar is a left over from another t-shooting attempt. It still did not extract the item when use used the vertical bar. I'll play with the dynamic dialog. I'm very close to finishing this. Thanks again.
Garbage in garbage out could be your problem. The WinBatch Studio debugger and its Watch window are nice tools for finding problems like that.
Here is the the final version. I am pasting the code in case anyone is interested. Who knows maybe something in the code can help someone down the line. The program will open a csv file containing phone book info.
;if you would like the user choose the file
;filename = AskFilename("CSV FIle", DirScript(), "CSV Files|*.csv", "", 1 )
filename = "C:\phonelist.csv" ;location of csv file contiaing user info. I am using excel.
names_array = ArrayFileGetCSV( filename, 0)
MyDialogFormat=`WWWDLGED,6.2`
MyDialogCaption=`phone book`
MyDialogX=002
MyDialogY=059
MyDialogWidth=510
MyDialogHeight=118
MyDialogNumControls=005
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,154|203|252`
MyDialogConfig=0
MyDialog001=`461,101,026,012,PUSHBUTTON,"PushButton_Close",DEFAULT,"Close",1,10,@csFlat|@csDefButton,DEFAULT,DEFAULT,"255|255|255"`
MyDialog002=`223,101,062,012,PUSHBUTTON,"PushButton_editspreadsheet",DEFAULT,"Edit Excell Spreadsheet",2,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`129,101,036,012,PUSHBUTTON,"PushButton_email",DEFAULT,"Email User",3,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`011,101,036,012,PUSHBUTTON,"PushButton_skype",DEFAULT,"Skype User",4,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`007,001,494,094,REPORTVIEW,"ReportView_1",names_array,DEFAULT,DEFAULT,20,@csAsort|@csFirstHeader|@csFullSel|@csGrid|@csColEdit|@csSingleSel,"Microsoft Sans Serif|9728|40|34",DEFAULT,DEFAULT`
ButtonPushed=Dialog("MyDialog")
;;;;;;Routine to edit the spreadsheet
If Buttonpushed == 2 then run("excel","C:\phonelist.csv")
;;;;;;Routine to email the user
If Buttonpushed == 3 then
; Get Selected Items
; The array variable defined in the Reportview
; will contain the selected rows once the dialog returns
selected = ""
For row = 0 To ArrInfo(names_array, 1)-1
data = ""
For col = 0 To ArrInfo(names_array,6)-1
item = names_array[row,col]
If data == '' Then data = item
Else data = data:'|':item
Next
If selected == '' Then selected = data
Else selected = selected:@TAB:data
Next
;now get email which is the 5 item in the list
useremail=ItemExtract(5,data, "|") ;the 5th column has the email ID
;display(2,"email name",useremail)
objShell = ObjectCreate('wscript.shell')
objShell.Run('outlook /c ipm.note /m %useremail%',0,0)
;objShell.Run('sip:%useremail%',0,0)
;now email that user
endif
;;;;;;Routine to skype the user
; Get Selected Items
; The array variable defined in the Reportview
; will contain the selected rows once the dialog returns
If Buttonpushed == 4 then
selected = ""
For row = 0 To ArrInfo(names_array, 1)-1
data = ""
For col = 0 To ArrInfo(names_array,6)-1
item = names_array[row,col]
If data == '' Then data = item
Else data = data:'|':item
Next
If selected == '' Then selected = data
Else selected = selected:@TAB:data
Next
;now get email which is the 5 item in the list
useremail=ItemExtract(5,data, "|")
;display(2,"email name",useremail)
objShell = ObjectCreate('wscript.shell')
objShell.Run('sip:%useremail% ')