Autore Topic: [RISOLTO] Open Dialog.Path  (Letto 1088 volte)

Offline tornu

  • Gran Maestro dei Gamberi
  • *****
  • Post: 855
    • Mostra profilo
[RISOLTO] Open Dialog.Path
« il: 25 Settembre 2010, 23:37:31 »
Continua la battaglia con Gambas3 per fargli digerire la conversione di un progetto in versione Gambas2.
Dopo aver corretto già un bel pò di righe di codice mi sono imbattuto in questa risposta di Gambas3 che non riesco a risolvere

Unexpected Open

riferito alla parte di codice della riga 17 (che in Gambas2 è perfettamente funzionante....ma và  ;D)

Codice: gambas [Seleziona]
Public Sub BtnSelFile_Click()
  Dim csvFile As File
  Dim textLine As String
  Dim items As String[]
  Dim i As Integer
  Dim key As Integer

  Dialog.Title = "Selezione tipo File"
  ' Dialog.Filter = ["Comma Separated Variable files (*.csv *.log)", "All files (*)"]

  ' Use this in Gambas 2
  Dialog.Filter = ["*.csv *.log", "Tipo files", "*", "Tutti i files"]

  If Dialog.OpenFile() Then Return
  ' Open the file as READ only
  ' This will throw an error if the file does not exist
      Open Dialog.Path For Read As #csvFile
      CvwDati.Clear
      CvwDati.Columns.Count = 1
      CvwDati.Columns[0].Text = "Item 1"
  ' Loop through each line until the end of file.
  ' Eof() returns true at the end of the file.
      While Not Eof(csvFile)
        Line Input #csvFile, textLine
    ' Split each line into fields
    ' Note that we set the " char as an escape char
        items = Split(textLine, ",", ";", "\"")
        Inc key
        CvwDati.Add(key, items[0])
        For i = 1 To items.Count - 1
          If CvwDati.Columns.Count <= i Then
            CvwDati.Columns.Count = i + 1
            CvwDati.Columns[i].Text = "Item " & (i + 1)
          End If
          CvwDati[key][i] = items[i]
        Next
      Wend
  Close #csvFile
  Catch
    Message.Info("<b>Cannot load items:</b><br>" & Dialog.Path & "<hr>" & Error.Text)
  ' Make sure the file is closed. If the file is already closed
  ' or a null object then TRY will make sure we do not raise an error.
  Try Close #csvFile
End



« Ultima modifica: 26 Settembre 2010, 12:31:51 da tornu »
Il software è come il sesso, è meglio quando è libero. (Linus Torvalds)

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.272
  • Chi parla poco dice tanto...
    • Mostra profilo
Re: Open Dialog.Path
« Risposta #1 il: 26 Settembre 2010, 00:00:16 »
Prova a sostituire con:

csvFile = Open Dialog.Path For Read

dovrebbe funzionare

Offline tornu

  • Gran Maestro dei Gamberi
  • *****
  • Post: 855
    • Mostra profilo
Re: Open Dialog.Path
« Risposta #2 il: 26 Settembre 2010, 12:31:15 »
 :-* ...Scusa la confidenza  :D
Il software è come il sesso, è meglio quando è libero. (Linus Torvalds)