Ergebnis einer Funktion in Datei speichern.

knowledge

Mitglied
Hallo,
Ich möchte das Ergebnis einer Funktion in eine Datei speichern. Die Datei wird angelegt aber wie kann ich die Daten speichern.Wie soll ich die Funktion aufrufen und wo?
Code:
Public Sub Filetest()
Dim iFileNumber As Integer
Dim sFilename As String
Dim sDirectory As String
Dim sYourString As String
Dim sYourString2 As String

sDirectory = "C:\" & Hallo
sYourString = "Überschrift: "
sYourString2 = "++++++++++++++++++++++++++++++++++++++++++++++++++  +++++++++++"

sFilename = Trim(Str(Year(Now()))) & "_" & Trim(Str(Month(Now()))) & "_" & Trim(Str(Day(Now()))) & ".txt"
iFileNumber = FreeFile

If Dir(sDirectory, vbDirectory) = "" Then MkDir (sDirectory)

Open sDirectory & sFilename & ".txt" For Append As iFileNumber
Print #iFileNumber, sYourString
Print #iFileNumber, sYourString2
Close #iFileNumber
End Sub
 
Moin,

ich habe da etwas für dich, ganz easy(, denke ich mal!)
Der Befehl heißt nicht Print,

sondern Write.

Das müßte eigentlich genügen!
 
Um welchen Datentypen handelt sich denn das Ergebnis dieser Funktion?

Läuft die Funktion vorher ab und rufst du die Filetest() Funktion erst danach auf?
 
Ich schon wieder, ich glaube ich weiß, was du möchtest!

Also, du hast also eine Funktion, nennen wir sie mal Function HyperRechnung().
In dieser Funktion rechnest du mit Werten und kommst anschließend auf
ein Ergebnis.
Dieses Ergebnis musst du dann der FileTest(Ergebnis As 'Was auch immer')
übergeben, ich hab hier mal ein Beispiel:

Code:
Public Sub Filetest(ByVal Ergebnis As Integer)
Dim iFileNumber As Integer
Dim sFilename As String
Dim sDirectory As String
Dim sYourString As String
Dim sYourString2 As String
Dim sErgebnis As String

sDirectory = "C:\" & Hallo
sYourString = "Überschrift: "
sYourString2 = "++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++"
sErgebnis = Ergebnis
 

sFilename = Trim(Str(Year(Now()))) & "_" & Trim(Str(Month(Now()))) & "_" & Trim(Str(Day(Now()))) & ".txt"
iFileNumber = FreeFile

If Dir(sDirectory, vbDirectory) = "" Then MkDir (sDirectory)

Open sDirectory & sFilename & ".txt" For Append As iFileNumber
Print #iFileNumber, sYourString
Print #iFileNumber, sYourString2
Print #iFileNumber, sErgebnis
Close #iFileNumber
End Sub

Probiers mal aus, wenn es das ist, was du meinst!
 
Genau das meine ich was du geschrieben hast aber irgenwie kapiere ich nicht wo ich die Funktion Zum Beispiel HyperRechnung() aufrufen soll. Ich bin nicht so gut mit VBA und file system ist für mich ganz ganz neu.
 
kannst du deinen Quellcode mal anhängen, dann kann man
direkt mal gucken, was wie und wo gemacht ist usw.
Und vielleicht lann ich dir dann sofort weiterhelfen.
 
Hier ist mein Code

Code:
Public Function ListAllProcedures()

    On Error Resume Next
    Dim obj As Object
    Dim i As Integer
    Dim j As Long
    Dim RetVar As Variant
    
    'For Each obj In CurrentProject.allforms
    '   DoCmd.OpenForm obj.Name, acDesign
    '   If Forms(obj.Name).HasModule = True Then
    '       AllProcs ("Form_" & obj.Name)
    '   End If
    'Next
    
    'For Each obj In CurrentProject.AllReports
    '   DoCmd.OpenReport obj.Name, acDesign
    '   If Reports(obj.Name).HasModule = True Then
    '       AllProcs ("Report_" & obj.Name)
    '   End If
    'Next
    
    For i = 0 To CodeDb.Containers("Modules").Documents.Count - 1
        RetVar = AllProcs(CodeDb.Containers("Modules").Documents(i).Name)
    Next i

End Function


Public Function AllProcs(strModuleName As String)
   
   Dim mdl As Module
   Dim lngCount As Long, lngCountDecl As Long, lngI As Long
   Dim strProcName As String, astrProcNames() As String
   Dim intI As Integer
   Dim lngR As Long
   
   Dim intBlankLineCount As Integer

   ' Open specified Module object.
   DoCmd.OpenModule strModuleName
   ' Return reference to Module object.
   Set mdl = Modules(strModuleName)
   ' Count lines in module.
   lngCount = mdl.CountOfLines
   ' Count lines in Declaration section in module.
   lngCountDecl = mdl.CountOfDeclarationLines
   ' Determine name of first procedure.
   strProcName = mdl.ProcOfLine(lngCountDecl + 1, lngR)
   ' Initialize counter variable.
   intI = 0
   ' Redimension array.
   ReDim Preserve astrProcNames(intI)
   ' Store name of first procedure in array.
   astrProcNames(intI) = strProcName
   ' Determine procedure name for each line after declarations.
   For lngI = lngCountDecl + 1 To lngCount
       ' Compare procedure name with ProcOfLine property value.
       If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
           ' Increment counter.
           intI = intI + 1
           strProcName = mdl.ProcOfLine(lngI, lngR)
           ReDim Preserve astrProcNames(intI)
           ' Assign unique procedure names to array.
           astrProcNames(intI) = strProcName
       End If
   Next lngI
   
   For intI = 0 To UBound(astrProcNames)
       Debug.Print strModuleName & " - " & astrProcNames(intI)
   Next intI
   
End Function
 
Yo, das ist also dein Code!

Welches Ergebnis möchtest du in die Textdatei speichern?
 
wenn ich die Funktion ListAllProcedures aufrufe dann erscheint eine Liste von Modulen ins Directfenster. Diese Liste hätte ich gern in einer Text-Datei.
 
Zurück