| Author |
Topic Search Topic Options
|
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 14/Mar/2012 at 09:07 |
Funzione n.088 Estra la occorrenza n di una stringa in un testo
§EstraiTesto Sub Testo VediCodice §Estrae il testo delimitato da un marcatore predefinito.§ Occorrenza 2 Memo amore§tesoro§ciao Controllo §
§Public Function EstraiTesto(Occorrenza As Integer, Memo As String, Controllo As String) As String 'DavideLeo http://forum.masterdrive.it/access-79/estrarre-stringa-access-13673/index2.html Memo = Memo & Controllo Dim Contatore As Integer For Contatore = 1 To Occorrenza If Len(Memo) > 0 Then EstraiTesto = Trim(Left(Memo, InStr(1, Memo, Controllo) - 1)) Memo = Mid(Memo, InStr(1, Memo, Controllo) + Len(Controllo)) Else EstraiTesto = "" Exit For End If Next MsgBox EstraiTesto End Function§
|
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 14/Mar/2012 at 09:51 |
Funzione n.089 Estrae tutte le occorrenze di una stringa in un testo
§EstraiTesto2 Sub Testo Luciano §Estrae tutte le occorenze di una stringa contenuta in un testo e delimitata da un marcatore predefinito.§ Memo amore<br>tesoro<br>amore<br>1<br> Controllo <br>
§Public Function EstraiTesto2(Memo As String, Controllo As String) As String Memo = Memo & Controllo Dim Contatore As Integer While Len(Memo) > Len(Controllo) Contatore = InStr(1, Memo, Controllo) EstraiTesto2 = Trim(Mid(Memo, 1, Contatore - 1)) Memo = Right(Memo, Len(Memo) - Contatore - Len(Controllo) + 1) MsgBox EstraiTesto2 Wend End Function§
|
Edited by Luciano - 20/Mar/2012 at 09:12
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 20/Mar/2012 at 09:07 |
Funzione n.090 Il file più vecchio e il più recente
§FilePiùVecchio Sub FileCartelle VediCodice §Estrae il più vecchio e il più recente file di una cartella§ Cartella C:\Users\Luciano2\Desktop\Funzioni Personali
§Public Sub FilePiùVecchio(Cartella) 'Alex http://forum.masterdrive.it/access-79/sistema-backup-compattazione-tramite-applicativo-64659/ Dim sFile, VecchioFile, RecenteFile As String Dim FileDT, VecchiaData, NuovaData As Date ' RECUPERA IL PRIMO FILE NELLA CARTELLA sFile = Dir$(Cartella & "\*.*") ' CICLA TUTTI I FILE(Ma dovrebbero essere solo 5) VecchiaData = Now NuovaData = 0 Do Until sFile = "" FileDT = FileDateTime(Cartella & "\" & sFile) ' CONFRONTA la data del FILE analizzato con quella più vecchia memorizzata If FileDT < VecchiaData Then VecchioFile = sFile VecchiaData = FileDT End If ' CONFRONTA la data del FILE analizzato con quella più vecchia memorizzata If FileDT > NuovaData Then RecenteFile = sFile NuovaData = FileDT End If sFile = Dir$ Loop MsgBox "Il file più recente nella cartella " & Cartella & " è: " & vbCrLf & RecenteFile & " -:- " & Format(NuovaData, "Short Date") & " " & Format(NuovaData, "Short Time") & vbCrLf & "Il file più vecchio è: " & vbCrLf & VecchioFile & " -:- " & Format(VecchiaData, "Short Date") & " " & Format(VecchiaData, "Short Time") End Sub§
|
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 24/Mar/2012 at 15:27 |
Funzione n.091 Cambia la stringa "null" in valore null
§TrasformaNull Sub Tabella Luciano §Cambia la stringa "null" di tutti i campi di una tabella di tipo stringa in valore null.§ Tabella Tabella1
§Public Sub TrasformaNull(Tabella) Dim rs As New ADODB.Recordset Dim fld As ADODB.Field Dim NomeCampo As String DoCmd.SetWarnings False rs.Open "select * from " & Tabella & "", CurrentProject.Connection, adOpenKeyset, adLockOptimistic Set flds = rs.Fields For Each fld In flds NomeCampo = fld.Name if fld.Type=202 "id" Then DoCmd.RunSQL "UPDATE " & Tabella & " SET " & NomeCampo & "= Null WHERE " & NomeCampo & " = ""null""" Next MsgBox " fatto " rs.Close DoCmd.SetWarnings False End Sub§
|
|
|
|
 |
