locked
VB.net Windows Mobile Save File RRS feed

  • Question

  • How do i create a file with the following name (where the feild references are replaced with the relevant strings & The DD-MM-YY is replaced with the current date i.e. 05-03-09)

    txtTeam1.text & " Vs " txtTeam2.text & DD-MM-YY & ".txt"


    and then add all the items in the list box lstLog to the created file


    answers in plain simple english please - a code smipit to do this would be even better thanks

    Thanks From Joe
    Thursday, March 5, 2009 10:51 PM

All replies

  •  
     
    DIM dt as DateTime
    'set the a value of dt here  
    fileName = String.Format("blah-blah-blah-{0:MM-dd-yyyy}.txt",dt)  
     

    Joel Ivory Johnson
    Friday, March 6, 2009 3:20 AM
  •  
    1 Dim dt as DateTime   
    2 'set the a value of dt here ? HOW????    
    3 fileName = String.Format(lblTeam1.text & " Vs " & lblTeam2.txt & " - " & dt & ".txt")  
    4 'How do i now save the file and add the lstLog to it? 

    is this right and can you complete the missing commented out areas
    Thanks From Joe
    Friday, March 6, 2009 12:28 PM
  • You can set the value of your date object by using the date constructor.  Take a look at the DateTime documentation for an example of how to use the constructor to set the value.   The syntax for the call to String.Format should look like this.

     
    fileName = String.Format ( "{0}Vs{1}-{2:MM-dd-yyyy}.txt", lblTeam1.Text, lblTeam2.txt, dt)  
     

    you can find more information on using String.Format here.


    Your listbox object has a member named Items.  You can use that to get to the items in your listbox.

    I'd like to suggest the book Microsoft .Net 2.0 Application Foundations. From your questions I gather you are new to programming and the .Net framework.  As the title suggest the book will cover foundational concepts of .Net including IO and basic UI operations.


    Joel Ivory Johnson
    Saturday, March 7, 2009 5:27 PM
  • Dim dlg As SaveFileDialog = New SaveFileDialog()
            'Set the Save dialog properties
            With dlg
                .FileName = lblTeam1.Text & " Vs " & lblTeam2.Text & DateTime.Now.ToString("' 'd'-'M'-'yy' 'h' 'mm tt") & ".txt"
                .Filter = "Text files (*.txt)|"
                .FilterIndex = 1
            End With
            Dim res As DialogResult = dlg.ShowDialog()
            If res = Windows.Forms.DialogResult.OK Then
                Dim objWriter As New System.IO.StreamWriter(res, True)
                objWriter.Write(lstLog.Items)
            End If

    3rd time lucky why doesnt this create a file ?
    dont know if append works as file not created :@ this getting annoying now - on PC edition the create file thing works fine

    Thanks From Joe
    Sunday, March 8, 2009 12:44 AM
  • you never passed a file name to the stream writer.  Instead you passed the variable "res." res just contains the enumerated value "OK."  The file name is in dlg.FileName.
    Joel Ivory Johnson
    Sunday, March 8, 2009 1:53 AM
  • ok thank you that all works but now i have another problem, windows mobile doesnt support txt file apparently it says 

    There is no application associated with "Team 1 Vs Team 2 8-3-09 1 21 PM". Run the Application first, then open the file from within the application.

    what file type should i use? if i rename the file and put .txt then still nothing.

    thanks for all your help with this

    Thanks From Joe
    Sunday, March 8, 2009 1:25 PM
  • i really want to be able to open and view the file on windows mobile and then on a PC once activesync has been run so a standard format would be best thanks
    Thanks From Joe
    Sunday, March 8, 2009 1:27 PM
  • if i open up the file in notes or mobile word it shows as an empty file :S
    Thanks From Joe
    Sunday, March 8, 2009 1:35 PM
  • Windows Mobile will let you open text files.  I'm wondering if the file you created really has a txt extention.  I'd speculate it doesn't; your filter string isn't quite right.  It should be "Text files (*.txt|*.txt".

    As for the file being empty you never actually wrote anything to it.  The Items member of the listbox is a collection and not a single entity.  You will need to use a for loop going from 0 the lstLog.Items.Count-1.  For each iteration of your for loop you will be writing lstLog.Items(index) to your file.


    Joel Ivory Johnson
    Sunday, March 8, 2009 10:23 PM
  • 1Dim dlg As SaveFileDialog = New SaveFileDialog() 
    2        'Set the Save dialog properties 
    3        With dlg 
    4            .FileName = lblTeam1.Text & " Vs " & lblTeam2.Text & DateTime.Now.ToString("' 'd'-'M'-'yy' 'h' 'mm tt") & ".txt" 
    5            .Filter = "Text files (*.txt)|*.txt" 
    6            .FilterIndex = 1 
    7        End With 
    8        Dim res As DialogResult = dlg.ShowDialog() 
    9        If res = Windows.Forms.DialogResult.OK Then 
    10            Dim objWriter As New System.IO.StreamWriter(dlg.FileName, True
    11            Dim i As Integer 
    12            i = 0 
    13            Do While i < lstLog.Items.Count 
    14                objWriter.Write(lstLog.Items(i)) 
    15                i = i + 1 
    16            Loop 
    17        End If 


    the file now saves as a text file you where correct it was not saveing as .txt - but the file is still empty :S


    Thanks From Joe
    Sunday, March 8, 2009 11:26 PM