Olisin kysellyt, onko kellään tietoa: käytän commondialog kontrollia. ja koodi näyttää seuraavalta, valmiissa filessä on ilmestynyt joissain riveillä ylimääräinen välilyönti alussa ja numeron/numeroiden jälkeen
common dialog1.FileName = "" ' alustetaan
common dialog1.Flags = &H200000
common dialog1.Flags = &H8
common dialog1.FileName = "C:\Documents and Settings\All Users\edellinen.txt"
If Dir(common dialog1.FileName) <> "" Then
Kill common dialog1.FileName
End If
uusitiedosto = FreeFile
common dialog1.FileName For Output As #uusitiedosto
Print #uusitiedosto, arvo ' muuttujan arvo (integer)
+ xxxxxxxx
+ xxxxxxxx
Close uusitiedostoek
Mod. lisäsi kooditagit.
MOI erkki!
Miksi ihmeessä käytät CommonDialog -objektia, kun kuitenkin määrittelet koko tiedostopolun suoraan koodissasi? Elikä mieti hieman oheisen esimerkin koodia...
Private Sub Command1_Click()
Dim fileName As String
Dim basePath As String
Dim fullPath As String
Dim arvo As Integer
fileName = "edellinen.txt"
basePath = Environ("ALLUSERSPROFILE")
fullPath = basePath & "\" & fileName
arvo = 100
Open fullPath For Output As #1
Print #1, CStr(arvo)
'CStr funktio muuntaa luvun merkkijonoksi
Close #1
Dim fileStr As String
Open fullPath For Input As #1
fileStr = Input$(LOF(1), 1)
Close #1
Dim lines() As String
If InStr(fileStr, vbCrLf) > 0 Then
lines = Split(fileStr, vbCrLf)
Else
ReDim lines(0)
lines(0) = fileStr
End If
fileStr = ""
Dim i As Integer
For i = LBound(lines) To UBound(lines)
Dim strvalue As String
strvalue = Trim(lines(i))
If IsNumeric(Left(strvalue, 1)) Then
If InStr(strvalue, ",") > 0 _
And InstrRev(strvalue, ",") _
= InStr(strvalue, ",") Then
strvalue = Replace(strvalue, ",", ".")
End if
arvo = CInt(Val(strvalue))
'Val funktio muuntaa numeerisen merkkijonon luvuksi
'CInt funktio muuntaa numeerisen merkkijonon tahi
'lukuarvon pyöristetyksi kokonaisluvuksi
MsgBox arvo
End If
Next
Erase lines
End SubKiitti neuvosta Nea, epäilemättä en ole syventynyt asiaan CommonDialogin käytössä, jostain se on jäänyt tavaksi. Koodisi on ok.
Eki
Aihe on jo aika vanha, joten et voi enää vastata siihen.