willy55
Veterano
Esperto di Access
Joined: 03/Ago/2011
Location: Italy
Status: Offline
Points: 1223
|
Posted: 24/Mar/2012 at 18:48 |
Sul web è disponibile molta documentazione per poter apprendere Access e approfondire i concetti sui database. Riprendo quindi l'iniziativa di Luciano (sempre lodevole) e lo spunto di Alberto, sollecitando Gregorio (se ne ha l'opportunità) di valutare l'esigenza a fornire uno spazio sul suo sito ove sia possibile allegare e scaricare del materiale di divulgazione. Propongo che questo thread, se lo staff di Ialweb forum lo ritiene opportuno, possa essere posto in evidenza (così come le funzioni fornite da Luciano).
Con l'occasione indico dei link per chi sia interessato a seguire dei videocorsi su Access e i database.
Thread ove vengono indicati i corsi su youtube per i vari aspetti teorici nella gestione dei database (in inglese) http://www.accessforums.net/showthread.php/23211-question-about-keys
Saluti a tutto il forum.
Edited by willy55 - 24/Mar/2012 at 18:49
|
|
Willy
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 30/Mar/2012 at 12:27 |
Funzione n.092 Trova un valore di campo duplicato
§RicercaDuplicato Funzione Tabella Luciano §Ritorna vero se esiste un valore di campo duplicato nella tabella scelta§ Campo Funzione Tabella Funzioni Valore TrasformaNull
§Public Function RicercaDuplicato(Campo, Tabella, Valore) Dim rs As DAO.Recordset Set rs = CurrentDb.OpenRecordset("SELECT count(" & Campo & ")as duplicati FROM " & Tabella & " WHERE " & Campo & "=""" & Valore & """") RicercaDuplicato = (rs.Fields("Duplicati") <> 0) rs.Close Set rs = Nothing MsgBox RicercaDuplicato End Function§
|
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 02/Apr/2012 at 11:18 |
Funzione n.093 Lista referenze necessarie
§ListaReferenze Sub Varie VediCodice § FUNZIONE PER ESTRARRE LA LISTA DELLE REFERENZE NECESSARIE ' Alessandro Baraldi§
§Public Sub ListaReferenze() Dim lista As String Dim accRef As Access.Reference For Each accRef In Application.References With accRef If (.IsBroken = False) Then lista = lista & vbCrLf & .Name & " " & .FullPath 'lista = lista & vbCrLf & .Name & " " & .Guid & " " & .FullPath Else MsgBox .Guid End If End With Next accRef MsgBox lista End Sub§
|
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 02/Apr/2012 at 12:12 |
Funzione n.094 Estrae l'html da una pagina web e lo salva in un file di testo
§EstraiHtml Sub Internet VediCodice §Estrae l'html da una pagina web e lo salva in un file di testo.§ Indirizzo http://www.sitocomune.com/ NomeFile Notes Percorso Application.CurrentProject.Path
§Public Sub EstraiHtml(Indirizzo, NomeFile, Percorso) Dim fs As Object Dim a As Variant Dim oHttp As Object Dim lngFile As Long Dim Miopath As String Dim txtRequestString As String Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile(Percorso, True) Set oHttp = CreateObject("MSXML2.XMLHTTP") oHttp.Open "GET", Indirizzo, False oHttp.send MsgBox oHttp.responseText lngFile = FreeFile() On Error GoTo 5000 If Percorso = "Application.CurrentProject.Path" Then Miopath = Application.CurrentProject.Path & "\" & NomeFile & ".txt" Else Miopath = Percorso & "\" & NomeFile & ".txt" End If Open Miopath For Append As lngFile Print #1, oHttp.responseText Close lngFile MsgBox NomeFile & " salvato" Exit Sub 5000 End Sub§
|
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 05/Apr/2012 at 11:25 |
Funzione n.095 Verifica i decimali di un numero
§Decimali Sub Matematica Luciano §Verifica se e quanti decimali ci sono nel numero (Valore)§ Valore -2,111
§Public Sub Decimali(Valore) If Int(Valore) = Valore Then MsgBox "il numero non contiene decimali" Else MsgBox "il numero contiene decimali" End If If InStr(Valore, ",") = 0 Then MsgBox "Il valore non contiene decimali" Else MsgBox "Il valore " & Valore & " contiene " & Len(Valore) - InStr(Valore, ",") & " numeri decimali" End If End Sub§
|
|
|
|
 |
Luciano
Utente Onorario
Joined: 05/Giu/2010
Location: Italy
Status: Offline
Points: 1972
|
Posted: 05/Apr/2012 at 13:17 |
Funzione n.096 Funzioni matematiche
§Matematica1 Sub Matematica Luciano §Segno, valore assoluto, parte intera, arrotondamento di un numero. Testa se un'espressione è un numero§ Valore -2,1234 Decimali 2
§Public Sub Matematica1(Valore, NumeroDecimali) On Error GoTo 5000 MsgBox "Sng(Valore)Estrae il segno di un numero ed è = " & Sgn(Valore) & vbCrLf & vbCrLf & _ "Fix(Valore) Restituisce in caso di segno negativo il primo intero negativo maggiore o uguale a Valore ed è = " & Fix(Valore) & vbCrLf & vbCrLf & _ "Int(Valore)Restituisce il primo intero negativo minore o uguale a Valore ed è = " & Int(Valore) & vbCrLf & vbCrLf & _ "Round(Valore, NumeroDecimali) Restituisce il valore arrotondato a NumeroDecimali ( " & NumeroDecimali & ")= " & Round(Valore, NumeroDecimali) & vbCrLf & vbCrLf & _ "Abs(Valore) Restituisce il valore assoluto di un numero ed è = " & Abs(Valore) 5000 MsgBox "IsNumeric(Valore) Restituisce un valore Boolean che indica se un'espressione può essere valutata come numero. In questo caso è " & IsNumeric(Valore) End Sub§
|
|
|
|
 |