Differenze tra le versioni di "Mostrare in un oggetto di testo il contenuto di un file trascinandolo e rilasciandolo senza l'uso delle specifiche risorse di Gambas del Drag&Drop"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "E' possibile far mostrare il contenuto di un file all'interno di un oggetto di testo, trascinandovi e rilasciandovi il file medesimo, senza l'uso delle specifiche risorse di G...") |
|||
Riga 1: | Riga 1: | ||
E' possibile far mostrare il contenuto di un file all'interno di un oggetto di testo, trascinandovi e rilasciandovi il file medesimo, senza l'uso delle specifiche risorse di Gambas per il ''Drag&Drop''. | E' possibile far mostrare il contenuto di un file all'interno di un oggetto di testo, trascinandovi e rilasciandovi il file medesimo, senza l'uso delle specifiche risorse di Gambas per il ''Drag&Drop''. | ||
− | Mostriamo di seguito un esempio pratico <SUP> | + | Mostriamo di seguito un esempio pratico <SUP>[[[#Note|nota 1]]]</sup>, che offre la possibilità appunto di mostrare il contenuto di un file <SUP>[ [[#Note|nota 2]] ]</sup> all'interno di una ''TextArea'', trascinandovi e rilasciandovi il file predetto. Se il ''charset'' dei file html non è UTF-8, esso viene convertito. |
− | + | Public Sub TextArea1_Change() | |
− | + | ||
− | |||
Dim s, s2, s3, sChar As String | Dim s, s2, s3, sChar As String | ||
Dim i As Integer | Dim i As Integer | ||
− | + | s = Trim(TextArea1.Text) | |
− | + | Object.Lock(TextArea1) | |
− | + | i = RInStr(s, "file:/") | |
− | + | If i > 0 Then | |
− | + | s2 = FromUrl(Trim(Mid(s, i + 7))) | |
− | + | Print s2 | |
− | + | Try s3 = File.Load(s2) | |
− | + | If Right(s, 4) = "html" Then | |
− | + | sChar = Charset(s3) | |
− | + | If sChar <> "UTF-8" Then Try s3 = Conv$(s3, sChar, "UTF-8") | |
− | + | Endif | |
− | + | If Error Then s3 = "#ERRORE N° " & Error.Code & " - " & Error.Text | |
− | + | TextArea1.Text = s3 | |
− | + | Endif | |
− | |||
− | |||
− | |||
− | + | Finally | |
+ | Object.Unlock(TextArea1) | ||
+ | |||
+ | End | ||
+ | |||
+ | Private Function Charset(value As String) As String | ||
− | |||
− | |||
Dim ss As String[] | Dim ss As String[] | ||
Dim s, r As String | Dim s, r As String | ||
Dim i, il As Integer | Dim i, il As Integer | ||
− | + | ss = Split(value, "\n") | |
− | + | For Each s In ss | |
− | + | If s Like "*charset=*" Then | |
− | + | il = RInStr(s, "charset=") | |
− | + | For i = (il + 8) To Len(s) | |
− | + | If Mid(s, i, 1) = "\"" Then | |
− | + | r = Mid(s, (il + 8), i - (il + 8)) | |
− | + | Return r | |
− | + | Endif | |
− | + | Next | |
− | + | Endif | |
− | + | Next | |
− | + | ||
− | + | End | |
− | |||
Versione delle 07:47, 5 ago 2023
E' possibile far mostrare il contenuto di un file all'interno di un oggetto di testo, trascinandovi e rilasciandovi il file medesimo, senza l'uso delle specifiche risorse di Gambas per il Drag&Drop.
Mostriamo di seguito un esempio pratico [nota 1], che offre la possibilità appunto di mostrare il contenuto di un file [ nota 2 ] all'interno di una TextArea, trascinandovi e rilasciandovi il file predetto. Se il charset dei file html non è UTF-8, esso viene convertito.
Public Sub TextArea1_Change() Dim s, s2, s3, sChar As String Dim i As Integer s = Trim(TextArea1.Text) Object.Lock(TextArea1) i = RInStr(s, "file:/") If i > 0 Then s2 = FromUrl(Trim(Mid(s, i + 7))) Print s2 Try s3 = File.Load(s2) If Right(s, 4) = "html" Then sChar = Charset(s3) If sChar <> "UTF-8" Then Try s3 = Conv$(s3, sChar, "UTF-8") Endif If Error Then s3 = "#ERRORE N° " & Error.Code & " - " & Error.Text TextArea1.Text = s3 Endif Finally Object.Unlock(TextArea1) End Private Function Charset(value As String) As String Dim ss As String[] Dim s, r As String Dim i, il As Integer ss = Split(value, "\n") For Each s In ss If s Like "*charset=*" Then il = RInStr(s, "charset=") For i = (il + 8) To Len(s) If Mid(s, i, 1) = "\"" Then r = Mid(s, (il + 8), i - (il + 8)) Return r Endif Next Endif Next End
Note
[1] Il codice è stato scritto dal membro Gianluigi del forum www.gambas-it.org .
[2] In effetti è possibile mostrare con rappresentazione testuale dei caratteri ASCII il contenuto di qualsiasi tipo di file.