Oppure

Loading
08/05/08 21:46
JJ69
Ciao,

sono un neofita e ho il seguente problema con questo codice ed il Common Dialog:

Private Sub Command1_Click()
Text3.Text = CDbl(Text1.Text) + CDbl(Text2.Text)
End Sub

Private Sub mnuApri_Click()

CommonDialog1.Filter = "Text Files|*.txt"

CommonDialog1.ShowOpen

titolo = CommonDialog1.FileName

Dim Campo1 As Currency
Dim Campo2 As Currency
Dim Campo3 As Currency


Open titolo For Input As #2



Input #2, Campo1
Input #2, Campo2
Input #2, Campo3




Close #2



Campo1 = CDbl(Text1.Text)
Campo2 = CDbl(Text2.Text)
Campo3 = CDbl(Text3.Text)


End Sub

Private Sub mnuEsci_Click()

Unload Me

End Sub

Private Sub mnuSalva_Click()

CommonDialog1.Filter = "Text Files|*.txt"
CommonDialog1.ShowSave

titolo = CommonDialog1.FileName

Open titolo For Output As #1

Text1.Text = FormatCurrency(Text1.Text, , , vbFalse)
Text2.Text = FormatCurrency(Text2.Text, , , vbFalse)
Text3.Text = FormatCurrency(Text3.Text, , , vbFalse)

Print #1, Text1.Text
Print #1, Text2.Text
Print #1, Text3.Text


Close #1

End Sub

Sul form ho disposto tre textbox ed un command button: nelle prime due textbox inserisco valori numerici che vado a sommare tramite il command button che ne restituisce il risultato nella terza textbox. Attivo il programma, inserisco i valori numerici e li sommo, salvo e correttamente le textbox si aggiornano con il seguente formato: €. 10,89. PURTROPPO quando vado ad aprire il file quest'ultimo mi restituisce dei valori non corretti e separati. Credo che il problema sia nel tipo di variabile che io dichiaro currency ed una volta sommata questa non lo è ovviamente più perchè si è aggiunto il carattere dell'euro. Dov'è l'inghippo?
Grazie per l'attenzione
aaa
09/05/08 16:46
kryc
Prova prima a salvare il file dopo assegnare il formato currency alle text box
aaa
10/05/08 13:41
JJ69
Grazie per il consiglio. Ora procedo come segue: apro e salvo con il codice che segue salvando tutto come string. Dopo, anzichè usare la variabile Currency utilizzo la variabile Variant e susseguentemente la dichiaro Decimal in uno solo degli operandi all'interno del command button che svolge l'operazione. Da quanto ho appreso dal sito msdn basta solo dichiararne una come decimal che automaticamente tutti gli altri operandi saranno interpretati come tali.

Private Sub Command1_Click()
CD1.ShowSave
If CD1.FileName <> "" Then
Open CD1.FileName For Output As #1
Write #1, Text1.Text
Close #1
End If
Text1.Text = ""
End Sub

Private Sub Command2_Click()
Dim ch As String
CD1.ShowOpen
If CD1.FileName <> "" Then
Open CD1.FileName For Input As #1
Input #1, ch
Close #1
Text1.Text = ch
End If
End Sub

Grazie ancora
aaa
10/05/08 13:42
JJ69
Dimenticavo: così funziona!:asd:
aaa